本文整理汇总了PHP中PHP_CodeSniffer_File::addWarningOnLine方法的典型用法代码示例。如果您正苦于以下问题:PHP PHP_CodeSniffer_File::addWarningOnLine方法的具体用法?PHP PHP_CodeSniffer_File::addWarningOnLine怎么用?PHP PHP_CodeSniffer_File::addWarningOnLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHP_CodeSniffer_File
的用法示例。
在下文中一共展示了PHP_CodeSniffer_File::addWarningOnLine方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
/**
* 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 jshint.js could not be run
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$fileName = $phpcsFile->getFilename();
$rhinoPath = PHP_CodeSniffer::getConfigData('rhino_path');
$jshintPath = PHP_CodeSniffer::getConfigData('jshint_path');
if ($rhinoPath === null || $jshintPath === null) {
return;
}
$cmd = "{$rhinoPath} \"{$jshintPath}\" \"{$fileName}\"";
$msg = exec($cmd, $output, $retval);
if (is_array($output) === true) {
foreach ($output as $finding) {
$matches = array();
$numMatches = preg_match('/^(.+)\\(.+:([0-9]+).*:[0-9]+\\)$/', $finding, $matches);
if ($numMatches === 0) {
continue;
}
$line = (int) $matches[2];
$message = 'jshint says: ' . trim($matches[1]);
$phpcsFile->addWarningOnLine($message, $line, 'ExternalTool');
}
}
// Ignore the rest of the file.
return $phpcsFile->numTokens + 1;
}
示例2: process
/**
* 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(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$fileName = $phpcsFile->getFilename();
$jslPath = PHP_CodeSniffer::getConfigData('jsl_path');
if (is_null($jslPath) === true) {
return;
}
$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 PHP_CodeSniffer_Exception("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;
}
示例3: process
/**
* 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(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$fileName = $phpcsFile->getFilename();
$csslintPath = PHP_CodeSniffer::getConfigData('csslint_path');
if ($csslintPath === null) {
return;
}
$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;
}
示例4: checkIfTokenIsCodeIgnoreAnnotation
/**
* @param PHP_CodeSniffer_File $phpCsFile
* @param array $token
*/
private function checkIfTokenIsCodeIgnoreAnnotation(\PHP_CodeSniffer_File $phpCsFile, $token)
{
$tagType = $this->getTagType($token['content']);
switch ($tagType) {
case 0:
$errorMessage = $this->tagTypes[0] . "-tag detected at line: " . $token['line'];
$phpCsFile->addWarningOnLine($errorMessage, $token['line']);
break;
case 1:
$errorMessage = $this->tagTypes[1] . "-tag detected at line: " . $token['line'];
$phpCsFile->addWarningOnLine($errorMessage, $token['line']);
break;
case 2:
$errorMessage = $this->tagTypes[2] . "-tag detected at line: " . $token['line'];
$phpCsFile->addWarningOnLine($errorMessage, $token['line']);
break;
}
}
示例5: process
/**
* 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(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$fileName = $phpcsFile->getFilename();
$lintPath = PHP_CodeSniffer::getConfigData('gjslint_path');
if ($lintPath === null) {
return;
}
$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;
}
示例6: process
/**
* 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(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$fileName = $phpcsFile->getFilename();
$analyzerPath = PHP_CodeSniffer::getConfigData('zend_ca_path');
if (is_null($analyzerPath) === true) {
return;
}
// 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 PHP_CodeSniffer_Exception("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;
}