/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new SymfonyStyle($input, $output); $io->title('Pre-commit delete'); $git = new GitVersionControl(); $projectBase = $git->getProjectBase(); $hookDir = $projectBase . '/.git/hooks'; if (!$io->confirm('Are you sure to remove Pre-commit hooks on this project?', true)) { exit(0); } $output->writeln(''); if (!is_dir($hookDir)) { $io->error(sprintf('The git hook directory does not exist (%s)', $hookDir)); exit(1); } $target = $hookDir . '/pre-commit'; $fs = new Filesystem(); if (is_file($target)) { $fs->remove($target); $io->success('pre-commit was deleted'); exit(0); } $io->error(sprintf('pre-commit file does\'nt exist (%s)', $target)); exit(1); }
/** * {@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); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new SymfonyStyle($input, $output); $io->title('Pre-commit install'); $git = new GitVersionControl(); $projectBase = $git->getProjectBase(); $phpunit = $io->confirm('Enable PhpUnit ?', true); $source = realpath($projectBase); $hookDir = $source . '/.git/hooks'; $defaultPhpUnitConfFile = $source . '/' . self::PHPUNIT_DEFAULT_CONF_FILENAME; $precommitCommand = sprintf('precommit check%s', $phpunit ? ' --phpunit true' : ''); if ($phpunit) { $phpunitPath = $io->ask('Specify Phpunit bin path [example: vendor/bin/phpunit] ? : ', 'phpunit'); $phpunitConfFile = $io->ask('Specify Phpunit config file path ? : ', $defaultPhpUnitConfFile); if ($phpunitPath != '') { if (strpos($phpunitPath, '/') !== false) { $phpunitPath = $source . '/' . $phpunitPath; if (!is_file($phpunitPath)) { $io->error(sprintf('No phpunit bin found "%s"', $phpunitPath)); exit(1); } } } if (!is_file($phpunitConfFile)) { $io->error(sprintf('No phpunit conf file found "%s"', $phpunitConfFile)); exit(1); } $precommitCommand .= $phpunitPath != 'phpunit' ? ' --phpunit-bin-path ' . $phpunitPath : ''; $precommitCommand .= $phpunitConfFile != $defaultPhpUnitConfFile ? ' --phpunit-conf ' . $phpunitConfFile : ''; } if (!is_dir($hookDir)) { $io->error(sprintf('The git hook directory does not exist (%s)', $hookDir)); exit(1); } $target = $hookDir . '/pre-commit'; $fs = new Filesystem(); if (!is_file($target)) { $fileContent = sprintf("#!/bin/sh\n%s", $precommitCommand); $fs->dumpFile($target, $fileContent); chmod($target, 0755); $io->success('pre-commit file correctly updated'); } else { $io->note(sprintf('A pre-commit file is already exist. Please add "%s" at the end !', $precommitCommand)); } exit(0); }