/**
  * 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();
             }
         }
     }
 }
 /**
  * @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 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);
     }
 }
Example #4
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 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);
             }
         }
     }
 }
 /**
  * Checks PHP files using PHP_CodeSniffer.
  */
 public function review(ReporterInterface $reporter, FileInterface $file)
 {
     $cmd = '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) {
             $message = $error['message'] . ' on line ' . $error['line'];
             $reporter->warning($message, $this, $file);
         }
     }
 }
Example #8
0
 /**
  * @param ReporterInterface   $reporter
  * @param ReviewableInterface $subject
  * @param string              $message
  */
 protected function scanMessage(ReporterInterface $reporter, ReviewableInterface $subject, string $message)
 {
     $this->getClimate()->yellow($message);
     $reporter->warning($message, $this, $subject);
 }