/** * @param InputInterface $input * @param OutputInterface $output * @return int */ protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $returnCode = Constants::RETURN_CODE_OK; $validators = []; $projectPath = $input->getArgument(self::ARG_PATH); if (true === $this->isProcessingAnyComposerFile()) { if ($input->getOption(self::OPT_ONLY_COMMITED_FILES)) { $validators[] = new ComposerValidator($this->getComposerFiles(), $projectPath, $output); } } if (true === $this->isProcessingAnyPhpFile()) { $phpKeywordValidationRules = [new PhpKeywordValidationRule(T_STRING, ['var_dump'], 'var_dump() function call found', Constants::RETURN_CODE_ERROR), new PhpKeywordValidationRule(T_EMPTY, ['empty'], 'empty() operator found', Constants::RETURN_CODE_WARNING), new PhpKeywordValidationRule(T_STRING, ['ereg', 'eregi', 'eregi_replace', 'ereg_replace', 'mail', 'split', 'stripos', 'stristr', 'strlen', 'strpos', 'strrchr', 'strripos', 'strrpos', 'strstr', 'strtolower', 'strtoupper', 'substr', 'substr_count'], 'Not multibyte string function found. Are you sure?', Constants::RETURN_CODE_WARNING)]; $validators[] = new PhpSyntaxValidator($this->getPhpFiles(), $projectPath, $output); $validators[] = (new PhpKeywordsValidator($this->getPhpFiles(), $projectPath, $output))->setValidationRules($phpKeywordValidationRules); $phpCodeStyleValidator = new PhpCodeStyleValidator($this->getPhpFiles(), $projectPath, $output); if ($input->getOption(self::OPT_CUSTOM_RULESET) !== null) { $phpCodeStyleValidator->setRuleset($input->getOption(self::OPT_CUSTOM_RULESET)); } $validators[] = $phpCodeStyleValidator; $validators[] = new PhpSniffsValidator($this->getPhpFiles(), $projectPath, $output); } if (true === $this->isProcessingAnyJsonFile()) { $validators[] = new JsonValidator($this->getJsonFiles(), $projectPath, $output); } foreach ($validators as $validator) { $returnCode = max($returnCode, $validator->validate()); } if ($returnCode > 0) { $output->writeln('Return code: ' . $returnCode); } return $returnCode; }
protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $phpCodeStyleFixer = new PhpCodeStyleFixer($this->getPhpFiles(), $output); if ($input->getOption(self::OPT_CUSTOM_RULESET) !== null) { $phpCodeStyleFixer->setRuleset($input->getOption(self::OPT_CUSTOM_RULESET)); } $phpCodeStyleFixer->fix($input->getOption(self::OPT_DRY_RUN), $input->getOption(self::OPT_ONLY_COMMITED_FILES)); }
protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $showFullPath = $input->getOption(self::OPTION_SHOW_FULL_PATHS); // Available tools $tools = ['jsonlint', 'phpcs', 'phpcbf']; $output->writeln('<info>Available tools</info>:'); $missingTools = false; foreach ($tools as $tool) { if (!file_exists($this->projectBasepath . '/bin/' . $tool)) { $output->writeln($tool . ' ' . Constants::CHARACTER_KO); $missingTools = true; } else { $output->writeln($tool . ' ' . Constants::CHARACTER_OK); } } if ($missingTools) { $output->writeln('<fg=red>Some tools are missing. Did you forget to execute composer install?</fg=red>'); } // Project basepath $output->writeln('<info>Project basepath</info>:'); $output->writeln($this->projectBasepath); // Hooks path $hooksPath = GitHelper::getHooksPath(); $output->writeln('<info>Hooks path</info>:'); $output->writeln($hooksPath); // Hooks source path $hooksSourcePath = GitHelper::getHooksSourcePath(); $output->writeln('<info>Hooks source path</info>:'); $output->writeln($hooksSourcePath); // Commited files $commitedFiles = (new ExtractCommitedFiles())->getFiles(); $output->writeln('<info>Commited files</info>:'); foreach ($this->prefixFiles($commitedFiles, $showFullPath) as $file) { $output->writeln($file); } // Excluded paths $output->writeln('<info>Excluded paths</info>:'); foreach ($this->prefixFiles($this->excludedPaths, $showFullPath) as $path) { $output->writeln($path); } // Project files (not in excluded paths) $projectFiles = $this->getAllFiles(); $output->writeln('<info>Project files</info>:'); foreach ($this->prefixFiles($projectFiles, $showFullPath) as $file) { $output->writeln($file); } }
protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); (new PhpCustomFixer($this->getPhpFiles(), $output))->fix($input->getOption(self::OPT_DRY_RUN)); }