function SyntaxSniff::process
Processes this test, when one of its tokens is encountered.
Parameters
\PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.:
int $stackPtr The position of the current token in: the stack passed in $tokens.
Return value
int
Overrides Sniff::process
File
-
vendor/
squizlabs/ php_codesniffer/ src/ Standards/ Generic/ Sniffs/ PHP/ SyntaxSniff.php, line 53
Class
Namespace
PHP_CodeSniffer\Standards\Generic\Sniffs\PHPCode
public function process(File $phpcsFile, $stackPtr) {
if ($this->phpPath === null) {
$this->phpPath = Config::getExecutablePath('php');
}
$fileName = escapeshellarg($phpcsFile->getFilename());
$cmd = Common::escapeshellcmd($this->phpPath) . " -l -d display_errors=1 -d error_prepend_string='' {$fileName} 2>&1";
$output = shell_exec($cmd);
$matches = [];
if (preg_match('/^.*error:(.*) in .* on line ([0-9]+)/m', 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;
}