/**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new SymfonyStyle($input, $output);
     $fileInput = trim($input->getArgument('file'));
     $pathInfoFile = pathinfo(realpath($fileInput));
     $file = new File('', realpath($fileInput), $pathInfoFile['dirname']);
     $fileCollection = new FileCollection();
     $fileCollection = $fileCollection->append($file);
     $reporter = new Reporter($output, 1);
     $review = new StaticReview($reporter);
     $review->addReview(new PhpCsFixerReview(self::AUTO_ADD_GIT));
     // Review the staged files.
     $review->files($fileCollection);
     // Check if any matching issues were found.
     if ($reporter->hasIssues()) {
         $reporter->displayReport();
     }
     if ($reporter->hasIssueLevel(Issue::LEVEL_ERROR)) {
         $io->error('✘ Please fix the errors above.');
         exit(1);
     } else {
         $io->success('✔ Looking good.');
         exit(0);
     }
 }
Пример #2
0
 * This file is part of StaticReview
 *
 * Copyright (c) 2014 Samuel Parkinson <@samparkinson_>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @see http://github.com/sjparkinson/static-review/blob/master/LICENSE.md
 */
$included = (include file_exists(__DIR__ . '/../vendor/autoload.php') ? __DIR__ . '/../vendor/autoload.php' : __DIR__ . '/../../../autoload.php');
if (!$included) {
    echo 'You must set up the project dependencies, run the following commands:' . PHP_EOL . 'curl -sS https://getcomposer.org/installer | php' . PHP_EOL . 'php composer.phar install' . PHP_EOL;
    exit(1);
}
// Reference the required classes and the reviews you want to use.
use StaticReview\Reporter\Reporter;
use StaticReview\Review\General\LineEndingsReview;
use StaticReview\StaticReview;
use StaticReview\VersionControl\GitVersionControl;
$reporter = new Reporter();
$review = new StaticReview($reporter);
// Add any reviews to the StaticReview instance, supports a fluent interface.
$review->addReview(new LineEndingsReview());
$git = new GitVersionControl();
// Review the staged files.
$review->review($git->getStagedFiles());
echo PHP_EOL;
// Check if any issues were found.
// Exit with a non-zero to block the commit.
$reporter->hasIssues() ? exit(1) : exit(0);
Пример #3
0
use StaticReview\Reporter\Reporter;
use StaticReview\StaticReview;
use StaticReview\VersionControl\GitVersionControl;
use Symfony\Component\Process\Process;
use StasPiv\Review\Fixer\PhpCsFixer;
$reporter = new Reporter();
$review = new StaticReview($reporter);
// Add any reviews to the StaticReview instance, supports a fluent interface.
$review->addReview(new PhpCsFixer());
$git = new GitVersionControl();
// Review the staged files.
$review->files($git->getStagedFiles());
echo PHP_EOL;
$climate = new CLImate();
$warnings = $errors = $info = 0;
if ($reporter->hasIssues()) {
    foreach ($reporter->getIssues() as $issue) {
        /** @var Issue $issue */
        if ($issue->getLevel() == Issue::LEVEL_INFO) {
            (new Process('git add ' . $issue->getSubject()->getName()))->run();
            ++$info;
        }
        if ($issue->getLevel() == Issue::LEVEL_WARNING) {
            ++$warnings;
        }
        if ($issue->getLevel() == Issue::LEVEL_ERROR) {
            $climate->backgroundRed($issue->getMessage());
            ++$errors;
        }
    }
}