diff --git a/src/Configuration/Configuration.php b/src/Configuration/Configuration.php index 7bff1551f80..f327fc5cfa3 100644 --- a/src/Configuration/Configuration.php +++ b/src/Configuration/Configuration.php @@ -44,6 +44,11 @@ final class Configuration */ private $areAnyPhpRectorsLoaded = false; + /** + * @var bool + */ + private $mustMatchGitDiff = false; + /** * Needs to run in the start of the life cycle, since the rest of workflow uses it. */ @@ -51,6 +56,7 @@ final class Configuration { $this->isDryRun = (bool) $input->getOption(Option::OPTION_DRY_RUN); $this->hideAutoloadErrors = (bool) $input->getOption(Option::HIDE_AUTOLOAD_ERRORS); + $this->mustMatchGitDiff = (bool) $input->getOption(Option::MUST_MATCH_GIT_DIFF); $this->showProgressBar = $this->canShowProgressBar($input); $this->setRule($input->getOption(Option::OPTION_RULE)); @@ -115,6 +121,11 @@ final class Configuration $this->areAnyPhpRectorsLoaded = $areAnyPhpRectorsLoaded; } + public function mustMatchGitDiff(): bool + { + return $this->mustMatchGitDiff; + } + private function canShowProgressBar(InputInterface $input): bool { return $input->getOption(Option::OPTION_OUTPUT_FORMAT) !== JsonOutputFormatter::NAME; diff --git a/src/Configuration/Option.php b/src/Configuration/Option.php index 79b45c9d11e..f5d6ee85c01 100644 --- a/src/Configuration/Option.php +++ b/src/Configuration/Option.php @@ -65,4 +65,9 @@ final class Option * @var string */ public const EXCLUDE_RECTORS_PARAMETER = 'exclude_rectors'; + + /** + * @var string + */ + public const MUST_MATCH_GIT_DIFF = 'must-match-git-diff'; } diff --git a/src/Console/Command/ProcessCommand.php b/src/Console/Command/ProcessCommand.php index ef73219de87..62b9fa0fb0b 100644 --- a/src/Console/Command/ProcessCommand.php +++ b/src/Console/Command/ProcessCommand.php @@ -148,6 +148,13 @@ final class ProcessCommand extends AbstractCommand 'Hide autoload errors for the moment.' ); + $this->addOption( + Option::MUST_MATCH_GIT_DIFF, + null, + InputOption::VALUE_NONE, + 'Execute only on file matching the git diff.' + ); + $this->addOption(Option::OPTION_RULE, 'r', InputOption::VALUE_REQUIRED, 'Run only this single rule.'); $availableOutputFormatters = $this->outputFormatterCollector->getNames();