diff --git a/src/lint/linter/ArcanistPhpLinter.php b/src/lint/linter/ArcanistPhpLinter.php new file mode 100644 --- /dev/null +++ b/src/lint/linter/ArcanistPhpLinter.php @@ -0,0 +1,81 @@ +getDeprecatedConfiguration('lint.php.bin', 'php'); + } + + public function getVersion() { + list($stdout) = execx('%C --version', $this->getExecutableCommand()); + + $matches = array(); + $regex = '/^PHP (?P\d+\.\d+\.\d+)\b/'; + if (preg_match($regex, $stdout, $matches)) { + return $matches['version']; + } else { + return false; + } + } + + public function shouldExpectCommandErrors() { + return true; + } + + public function supportsReadDataFromStdin() { + return false; + } + + protected function parseLinterOutput($path, $err, $stdout, $stderr) { + $matches = array(); + if (preg_match('/syntax error, (.*?) in (.*?) on line (\d*)/', + $stdout, $matches)) { + + $message = new ArcanistLintMessage(); + $message->setPath($matches[2]); + $message->setLine($matches[3]); + $message->setCode('php.syntax'); + $message->setDescription('This file contains a syntax error: '. + $matches[1].' on line '.$matches[3]); + $message->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR); + + // php -l only returns the first syntax error + return array($message); + } + + return array(); + } + +}