Example #1
0
 /**
  * Processes the tokens that this sniff is interested in.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
  * @param int                  $stackPtr  The position in the stack where
  *                                        the token was found.
  *
  * @return void
  * @throws PHP_CodeSniffer_Exception If jslint.js could not be run
  */
 public function process(File $phpcsFile, $stackPtr)
 {
     $rhinoPath = Config::getExecutablePath('jslint');
     $jslintPath = Config::getExecutablePath('jslint');
     if ($rhinoPath === null || $jslintPath === null) {
         return;
     }
     $fileName = $phpcsFile->getFilename();
     $cmd = "{$rhinoPath} \"{$jslintPath}\" \"{$fileName}\"";
     $msg = exec($cmd, $output, $retval);
     if (is_array($output) === true) {
         foreach ($output as $finding) {
             $matches = array();
             $numMatches = preg_match('/Lint at line ([0-9]+).*:(.*)$/', $finding, $matches);
             if ($numMatches === 0) {
                 continue;
             }
             $line = (int) $matches[1];
             $message = 'jslint says: ' . trim($matches[2]);
             $phpcsFile->addWarningOnLine($message, $line, 'ExternalTool');
         }
     }
     // Ignore the rest of the file.
     return $phpcsFile->numTokens + 1;
 }
Example #2
0
 /**
  * Processes this test, when one of its tokens is encountered.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
  * @param int                  $stackPtr  The position of the current token in
  *                                        the stack passed in $tokens.
  *
  * @return void
  */
 public function process(File $phpcsFile, $stackPtr)
 {
     if ($this->phpPath === null) {
         $this->phpPath = Config::getExecutablePath('php');
         if ($this->phpPath === null) {
             // PHP_BINARY is available in PHP 5.4+.
             if (defined('PHP_BINARY') === true) {
                 $this->phpPath = PHP_BINARY;
             } else {
                 return;
             }
         }
     }
     $fileName = $phpcsFile->getFilename();
     $cmd = $this->phpPath . " -l \"{$fileName}\" 2>&1";
     $output = shell_exec($cmd);
     $matches = array();
     if (preg_match('/^.*error:(.*) in .* on line ([0-9]+)/', trim($output), $matches) === 1) {
         $error = trim($matches[1]);
         $line = (int) $matches[2];
         $phpcsFile->addErrorOnLine("PHP syntax error: {$error}", $line, 'PHPSyntax');
     }
     // Ignore the rest of the file.
     return $phpcsFile->numTokens + 1;
 }
Example #3
0
 /**
  * Processes the tokens that this sniff is interested in.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
  * @param int                  $stackPtr  The position in the stack where
  *                                        the token was found.
  *
  * @return void
  */
 public function process(File $phpcsFile, $stackPtr)
 {
     $jslPath = Config::getExecutablePath('jsl');
     if (is_null($jslPath) === true) {
         return;
     }
     $fileName = $phpcsFile->getFilename();
     $cmd = '"' . $jslPath . '" -nologo -nofilelisting -nocontext -nosummary -output-format __LINE__:__ERROR__ -process "' . $fileName . '"';
     $msg = exec($cmd, $output, $retval);
     // Variable $exitCode is the last line of $output if no error occurs, on
     // error it is numeric. Try to handle various error conditions and
     // provide useful error reporting.
     if ($retval === 2 || $retval === 4) {
         if (is_array($output) === true) {
             $msg = join('\\n', $output);
         }
         throw new RuntimeException("Failed invoking JavaScript Lint, retval was [{$retval}], output was [{$msg}]");
     }
     if (is_array($output) === true) {
         foreach ($output as $finding) {
             $split = strpos($finding, ':');
             $line = substr($finding, 0, $split);
             $message = substr($finding, $split + 1);
             $phpcsFile->addWarningOnLine(trim($message), $line, 'ExternalTool');
         }
     }
     // Ignore the rest of the file.
     return $phpcsFile->numTokens + 1;
 }
Example #4
0
 /**
  * Processes the tokens that this sniff is interested in.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
  * @param int                  $stackPtr  The position in the stack where
  *                                        the token was found.
  *
  * @return void
  */
 public function process(File $phpcsFile, $stackPtr)
 {
     $csslintPath = Config::getExecutablePath('csslint');
     if ($csslintPath === null) {
         return;
     }
     $fileName = $phpcsFile->getFilename();
     $cmd = $csslintPath . ' ' . escapeshellarg($fileName);
     exec($cmd, $output, $retval);
     if (is_array($output) === false) {
         return;
     }
     $count = count($output);
     for ($i = 0; $i < $count; $i++) {
         $matches = array();
         $numMatches = preg_match('/(error|warning) at line (\\d+)/', $output[$i], $matches);
         if ($numMatches === 0) {
             continue;
         }
         $line = (int) $matches[2];
         $message = 'csslint says: ' . $output[$i + 1];
         // First line is message with error line and error code.
         // Second is error message.
         // Third is wrong line in file.
         // Fourth is empty line.
         $i += 4;
         $phpcsFile->addWarningOnLine($message, $line, 'ExternalTool');
     }
     //end for
     // Ignore the rest of the file.
     return $phpcsFile->numTokens + 1;
 }
