/** * @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; }
private function _testPhpSniffs($file, $customRuleset = null) { $outputInterface = new OutputInterfaceMock(); $validator = new PhpCodeStyleValidator([$file], $this->tmpdir, $outputInterface); if ($customRuleset !== null) { $validator->setRuleset($customRuleset); } return $validator->validate(); }