public function review(ReporterInterface $reporter, ReviewableInterface $commit)
 {
     if (!preg_match('/^[A-Z]/u', $commit->getSubject())) {
         $message = 'Subject line must begin with a capital letter';
         $reporter->error($message, $this, $commit);
     }
 }
 /**
  * Checks JS files using the builtin eslint, `eslint`.
  */
 public function review(ReporterInterface $reporter, ReviewableInterface $file = null)
 {
     // PHP Mess Detector
     $cmd = sprintf('eslint --fix %s -f unix -c %s', $file->getFullPath(), self::JS_ESLINT_RULE_DIR);
     $process = $this->getProcess($cmd);
     $process->run();
     // Create the array of outputs and remove empty values.
     $output = array_filter(explode(PHP_EOL, $process->getOutput()));
     if (!$process->isSuccessful()) {
         foreach (array_slice($output, 0, -1) as $error) {
             preg_match('/(.*):([0-9]+):[0-9]+:(.*)/i', $error, $matches);
             $line = isset($matches[2]) ? $matches[2] : null;
             $error = $matches[1] . $matches[3];
             $message = trim(str_replace($file->getFullPath(), '', $error));
             if (preg_match('/parsing error/i', $message)) {
                 $reporter->error($message, $this, $file, $line);
             } else {
                 $reporter->warning($message, $this, $file, $line);
             }
             if ($this->autoAddGit) {
                 $cmd = sprintf('git add %s', $file->getFullPath());
                 $process = $this->getProcess($cmd);
                 $process->run();
             }
         }
     }
 }
 public function review(ReporterInterface $reporter, ReviewableInterface $commit)
 {
     if (substr($commit->getSubject(), -1) === '.') {
         $message = 'Subject line must not end with a period';
         $reporter->error($message, $this, $commit);
     }
 }
 public function review(ReporterInterface $reporter, ReviewableInterface $commit)
 {
     if (strlen($commit->getSubject()) > $this->getMaximumLength()) {
         $message = sprintf('Subject line is greater than %d characters', $this->getMaximumLength());
         $reporter->error($message, $this, $commit);
     }
 }
 public function review(ReporterInterface $reporter, ReviewableInterface $commit)
 {
     $fulltext = $commit->getSubject() . PHP_EOL . $commit->getBody();
     if (preg_match('/\\bwip\\b/i', $fulltext)) {
         $message = 'Do not commit WIP to shared branches';
         $reporter->error($message, $this, $commit);
     }
 }
 public function review(ReporterInterface $reporter, ReviewableInterface $commit)
 {
     $regex = '/^(?:' . implode('|', $this->incorrect) . ')/i';
     if (preg_match($regex, $commit->getSubject())) {
         $message = 'Subject line must use imperative present tense';
         $reporter->error($message, $this, $commit);
     }
 }
 /**
  * Checks if the set file contains any CRLF line endings.
  *
  * @link http://stackoverflow.com/a/3570574
  */
 public function review(ReporterInterface $reporter, ReviewableInterface $file)
 {
     $cmd = sprintf('file %s | grep --fixed-strings --quiet "CRLF"', $file->getFullPath());
     $process = $this->getProcess($cmd);
     $process->run();
     if ($process->isSuccessful()) {
         $message = 'File contains CRLF line endings';
         $reporter->error($message, $this, $file);
     }
 }
 /**
  * Check the composer.json file is valid.
  *
  * @param ReporterInterface $reporter
  * @param FileInterface     $file
  */
 public function review(ReporterInterface $reporter, FileInterface $file)
 {
     $cmd = sprintf('composer validate %s', $file->getFullPath());
     $process = $this->getProcess($cmd);
     $process->run();
     if (!$process->isSuccessful()) {
         $message = 'The composer configuration is not valid';
         $reporter->error($message, $this, $file);
     }
 }
 /**
  * Checks if the file contains `NOCOMMIT`.
  *
  * @link http://stackoverflow.com/a/4749368
  */
 public function review(ReporterInterface $reporter, ReviewableInterface $file)
 {
     $cmd = sprintf('grep --fixed-strings --ignore-case --quiet "NOCOMMIT" %s', $file->getFullPath());
     $process = $this->getProcess($cmd);
     $process->run();
     if ($process->isSuccessful()) {
         $message = 'A NOCOMMIT tag was found';
         $reporter->error($message, $this, $file);
     }
 }
 /**
  * Check the composer.lock file doesn't contain dependencies
  * with known security vulnerabilities.
  *
  * @param ReporterInterface   $reporter
  * @param ReviewableInterface $file
  */
 public function review(ReporterInterface $reporter, ReviewableInterface $file)
 {
     $cmd = sprintf('security-checker security:check %s', $file->getFullPath());
     $process = $this->getProcess($cmd);
     $process->run();
     if (!$process->isSuccessful()) {
         $message = 'The composer project dependencies contain known vulnerabilities';
         $reporter->error($message, $this, $file);
     }
 }
 public function review(ReporterInterface $reporter, ReviewableInterface $commit)
 {
     $lines = preg_split('/(\\r?\\n)+/', $commit->getBody());
     foreach ($lines as $line) {
         if ($this->isLineTooLong($line) && !$this->doesContainUrl($line)) {
             $message = sprintf('Body line is greater than %d characters ( "%s ..." )', $this->getMaximumLength(), substr($line, 0, 16));
             $reporter->error($message, $this, $commit);
         }
     }
 }
 /**
  * Checks if the set file starts with the correct character sequence, which
  * helps to stop any rouge whitespace making it in before the first php tag.
  *
  * @link http://stackoverflow.com/a/2440685
  */
 public function review(ReporterInterface $reporter, ReviewableInterface $file)
 {
     $cmd = sprintf('read -r LINE < %s && echo $LINE', $file->getFullPath());
     $process = $this->getProcess($cmd);
     $process->run();
     if (!in_array(trim($process->getOutput()), ['<?php', '#!/usr/bin/env php'])) {
         $message = 'File must begin with `<?php` or `#!/usr/bin/env php`';
         $reporter->error($message, $this, $file);
     }
 }
 /**
  * Check the composer.json file is valid.
  *
  * @param ReporterInterface   $reporter
  * @param ReviewableInterface $file
  */
 public function review(ReporterInterface $reporter, ReviewableInterface $file)
 {
     $cmd = sprintf('composer validate %s', $file->getFullPath());
     $process = $this->getProcess($cmd);
     $process->run();
     if (!$process->isSuccessful() && strpos($process->getErrorOutput(), 'composer.json is valid') === false) {
         $message = 'The composer configuration is not valid';
         $reporter->error($message, $this, $file);
     }
 }
 /**
  * Checks if the set file starts with the correct character sequence, which
  * helps to stop any rouge whitespace making it in before the first php tag.
  *
  * @link http://stackoverflow.com/a/2440685
  */
 public function review(ReporterInterface $reporter, ReviewableInterface $file)
 {
     $f = fopen($file->getFullPath(), 'r');
     $line = fgets($f);
     fclose($f);
     if (!in_array(trim($line), ['<?php', '#!/usr/bin/env php'])) {
         $message = 'File must begin with `<?php` or `#!/usr/bin/env php`';
         $reporter->error($message, $this, $file);
     }
 }
 /**
  * Check the composer.lock file doesn't contain dependencies
  * with known security vulnerabilities.
  *
  * @param ReporterInterface $reporter
  * @param FileInterface     $file
  */
 public function review(ReporterInterface $reporter, ReviewableInterface $file)
 {
     $executable = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, 'vendor/bin/security-checker');
     $cmd = sprintf('%s security:check %s', $executable, $file->getFullPath());
     $process = $this->getProcess($cmd);
     $process->run();
     if (!$process->isSuccessful()) {
         $message = 'The composer project dependencies contain known vulnerabilities';
         $reporter->error($message, $this, $file);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function review(ReporterInterface $reporter, ReviewableInterface $file = null)
 {
     $cmd = sprintf('xmllint --noout %s', $file->getFullPath());
     $process = $this->getProcess($cmd);
     $process->run();
     if (!$process->isSuccessful()) {
         $output = $process->getErrorOutput();
         preg_match('/:([0-9]+):/i', $output, $matches);
         $line = isset($matches[1]) ? $matches[1] : null;
         $reporter->error('Unable to parse the XML file', $this, $file, $line);
     }
 }
 public function review(ReporterInterface $reporter, ReviewableInterface $file = null)
 {
     $cmd = sprintf('jsonlint %s', $file->getFullPath());
     $process = $this->getProcess($cmd);
     $process->run();
     $output = array_filter(explode(PHP_EOL, $process->getErrorOutput()));
     if (!$process->isSuccessful()) {
         $error = $output[0];
         $raw = substr($error, 0, -1);
         $message = str_replace($file->getFullPath() . ': ', '', $raw);
         $reporter->error($message, $this, $file);
     }
 }
 /**
  * Checks PHP StopWords.
  */
 public function review(ReporterInterface $reporter, ReviewableInterface $file = null)
 {
     $stopWordsPhp = array('var_dump()' => '[^a-zA-Z]var_dump(', 'die()' => '[^a-zA-Z]die(');
     // Check StopWords
     foreach ($stopWordsPhp as $key => $word) {
         $cmd = sprintf('grep --ignore-case --quiet \'%s\' %s', $word, $file->getFullPath());
         $process = $this->getProcess($cmd);
         $process->run();
         if ($process->isSuccessful()) {
             $reporter->error(sprintf('expr "%s" detected', $key), $this, $file);
         }
     }
 }
 /**
  * Git conflict review.
  *
  * @param ReporterInterface   $reporter
  * @param ReviewableInterface $file
  */
 public function review(ReporterInterface $reporter, ReviewableInterface $file = null)
 {
     $gitConflictMarkers = array('>>>>>>', '<<<<<<');
     // Check Git Conflict Markers
     foreach ($gitConflictMarkers as $word) {
         $cmd = sprintf('grep --fixed-strings --ignore-case --quiet "%s" %s', $word, $file->getFullPath());
         $process = $this->getProcess($cmd);
         $process->run();
         if ($process->isSuccessful()) {
             $reporter->error(sprintf('Git Conflict marker "%s" detected', $word), $this, $file);
         }
     }
 }
 /**
  * Reviewing method.
  *
  * @param ReporterInterface   $reporter
  * @param ReviewableInterface $file
  */
 public function review(ReporterInterface $reporter, ReviewableInterface $file = null)
 {
     // JavaScript debug code that would break IE.
     $stopWordsJs = array('console.debug()' => 'console.debug', 'console.log()' => 'console.log', 'alert()' => '[^a-zA-Z]alert(');
     // Check StopWords
     foreach ($stopWordsJs as $key => $word) {
         $cmd = sprintf('grep --ignore-case --quiet \'%s\' %s', $word, $file->getFullPath());
         $process = $this->getProcess($cmd);
         $process->run();
         if ($process->isSuccessful()) {
             $reporter->error(sprintf('expr "%s" detected', $key), $this, $file);
         }
     }
 }
 /**
  * Git conflict review.
  *
  * @param ReporterInterface $reporter
  */
 public function review(ReporterInterface $reporter, ReviewableInterface $file = null)
 {
     if ($this->phpUnitConfigPath && !(is_file($this->phpUnitConfigPath) || is_file($this->projectBase . '/' . $this->phpUnitConfigPath))) {
         $reporter->error('Phpunit config path is not correct.', $this, $file);
         return;
     }
     $cmd = sprintf('export SYMFONY_DEPRECATIONS_HELPER=%s;', self::LEVEL_SYMFONY_DEPRECATION_WEAK);
     $cmd .= sprintf('%s --exclude_group slow --stop-on-failure%s', $this->phpUnitBinPath, $this->phpUnitConfigPath ? ' -c ' . $this->phpUnitConfigPath : '');
     $process = $this->getProcess($cmd, $this->projectBase, null, null, 960);
     echo "\n";
     $process->run(function ($type, $buffer) {
         if (Process::ERR !== $type) {
             if (in_array($buffer, array('.', 'F', 'E', 'R', 'S', 'I')) || preg_match('/\\( [0-9]+\\%\\)/', $buffer)) {
                 echo $buffer;
             }
         }
     });
     echo "\n";
     if (preg_match('|Usage: phpunit|i', $process->getOutput())) {
         $reporter->error('You must specify Phpunit config path [--phpunit-conf PATH].', $this, $file);
     } elseif (!$process->isSuccessful()) {
         $reporter->error('Fix the Unit Tests !!!', $this, $file);
     }
 }
 /**
  * @param ReporterInterface        $reporter
  * @param ReviewableInterface|null $file
  */
 public function review(ReporterInterface $reporter, ReviewableInterface $file = null)
 {
     // delete PHP code in yaml files to avoid ParseException
     $ymlData = preg_replace('|(<\\?php.*\\?>)|i', '', file_get_contents($file->getFullPath()));
     // delete Namespace string to avoid ParseException with escape caracter
     $ymlData = preg_replace('|([\\\\]{1}[a-z]+)|i', '', $ymlData);
     // delete reserved indicator "@" to avoid ParseException
     $ymlData = preg_replace('|(@)|i', '', $ymlData);
     try {
         Yaml::parse($ymlData, false, true);
     } catch (ParseException $e) {
         preg_match('/at line ([0-9]+)/i', $e->getMessage(), $matches);
         $line = isset($matches[1]) ? $matches[1] : null;
         $reporter->error('Unable to parse the YAML file', $this, $file, $line);
     }
 }
Beispiel #23
0
 /**
  * Checks PHP files using the builtin PHP linter, `php -l`.
  */
 public function review(ReporterInterface $reporter, FileInterface $file)
 {
     $cmd = sprintf('php --syntax-check %s', $file->getFullPath());
     $process = $this->getProcess($cmd);
     $process->run();
     // Create the array of outputs and remove empty values.
     $output = array_filter(explode(PHP_EOL, $process->getOutput()));
     $needle = 'Parse error: syntax error, ';
     if (!$process->isSuccessful()) {
         foreach (array_slice($output, 0, count($output) - 1) as $error) {
             $raw = ucfirst(substr($error, strlen($needle)));
             $message = str_replace(' in ' . $file->getFullPath(), '', $raw);
             $reporter->error($message, $this, $file);
         }
     }
 }
 /**
  * Checks PHP files using PHP_CodeSniffer.
  */
 public function review(ReporterInterface $reporter, ReviewableInterface $file = null)
 {
     $cmd = '~/.composer/vendor/bin/phpcs --report=json ';
     if ($this->getOptionsForConsole()) {
         $cmd .= $this->getOptionsForConsole();
     }
     $cmd .= $file->getFullPath();
     $process = $this->getProcess($cmd);
     $process->run();
     if (!$process->isSuccessful()) {
         // Create the array of outputs and remove empty values.
         $output = json_decode($process->getOutput(), true);
         $filter = function ($acc, $file) {
             if ($file['errors'] > 0 || $file['warnings'] > 0) {
                 return $acc + $file['messages'];
             }
         };
         foreach (array_reduce($output['files'], $filter, []) as $error) {
             if ($error['message'] == 'Missing function doc comment') {
                 $reporter->error('Missing PHPDoc function doc comment', $this, $file, $error['line']);
             }
         }
     }
 }