Example #5
0
 /**
  * Should this test be skipped for some reason.
  *
  * @return void
  */
 protected function shouldSkipTest()
 {
     if (defined('PHP_BINARY') === true) {
         return false;
     }
     $phpPath = Config::getExecutablePath('php');
     if ($phpPath === null) {
         return true;
     }
     return false;
 }
Example #6
0
 /**
  * Load configuration data.
  */
 public function __construct()
 {
     $path = Config::getExecutablePath('notifysend');
     if ($path !== null) {
         $this->path = $path;
     }
     $timeout = Config::getConfigData('notifysend_timeout');
     if ($timeout !== null) {
         $this->timeout = (int) $timeout;
     }
     $showOk = Config::getConfigData('notifysend_showok');
     if ($showOk !== null) {
         $this->showOk = (bool) $showOk;
     }
     $this->version = str_replace('notify-send ', '', exec($this->path . ' --version'));
 }
Example #7
0
 /**
  * Processes the tokens that this sniff is interested in.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
  * @param int                  $stackPtr  The position in the stack where
  *                                        the token was found.
  *
  * @return int
  */
 public function process(File $phpcsFile, $stackPtr)
 {
     $analyzerPath = Config::getExecutablePath('zend_ca');
     if (is_null($analyzerPath) === true) {
         return;
     }
     $fileName = $phpcsFile->getFilename();
     // In the command, 2>&1 is important because the code analyzer sends its
     // findings to stderr. $output normally contains only stdout, so using 2>&1
     // will pipe even stderr to stdout.
     $cmd = $analyzerPath . ' ' . $fileName . ' 2>&1';
     // There is the possibility to pass "--ide" as an option to the analyzer.
     // This would result in an output format which would be easier to parse.
     // The problem here is that no cleartext error messages are returnwd; only
     // error-code-labels. So for a start we go for cleartext output.
     $exitCode = exec($cmd, $output, $retval);
     // Variable $exitCode is the last line of $output if no error occures, on
     // error it is numeric. Try to handle various error conditions and
     // provide useful error reporting.
     if (is_numeric($exitCode) === true && $exitCode > 0) {
         if (is_array($output) === true) {
             $msg = join('\\n', $output);
         }
         throw new RuntimeException("Failed invoking ZendCodeAnalyzer, exitcode was [{$exitCode}], retval was [{$retval}], output was [{$msg}]");
     }
     if (is_array($output) === true) {
         foreach ($output as $finding) {
             // The first two lines of analyzer output contain
             // something like this:
             // > Zend Code Analyzer 1.2.2
             // > Analyzing <filename>...
             // So skip these...
             $res = preg_match("/^.+\\(line ([0-9]+)\\):(.+)\$/", $finding, $regs);
             if (empty($regs) === true || $res === false) {
                 continue;
             }
             $phpcsFile->addWarningOnLine(trim($regs[2]), $regs[1], 'ExternalTool');
         }
     }
     // Ignore the rest of the file.
     return $phpcsFile->numTokens + 1;
 }
Example #8
0
 /**
  * Processes the tokens that this sniff is interested in.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
  * @param int                  $stackPtr  The position in the stack where
  *                                        the token was found.
  *
  * @return void
  * @throws PHP_CodeSniffer_Exception If jslint.js could not be run
  */
 public function process(File $phpcsFile, $stackPtr)
 {
     $lintPath = Config::getExecutablePath('gjslint');
     if ($lintPath === null) {
         return;
     }
     $fileName = $phpcsFile->getFilename();
     $cmd = "{$lintPath} --nosummary --notime --unix_mode \"{$fileName}\"";
     $msg = exec($cmd, $output, $retval);
     if (is_array($output) === false) {
         return;
     }
     foreach ($output as $finding) {
         $matches = array();
         $numMatches = preg_match('/^(.*):([0-9]+):\\(.*?([0-9]+)\\)(.*)$/', $finding, $matches);
         if ($numMatches === 0) {
             continue;
         }
         // Skip error codes we are ignoring.
         $code = $matches[3];
         if (in_array($code, $this->ignoreCodes) === true) {
             continue;
         }
         $line = (int) $matches[2];
         $error = trim($matches[4]);
         $message = 'gjslint says: (%s) %s';
         $data = array($code, $error);
         if (in_array($code, $this->errorCodes) === true) {
             $phpcsFile->addErrorOnLine($message, $line, 'ExternalToolError', $data);
         } else {
             $phpcsFile->addWarningOnLine($message, $line, 'ExternalTool', $data);
         }
     }
     //end foreach
     // Ignore the rest of the file.
     return $phpcsFile->numTokens + 1;
 }
Example #9
0
 /**
  * Should this test be skipped for some reason.
  *
  * @return void
  */
 protected function shouldSkipTest()
 {
     $analyzerPath = Config::getExecutablePath('zend_ca');
     return is_null($analyzerPath);
 }
Example #10
0
 /**
  * Should this test be skipped for some reason.
  *
  * @return void
  */
 protected function shouldSkipTest()
 {
     $jslPath = Config::getExecutablePath('jslint');
     return is_null($jslPath);
 }