CheckCommand.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of PHP CS Fixer.
  5. *
  6. * (c) Fabien Potencier <fabien@symfony.com>
  7. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  8. *
  9. * This source file is subject to the MIT license that is bundled
  10. * with this source code in the file LICENSE.
  11. */
  12. namespace PhpCsFixer\Console\Command;
  13. use PhpCsFixer\ToolInfoInterface;
  14. use Symfony\Component\Console\Attribute\AsCommand;
  15. use Symfony\Component\Console\Input\InputInterface;
  16. use Symfony\Component\Console\Input\InputOption;
  17. /**
  18. * @author Greg Korba <greg@codito.dev>
  19. *
  20. * @internal
  21. */
  22. #[AsCommand(name: 'check', description: 'Checks if configured files/directories comply with configured rules.')]
  23. final class CheckCommand extends FixCommand
  24. {
  25. /** @var string */
  26. protected static $defaultName = 'check';
  27. /** @var string */
  28. protected static $defaultDescription = 'Checks if configured files/directories comply with configured rules.';
  29. public function __construct(ToolInfoInterface $toolInfo)
  30. {
  31. parent::__construct($toolInfo);
  32. }
  33. public function getHelp(): string
  34. {
  35. $help = explode('<comment>--dry-run</comment>', parent::getHelp());
  36. return substr($help[0], 0, strrpos($help[0], "\n") - 1)
  37. .substr($help[1], strpos($help[1], "\n"));
  38. }
  39. protected function configure(): void
  40. {
  41. parent::configure();
  42. $this->setDefinition([
  43. ...array_values($this->getDefinition()->getArguments()),
  44. ...array_values(array_filter(
  45. $this->getDefinition()->getOptions(),
  46. static fn (InputOption $option): bool => 'dry-run' !== $option->getName()
  47. )),
  48. ]);
  49. }
  50. protected function isDryRun(InputInterface $input): bool
  51. {
  52. return true;
  53. }
  54. }