From 412cf753ce49a50b2ab67138cddbda6137ad2bff Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 27 Jun 2022 15:16:42 +0200 Subject: [PATCH 1/6] CS fixes --- DependencyInjection/AddConsoleCommandPass.php | 2 +- Helper/Table.php | 2 +- Logger/ConsoleLogger.php | 2 +- Style/SymfonyStyle.php | 6 +++--- Tests/Tester/CommandTesterTest.php | 3 +-- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/DependencyInjection/AddConsoleCommandPass.php b/DependencyInjection/AddConsoleCommandPass.php index aff892cc2..d9449dc56 100644 --- a/DependencyInjection/AddConsoleCommandPass.php +++ b/DependencyInjection/AddConsoleCommandPass.php @@ -55,7 +55,7 @@ public function process(ContainerBuilder $container) if (!$r->isSubclassOf(Command::class)) { throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must be a subclass of "%s".', $id, $this->commandTag, Command::class)); } - $commandName = $class::getDefaultName() !== null ? str_replace('%', '%%', $class::getDefaultName()) : null; + $commandName = null !== $class::getDefaultName() ? str_replace('%', '%%', $class::getDefaultName()) : null; } if (null === $commandName) { diff --git a/Helper/Table.php b/Helper/Table.php index 99496b1c7..f068f02fa 100644 --- a/Helper/Table.php +++ b/Helper/Table.php @@ -641,7 +641,7 @@ private function fillNextRows(array $rows, int $line): array { $unmergedRows = []; foreach ($rows[$line] as $column => $cell) { - if (null !== $cell && !$cell instanceof TableCell && !is_scalar($cell) && !(\is_object($cell) && method_exists($cell, '__toString'))) { + if (null !== $cell && !$cell instanceof TableCell && !\is_scalar($cell) && !(\is_object($cell) && method_exists($cell, '__toString'))) { throw new InvalidArgumentException(sprintf('A cell must be a TableCell, a scalar or an object implementing "__toString()", "%s" given.', \gettype($cell))); } if ($cell instanceof TableCell && $cell->getRowspan() > 1) { diff --git a/Logger/ConsoleLogger.php b/Logger/ConsoleLogger.php index c9ee03561..4a10fa172 100644 --- a/Logger/ConsoleLogger.php +++ b/Logger/ConsoleLogger.php @@ -110,7 +110,7 @@ private function interpolate(string $message, array $context): string $replacements = []; foreach ($context as $key => $val) { - if (null === $val || is_scalar($val) || (\is_object($val) && method_exists($val, '__toString'))) { + if (null === $val || \is_scalar($val) || (\is_object($val) && method_exists($val, '__toString'))) { $replacements["{{$key}}"] = $val; } elseif ($val instanceof \DateTimeInterface) { $replacements["{{$key}}"] = $val->format(\DateTime::RFC3339); diff --git a/Style/SymfonyStyle.php b/Style/SymfonyStyle.php index 66db3ad5a..1c99a1865 100644 --- a/Style/SymfonyStyle.php +++ b/Style/SymfonyStyle.php @@ -430,18 +430,18 @@ private function autoPrependBlock(): void $chars = substr(str_replace(\PHP_EOL, "\n", $this->bufferedOutput->fetch()), -2); if (!isset($chars[0])) { - $this->newLine(); //empty history, so we should start with a new line. + $this->newLine(); // empty history, so we should start with a new line. return; } - //Prepend new line for each non LF chars (This means no blank line was output before) + // Prepend new line for each non LF chars (This means no blank line was output before) $this->newLine(2 - substr_count($chars, "\n")); } private function autoPrependText(): void { $fetched = $this->bufferedOutput->fetch(); - //Prepend new line if last char isn't EOL: + // Prepend new line if last char isn't EOL: if (!str_ends_with($fetched, "\n")) { $this->newLine(); } diff --git a/Tests/Tester/CommandTesterTest.php b/Tests/Tester/CommandTesterTest.php index 244a3f1d0..ac8bb7691 100644 --- a/Tests/Tester/CommandTesterTest.php +++ b/Tests/Tester/CommandTesterTest.php @@ -217,8 +217,7 @@ public function testErrorOutput() $command->addArgument('foo'); $command->setCode(function ($input, $output) { $output->getErrorOutput()->write('foo'); - } - ); + }); $tester = new CommandTester($command); $tester->execute( From 3f2ece49fd497a0bd848f174e3b229f48bd9504c Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Tue, 5 Jul 2022 13:52:53 +0200 Subject: [PATCH 2/6] Fix Command::run phpdoc --- Command/Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Command/Command.php b/Command/Command.php index da9b9f6af..b0c1bf864 100644 --- a/Command/Command.php +++ b/Command/Command.php @@ -195,7 +195,7 @@ protected function initialize(InputInterface $input, OutputInterface $output) * * @return int The command exit code * - * @throws \Exception When binding input fails. Bypass this by calling {@link ignoreValidationErrors()}. + * @throws ExceptionInterface When input binding fails. Bypass this by calling {@link ignoreValidationErrors()}. * * @see setCode() * @see execute() From c35fafd7f12ebd6f9e29c95a370df7f1fb171a40 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 20 Jul 2022 11:29:12 +0200 Subject: [PATCH 3/6] Fix CS --- Tests/Formatter/OutputFormatterTest.php | 8 ++++---- Tests/Helper/SymfonyQuestionHelperTest.php | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Tests/Formatter/OutputFormatterTest.php b/Tests/Formatter/OutputFormatterTest.php index f418f446f..b041a0db5 100644 --- a/Tests/Formatter/OutputFormatterTest.php +++ b/Tests/Formatter/OutputFormatterTest.php @@ -279,7 +279,7 @@ public function testContentWithLineBreaks() some text EOF - )); + )); $this->assertEquals(<<some text EOF - )); + )); $this->assertEquals(<< EOF - )); + )); $this->assertEquals(<< EOF - )); + )); } public function testFormatAndWrap() diff --git a/Tests/Helper/SymfonyQuestionHelperTest.php b/Tests/Helper/SymfonyQuestionHelperTest.php index b8623e199..296c9fd00 100644 --- a/Tests/Helper/SymfonyQuestionHelperTest.php +++ b/Tests/Helper/SymfonyQuestionHelperTest.php @@ -162,7 +162,7 @@ public function testChoiceQuestionPadding() [łabądź] baz > EOT - , $output, true); + , $output, true); } public function testChoiceQuestionCustomPrompt() @@ -181,7 +181,7 @@ public function testChoiceQuestionCustomPrompt() [0] foo >ccc> EOT - , $output, true); + , $output, true); } protected function getInputStream($input) From d81a3988cc2c8c32569596247830a717268dcefb Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 20 Jul 2022 13:50:25 +0200 Subject: [PATCH 4/6] Fix CS --- Command/Command.php | 2 +- Command/CompleteCommand.php | 6 +++--- Helper/QuestionHelper.php | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Command/Command.php b/Command/Command.php index 357c54b5d..e0593e17a 100644 --- a/Command/Command.php +++ b/Command/Command.php @@ -518,7 +518,7 @@ public function getName() * * @final since Symfony 5.1 */ - public function setHidden(bool $hidden /*= true*/) + public function setHidden(bool $hidden /* = true */) { $this->hidden = $hidden; diff --git a/Command/CompleteCommand.php b/Command/CompleteCommand.php index a94021ce4..11ada4e44 100644 --- a/Command/CompleteCommand.php +++ b/Command/CompleteCommand.php @@ -65,15 +65,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int { try { // uncomment when a bugfix or BC break has been introduced in the shell completion scripts - //$version = $input->getOption('symfony'); - //if ($version && version_compare($version, 'x.y', '>=')) { + // $version = $input->getOption('symfony'); + // if ($version && version_compare($version, 'x.y', '>=')) { // $message = sprintf('Completion script version is not supported ("%s" given, ">=x.y" required).', $version); // $this->log($message); // $output->writeln($message.' Install the Symfony completion script again by using the "completion" command.'); // return 126; - //} + // } $shell = $input->getOption('shell'); if (!$shell) { diff --git a/Helper/QuestionHelper.php b/Helper/QuestionHelper.php index 842a618ef..10602038c 100644 --- a/Helper/QuestionHelper.php +++ b/Helper/QuestionHelper.php @@ -24,6 +24,7 @@ use Symfony\Component\Console\Question\ChoiceQuestion; use Symfony\Component\Console\Question\Question; use Symfony\Component\Console\Terminal; + use function Symfony\Component\String\s; /** From a575bcb51293996ad54127bd43eb84c83013cdc5 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 20 Jul 2022 17:00:40 +0200 Subject: [PATCH 5/6] Fix CS --- Command/Command.php | 4 ++-- Command/LazyCommand.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Command/Command.php b/Command/Command.php index 71205bb69..434c79049 100644 --- a/Command/Command.php +++ b/Command/Command.php @@ -442,7 +442,7 @@ public function getNativeDefinition(): InputDefinition * * @return $this */ - public function addArgument(string $name, int $mode = null, string $description = '', mixed $default = null, /*array|\Closure $suggestedValues = null*/): static + public function addArgument(string $name, int $mode = null, string $description = '', mixed $default = null /* array|\Closure $suggestedValues = null */): static { $suggestedValues = 5 <= \func_num_args() ? func_get_arg(4) : []; if (!\is_array($suggestedValues) && !$suggestedValues instanceof \Closure) { @@ -466,7 +466,7 @@ public function addArgument(string $name, int $mode = null, string $description * * @return $this */ - public function addOption(string $name, string|array $shortcut = null, int $mode = null, string $description = '', mixed $default = null, /*array|\Closure $suggestedValues = []*/): static + public function addOption(string $name, string|array $shortcut = null, int $mode = null, string $description = '', mixed $default = null /* array|\Closure $suggestedValues = [] */): static { $suggestedValues = 6 <= \func_num_args() ? func_get_arg(5) : []; if (!\is_array($suggestedValues) && !$suggestedValues instanceof \Closure) { diff --git a/Command/LazyCommand.php b/Command/LazyCommand.php index cb4d7f245..58cbb770a 100644 --- a/Command/LazyCommand.php +++ b/Command/LazyCommand.php @@ -114,7 +114,7 @@ public function getNativeDefinition(): InputDefinition * * @param array|\Closure(CompletionInput,CompletionSuggestions):list $suggestedValues The values used for input completion */ - public function addArgument(string $name, int $mode = null, string $description = '', mixed $default = null, /*array|\Closure $suggestedValues = []*/): static + public function addArgument(string $name, int $mode = null, string $description = '', mixed $default = null /* array|\Closure $suggestedValues = [] */): static { $suggestedValues = 5 <= \func_num_args() ? func_get_arg(4) : []; $this->getCommand()->addArgument($name, $mode, $description, $default, $suggestedValues); @@ -127,7 +127,7 @@ public function addArgument(string $name, int $mode = null, string $description * * @param array|\Closure(CompletionInput,CompletionSuggestions):list $suggestedValues The values used for input completion */ - public function addOption(string $name, string|array $shortcut = null, int $mode = null, string $description = '', mixed $default = null, /*array|\Closure $suggestedValues = []*/): static + public function addOption(string $name, string|array $shortcut = null, int $mode = null, string $description = '', mixed $default = null /* array|\Closure $suggestedValues = [] */): static { $suggestedValues = 6 <= \func_num_args() ? func_get_arg(5) : []; $this->getCommand()->addOption($name, $shortcut, $mode, $description, $default, $suggestedValues); From 535846c7ee6bc4dd027ca0d93220601456734b10 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Fri, 22 Jul 2022 08:02:27 +0200 Subject: [PATCH 6/6] [Console] get full command path for command in search path --- Resources/completion.bash | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Resources/completion.bash b/Resources/completion.bash index c5e89c3c2..fba46070c 100644 --- a/Resources/completion.bash +++ b/Resources/completion.bash @@ -13,9 +13,11 @@ _sf_{{ COMMAND_NAME }}() { # for an alias, get the real script behind it if [[ $(type -t $sf_cmd) == "alias" ]]; then sf_cmd=$(alias $sf_cmd | sed -E "s/alias $sf_cmd='(.*)'/\1/") + else + sf_cmd=$(type -p $sf_cmd) fi - if [ ! -f "$sf_cmd" ]; then + if [ ! -x "$sf_cmd" ]; then return 1 fi