foreach ($history as $i => $line) {
if ($this->filter->match($line, $matches)) {
if (isset($matches[0])) {
- $chunks = explode($matches[0], $history[$i]);
- $chunks = array_map([__CLASS__, 'escape'], $chunks);
- $glue = sprintf('<urgent>%s</urgent>', self::escape($matches[0]));
+ $chunks = \explode($matches[0], $history[$i]);
+ $chunks = \array_map([__CLASS__, 'escape'], $chunks);
+ $glue = \sprintf('<urgent>%s</urgent>', self::escape($matches[0]));
- $highlighted[$i] = implode($glue, $chunks);
+ $highlighted[$i] = \implode($glue, $chunks);
}
} else {
unset($history[$i]);
}
if ($save = $input->getOption('save')) {
- $output->writeln(sprintf('Saving history in %s...', $save));
- file_put_contents($save, implode(PHP_EOL, $history) . PHP_EOL);
+ $output->writeln(\sprintf('Saving history in %s...', $save));
+ \file_put_contents($save, \implode(PHP_EOL, $history) . PHP_EOL);
$output->writeln('<info>History saved.</info>');
} elseif ($input->getOption('replay')) {
if (!($input->getOption('show') || $input->getOption('head') || $input->getOption('tail'))) {
throw new \InvalidArgumentException('You must limit history via --head, --tail or --show before replaying');
}
- $count = count($history);
- $output->writeln(sprintf('Replaying %d line%s of history', $count, ($count !== 1) ? 's' : ''));
+ $count = \count($history);
+ $output->writeln(\sprintf('Replaying %d line%s of history', $count, ($count !== 1) ? 's' : ''));
$this->getApplication()->addInput($history);
} elseif ($input->getOption('clear')) {
$this->clearHistory();
*/
private function extractRange($range)
{
- if (preg_match('/^\d+$/', $range)) {
+ if (\preg_match('/^\d+$/', $range)) {
return [$range, $range + 1];
}
$matches = [];
- if ($range !== '..' && preg_match('/^(\d*)\.\.(\d*)$/', $range, $matches)) {
- $start = $matches[1] ? intval($matches[1]) : 0;
- $end = $matches[2] ? intval($matches[2]) + 1 : PHP_INT_MAX;
+ if ($range !== '..' && \preg_match('/^(\d*)\.\.(\d*)$/', $range, $matches)) {
+ $start = $matches[1] ? \intval($matches[1]) : 0;
+ $end = $matches[2] ? \intval($matches[2]) + 1 : PHP_INT_MAX;
return [$start, $end];
}
$history = $this->readline->listHistory();
// don't show the current `history` invocation
- array_pop($history);
+ \array_pop($history);
if ($show) {
list($start, $end) = $this->extractRange($show);
$length = $end - $start;
} elseif ($head) {
- if (!preg_match('/^\d+$/', $head)) {
+ if (!\preg_match('/^\d+$/', $head)) {
throw new \InvalidArgumentException('Please specify an integer argument for --head');
}
$start = 0;
- $length = intval($head);
+ $length = \intval($head);
} elseif ($tail) {
- if (!preg_match('/^\d+$/', $tail)) {
+ if (!\preg_match('/^\d+$/', $tail)) {
throw new \InvalidArgumentException('Please specify an integer argument for --tail');
}
- $start = count($history) - $tail;
- $length = intval($tail) + 1;
+ $start = \count($history) - $tail;
+ $length = \intval($tail) + 1;
} else {
return $history;
}
- return array_slice($history, $start, $length, true);
+ return \array_slice($history, $start, $length, true);
}
/**
}
if ($count > 1) {
- throw new \InvalidArgumentException('Please specify only one of --' . implode(', --', $options));
+ throw new \InvalidArgumentException('Please specify only one of --' . \implode(', --', $options));
}
}