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);
     }
 }
예제 #2
0
 /**
  * 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 (!preg_match('/^[A-Z]/u', $commit->getSubject())) {
         $message = 'Subject line must begin with a capital letter';
         $reporter->error($message, $this, $commit);
     }
 }
예제 #5
0
 /**
  * check blackList files.
  *
  * @param ReviewableInterface $fileName
  *
  * @return bool
  */
 public function isBlacklistFile(ReviewableInterface $fileName)
 {
     if (strpos($fileName->getName(), '.js.php') !== false) {
         return true;
     }
     $blacklistFiles = array('_inline_end_js.mobile.php', '_inline_end_js.php');
     return in_array($fileName->getName(), $blacklistFiles);
 }
 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 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);
     }
 }
예제 #9
0
 /**
  * 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 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);
     }
 }
예제 #11
0
 /**
  * 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)
 {
     $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 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);
     }
 }
예제 #14
0
 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);
         }
     }
 }
 /**
  * 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);
     }
 }
예제 #16
0
 /**
  * {@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);
     }
 }
 /**
  * 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);
         }
     }
 }
 /**
  * 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);
     }
 }
예제 #19
0
 /**
  * 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);
         }
     }
 }
예제 #20
0
 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);
     }
 }
예제 #21
0
 /**
  * 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);
         }
     }
 }
예제 #22
0
 /**
  * Checks PHP files using the builtin PHP linter, `php -l`.
  */
 public function review(ReporterInterface $reporter, ReviewableInterface $file = null)
 {
     $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->getErrorOutput()));
     $needle = 'PHP Parse error:  syntax error, ';
     if (!$process->isSuccessful()) {
         foreach ($output as $error) {
             $raw = ucfirst(substr($error, strlen($needle)));
             $message = str_replace(' in ' . $file->getFullPath(), '', $raw);
             $reporter->error($message, $this, $file);
         }
     }
 }
예제 #23
0
 /**
  * @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);
     }
 }
예제 #24
0
 /**
  * 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);
         }
     }
 }
예제 #25
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);
         }
     }
 }
예제 #26
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);
             }
         }
     }
 }
예제 #27
0
 /**
  * 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();
             }
         }
     }
 }
 /**
  * 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']);
             }
         }
     }
 }
예제 #29
0
 /**
  * Checks PHP files using PHP_CodeSniffer.
  */
 public function review(ReporterInterface $reporter, ReviewableInterface $file)
 {
     $bin = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, 'vendor/bin/phpcs');
     $cmd = $bin . ' --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) {
             $message = $error['message'] . ' on line ' . $error['line'];
             $reporter->warning($message, $this, $file);
         }
     }
 }
예제 #30
0
 /**
  * @param ReviewableInterface $subject
  *
  * @return string
  */
 protected function getCommandLine(ReviewableInterface $subject) : string
 {
     return 'vendor/bin/php-cs-fixer -vvv fix ' . $subject->getName() . ' --level=symfony';
 }