Changeset View
Changeset View
Standalone View
Standalone View
src/lint/linter/ArcanistPhpLinter.php
- This file was added.
<?php | |||||
/** | |||||
* Uses "php -l" to detect syntax errors in PHP code. | |||||
*/ | |||||
final class ArcanistPhpLinter extends ArcanistExternalLinter { | |||||
public function getInfoName() { | |||||
return 'php -l'; | |||||
} | |||||
public function getInfoURI() { | |||||
return 'http://php.net/'; | |||||
} | |||||
public function getInfoDescription() { | |||||
return pht( | |||||
'Checks for syntax errors in php files'); | |||||
epriestley: Add punctuation. | |||||
} | |||||
public function getLinterName() { | |||||
return 'PHP'; | |||||
} | |||||
public function getLinterConfigurationName() { | |||||
return 'php'; | |||||
} | |||||
public function getMandatoryFlags() { | |||||
return array('-l'); | |||||
} | |||||
public function getInstallInstructions() { | |||||
return pht('Install PHP'); | |||||
epriestleyUnsubmitted Not Done Inline ActionsAdd punctuation. epriestley: Add punctuation. | |||||
} | |||||
public function getDefaultBinary() { | |||||
return $this->getDeprecatedConfiguration('lint.php.bin', 'php'); | |||||
epriestleyUnsubmitted Not Done Inline ActionsReturn 'php' instead. Don't introduce deprecated configuration. The "bin" option covers this now. epriestley: Return `'php'` instead. Don't introduce deprecated configuration. The "bin" option covers this… | |||||
} | |||||
public function getVersion() { | |||||
list($stdout) = execx('%C --version', $this->getExecutableCommand()); | |||||
$matches = array(); | |||||
$regex = '/^PHP (?P<version>\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(); | |||||
} | |||||
} |
Add punctuation.