From 5d59ddb7615e254e9e18b34ad119d2d2bb2fe0b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois-Xavier=20de=20Guillebon?= Date: Thu, 29 Sep 2022 18:29:59 +0200 Subject: [PATCH] fix(symfony): fix command constants not available for symfony <5.1 or <5.3 --- .../Symfony/Bundle/Command/UpgradeApiResourceCommand.php | 8 ++++---- src/Symfony/Bundle/Command/DebugResourceCommand.php | 6 +++--- src/Symfony/Bundle/Command/GraphQlExportCommand.php | 2 +- src/Symfony/Bundle/Command/OpenApiCommand.php | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Core/Bridge/Symfony/Bundle/Command/UpgradeApiResourceCommand.php b/src/Core/Bridge/Symfony/Bundle/Command/UpgradeApiResourceCommand.php index 396742331b7..03d377816cb 100644 --- a/src/Core/Bridge/Symfony/Bundle/Command/UpgradeApiResourceCommand.php +++ b/src/Core/Bridge/Symfony/Bundle/Command/UpgradeApiResourceCommand.php @@ -86,13 +86,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int if (!$input->getOption('force') && \PHP_VERSION_ID < 80100) { $output->write('The new metadata system only works with PHP 8.1 and above.'); - return Command::INVALID; + return \defined(Command::class.'::INVALID') ? Command::INVALID : 2; } if (!class_exists(NodeTraverser::class)) { $output->writeln('Run `composer require --dev `nikic/php-parser` or install phpunit to use this command.'); - return Command::FAILURE; + return \defined(Command::class.'::FAILURE') ? Command::FAILURE : 1; } $subresources = $this->getSubresources(); @@ -151,7 +151,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int if (!class_exists(Differ::class)) { $output->writeln('Run `composer require --dev sebastian/diff` or install phpunit to print a diff.'); - return Command::FAILURE; + return \defined(Command::class.'::FAILURE') ? Command::FAILURE : 1; } $this->printDiff($oldCode, $newCode, $output); @@ -161,7 +161,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int file_put_contents($fileName, $newCode); } - return Command::SUCCESS; + return \defined(Command::class.'::SUCCESS') ? Command::SUCCESS : 0; } /** diff --git a/src/Symfony/Bundle/Command/DebugResourceCommand.php b/src/Symfony/Bundle/Command/DebugResourceCommand.php index 4aa823eaabe..f7670a5554d 100644 --- a/src/Symfony/Bundle/Command/DebugResourceCommand.php +++ b/src/Symfony/Bundle/Command/DebugResourceCommand.php @@ -58,7 +58,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int if (0 === \count($resourceCollection)) { $output->writeln(sprintf('No resources found for class %s', $resourceClass)); - return Command::INVALID; + return \defined(Command::class.'::INVALID') ? Command::INVALID : 2; } $shortName = (false !== $pos = strrpos($resourceClass, '\\')) ? substr($resourceClass, $pos + 1) : $resourceClass; @@ -110,13 +110,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->dumper->dump($this->cloner->cloneVar($selectedResource)); $output->writeln('Successfully dumped the selected resource'); - return Command::SUCCESS; + return \defined(Command::class.'::SUCCESS') ? Command::SUCCESS : 0; } $this->dumper->dump($this->cloner->cloneVar($resourceCollection->getOperation($answerOperation))); $output->writeln('Successfully dumped the selected operation'); - return Command::SUCCESS; + return \defined(Command::class.'::SUCCESS') ? Command::SUCCESS : 0; } public static function getDefaultName(): string diff --git a/src/Symfony/Bundle/Command/GraphQlExportCommand.php b/src/Symfony/Bundle/Command/GraphQlExportCommand.php index 96012d89768..d496c6a248a 100644 --- a/src/Symfony/Bundle/Command/GraphQlExportCommand.php +++ b/src/Symfony/Bundle/Command/GraphQlExportCommand.php @@ -75,7 +75,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln($schemaExport); } - return 0; + return \defined(Command::class.'::SUCCESS') ? Command::SUCCESS : 0; } public static function getDefaultName(): string diff --git a/src/Symfony/Bundle/Command/OpenApiCommand.php b/src/Symfony/Bundle/Command/OpenApiCommand.php index c61d9dc2e55..44bb04f6226 100644 --- a/src/Symfony/Bundle/Command/OpenApiCommand.php +++ b/src/Symfony/Bundle/Command/OpenApiCommand.php @@ -86,12 +86,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int $filesystem->dumpFile($filename, $content); $io->success(sprintf('Data written to %s.', $filename)); - return 0; + return \defined(Command::class.'::SUCCESS') ? Command::SUCCESS : 0; } $output->writeln($content); - return 0; + return \defined(Command::class.'::SUCCESS') ? Command::SUCCESS : 0; } public static function getDefaultName(): string