/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new SymfonyStyle($input, $output); $git = new GitVersionControl(); $stagedFiles = $git->getStagedFiles(); $projectBase = $git->getProjectBase(); $reporter = new Reporter($output, count($stagedFiles)); $review = new StaticReview($reporter); $review->addReview(new ComposerLockReview())->addReview(new ComposerLintReview())->addReview(new PhpLintReview())->addReview(new PhpStopWordsReview())->addReview(new JsStopWordsReview())->addReview(new EsLintReview(self::AUTO_ADD_GIT))->addReview(new YmlLintReview())->addReview(new JsonLintReview())->addReview(new XmlLintReview())->addReview(new GitConflictReview()); // -------------------------------------------------------- // Front Dev profile // -------------------------------------------------------- /*$review->addReview(new ScssLintReview()) ->addReview(new SassConvertFixerReview(self::AUTO_ADD_GIT));*/ // -------------------------------------------------------- // Dev PHP profile // -------------------------------------------------------- $phpCodeSniffer = new PhpCodeSnifferReview(); $phpCodeSniffer->setOption('standard', 'Pear'); $phpCodeSniffer->setOption('sniffs', 'PEAR.Commenting.FunctionComment'); $review->addReview(new PhpCPDReview())->addReview(new PhpMDReview())->addReview($phpCodeSniffer); // -------------------------------------------------------- $review->files($stagedFiles); $reporter->displayReport(); $testingReporter = new Reporter($output, 0); // -------------------------------------------------------- // Dev PHP profile // -------------------------------------------------------- if (!$reporter->hasIssueLevel(Issue::LEVEL_ERROR) && count($stagedFiles) > 0) { $testingReview = new TestingReview($testingReporter); if ($input->getOption('phpunit')) { $testingReview->addReview(new PhpUnitReview($input->getOption('phpunit-bin-path'), $input->getOption('phpunit-conf'), $projectBase)); } $testingReview->review(); $testingReporter->displayReport(); } // -------------------------------------------------------- if ($reporter->hasIssueLevel(Issue::LEVEL_ERROR) || $testingReporter->hasIssueLevel(Issue::LEVEL_ERROR)) { $io->error('✘ Please fix the errors above or use --no-verify.'); exit(1); } elseif ($reporter->hasIssueLevel(Issue::LEVEL_WARNING) || $testingReporter->hasIssueLevel(Issue::LEVEL_WARNING)) { $io->note('Try to fix warnings !'); } else { $io->success('✔ Looking good.'); } exit(0); }
use League\CLImate\CLImate; use StaticReview\Reporter\Reporter; use StaticReview\Review\Composer\ComposerLintReview; use StaticReview\Review\Composer\ComposerSecurityReview; use StaticReview\Review\General\LineEndingsReview; use StaticReview\Review\PHP\PhpCodeSnifferReview; use StaticReview\Review\PHP\PhpLintReview; use StaticReview\StaticReview; use StaticReview\VersionControl\GitVersionControl; $reporter = new Reporter(); $climate = new CLImate(); $git = new GitVersionControl(); $review = new StaticReview($reporter); // Add any reviews to the StaticReview instance, supports a fluent interface. $review->addReview(new LineEndingsReview())->addReview(new PhpLintReview())->addReview(new ComposerLintReview())->addReview(new ComposerSecurityReview()); $codeSniffer = new PhpCodeSnifferReview(); $codeSniffer->setOption('standard', 'PSR2'); $review->addReview($codeSniffer); if ($git->getStagedFiles()->count() === 0) { $climate->out('')->yellow('[-] Nothing to do.')->white('No files founded in the git staged.'); exit(0); } // Review the staged files. $review->files($git->getStagedFiles()); // Check if any matching issues were found. if ($reporter->hasIssues()) { $climate->out('')->out(''); foreach ($reporter->getIssues() as $issue) { $climate->red($issue); } $climate->out('')->red('[x] Please fix the errors above.');