grumPHP = $config; $this->changedFilesLocator = $changedFilesLocator; } public static function getDefaultName(): string { return self::COMMAND_NAME; } /** * Configure command. */ protected function configure(): void { $this->setDescription('Executed by the pre-commit hook'); $this->addOption( 'skip-success-output', null, InputOption::VALUE_NONE, 'Skips the success output. This will be shown by another command in the git commit hook chain.' ); } public function execute(InputInterface $input, OutputInterface $output): int { $io = new ConsoleIO($input, $output); $files = $this->getCommittedFiles($io); $context = new TaskRunnerContext( new GitPreCommitContext($files), $this->grumPHP->getTestSuites()->getOptional('git_pre_commit') ); $context->setSkipSuccessOutput((bool) $input->getOption('skip-success-output')); $output->writeln('GrumPHP detected a pre-commit command.'); return $this->taskRunner()->run($output, $context); } protected function getCommittedFiles(ConsoleIO $io): FilesCollection { if ($stdin = $io->readCommandInput(STDIN)) { return $this->changedFilesLocator->locateFromRawDiffInput($stdin); } return $this->changedFilesLocator->locateFromGitRepository(); } protected function taskRunner(): TaskRunnerHelper { return $this->getHelper(TaskRunnerHelper::HELPER_NAME); } }