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);
     }
 }
 /**
  * @param ReporterInterface   $reporter
  * @param ReviewableInterface $subject
  * @param string              $message
  */
 protected function scanMessage(ReporterInterface $reporter, ReviewableInterface $subject, string $message)
 {
     $this->getClimate()->out($message);
     if (strpos($message, 'ERROR')) {
         $reporter->warning($message, $this, $subject);
     }
 }
 /**
  * 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 (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)
 {
     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)
 {
     $regex = '/^(?:' . implode('|', $this->incorrect) . ')/i';
     if (preg_match($regex, $commit->getSubject())) {
         $message = 'Subject line must use imperative present tense';
         $reporter->error($message, $this, $commit);
     }
 }
Example #7
0
 /**
  * @param ReporterInterface   $reporter
  * @param ReviewableInterface $subject
  * @param string              $message
  */
 protected function scanMessage(ReporterInterface $reporter, ReviewableInterface $subject, string $message)
 {
     if ($message == 'F') {
         $message = 'Styling has been fixed in ' . $subject->getName();
         $this->getClimate()->green($message);
         $reporter->info($message, $this, $subject);
     }
 }
 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);
     }
 }
Example #9
0
 /**
  * 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);
     }
 }
 /**
  * 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);
     }
 }
 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 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);
     }
 }
 /**
  * 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.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);
     }
 }
 /**
  * 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.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);
     }
 }
 /**
  * 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);
         }
     }
 }
 /**
  * Checks Composer json and lock files.
  */
 public function review(ReporterInterface $reporter, ReviewableInterface $file = null)
 {
     if ($file->getFileName() == 'composer.json') {
         $this->composerJsonDetected = true;
     }
     if ($file->getFileName() == 'composer.lock') {
         $this->composerLockDetected = true;
     }
     // Check if we are on the Last File
     if ($reporter->getCurrent() - 1 == $reporter->getTotal() && $this->composerJsonDetected && !$this->composerLockDetected) {
         $reporter->warning('You must commit composer.lock with composer.json', $this);
     }
 }
 /**
  * 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);
         }
     }
 }
 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);
     }
 }
 /**
  * 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);
         }
     }
 }
 /**
  * @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);
     }
 }
Example #25
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);
         }
     }
 }
Example #26
0
 /**
  * Checks PHP files using the builtin PHP linter, `php -l`.
  */
 public function review(ReporterInterface $reporter, ReviewableInterface $file = null)
 {
     // PHP Mess Detector
     $cmd = sprintf('phpmd %s text %s', $file->getFullPath(), self::PHP_MD_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 ($output as $error) {
             preg_match('/:([0-9]+)/i', $error, $matches);
             $line = isset($matches[1]) ? $matches[1] : null;
             $error = str_replace("\t", ' ', $error);
             $message = trim(str_replace($file->getFullPath() . ':' . $line, '', $error));
             $reporter->warning($message, $this, $file, $line);
         }
     }
 }
 /**
  * Checks SCSS files using the builtin eslint, `eslint`.
  */
 public function review(ReporterInterface $reporter, ReviewableInterface $file = null)
 {
     // PHP Mess Detector
     $cmd = sprintf('scss-lint -c %s %s', self::SCSS_SCSSLINT_RULE_DIR, $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()));
     if (!$process->isSuccessful()) {
         foreach ($output as $error) {
             preg_match('/(.*):([0-9]+)(.*)/i', $error, $matches);
             $line = isset($matches[2]) ? $matches[2] : null;
             $error = $matches[1] . $matches[3];
             $message = trim(str_replace($file->getFullPath(), '', $error));
             $reporter->warning($message, $this, $file, $line);
         }
     }
 }
 /**
  * Checks PHP files using php-cs-fixer.
  */
 public function review(ReporterInterface $reporter, ReviewableInterface $file = null)
 {
     $cmd = sprintf('php-cs-fixer fix -v %s --config-file %s', $file->getFullPath(), self::PHP_CS_FIXER_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, 3, -1) as $error) {
             $raw = ucfirst($error);
             $message = trim(str_replace('   1) ' . $file->getFullPath(), '', $raw));
             $reporter->info($message, $this, $file);
             if ($this->autoAddGit) {
                 $cmd = sprintf('git add %s', $file->getFullPath());
                 $process = $this->getProcess($cmd);
                 $process->run();
             }
         }
     }
 }
Example #29
0
 /**
  * Checks PHP files using the builtin PHP linter, `php -l`.
  */
 public function review(ReporterInterface $reporter, ReviewableInterface $file = null)
 {
     $cmd = sprintf('phpcpd --min-lines %s --min-tokens %s %s', self::PHP_CPD_MIN_LINES, self::PHP_CPD_MIN_TOKENS, $file->getFullPath());
     $process = $this->getProcess($cmd);
     $process->run();
     // Create the array of outputs and remove empty values.
     $output = $process->getOutput();
     if (!$process->isSuccessful()) {
         // get dupplicate code ratio
         preg_match("|([0-9]{1,2}\\.[0-9]{1,2}%)|i", $output, $resultcpd);
         if (isset($resultcpd[1]) && $resultcpd[1] != '0.00%') {
             $output = array_filter(explode(PHP_EOL, $process->getOutput()));
             foreach (array_slice($output, 1, -3) as $error) {
                 //$raw = ucfirst(substr($error, strlen($needle)));
                 $error = str_replace($file->getFullPath(), '', $error);
                 $reporter->warning($error, $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);
     }
 }