1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-08 16:02:39 +01:00

Add constants and class methods to php_compat_info.json.

Summary: Allows the `ArcanistXHPASTLinter` to determine whether constants can be used, based on the target PHP version. Also added class methods to the compatibility information, although this isn't used yet (it is small anyway).

Test Plan: Created a test file that contained the `JSON_PRETTY_PRINT` constant. Verified that a linter error was raised.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D9571
This commit is contained in:
Joshua Spence 2014-06-17 01:00:23 +10:00
parent 8f8ab969db
commit 36698b92af
3 changed files with 6118 additions and 1 deletions

File diff suppressed because it is too large Load diff

View file

@ -14,6 +14,8 @@ $output['params'] = array();
$output['functions'] = array();
$output['classes'] = array();
$output['interfaces'] = array();
$output['constants'] = array();
$output['classMethods'] = array();
$references = array(
new \Bartlett\CompatInfo\Reference\Extension\ApcExtension(),
@ -71,12 +73,34 @@ foreach ($references as $reference) {
'max' => nonempty($compat['php.max'], null),
);
}
foreach ($reference->getConstants() as $constant => $compat) {
$output['constants'][$constant] = array(
'min' => nonempty($compat['php.min'], null),
'max' => nonempty($compat['php.max'], null),
);
}
foreach ($reference->getClassMethods() as $class => $methods) {
if (!array_key_exists($class, $output['classMethods'])) {
$output['classMethods'][$class] = array();
}
foreach ($methods as $method => $compat) {
$output['classMethods'][$class][$method] = array(
'min' => nonempty($compat['php.min'], null),
'max' => nonempty($compat['php.max'], null),
);
}
}
}
ksort($output['params']);
ksort($output['functions']);
ksort($output['classes']);
ksort($output['interfaces']);
ksort($output['constants']);
ksort($output['classMethods']);
// Grepped from PHP Manual.
$output['functions_windows'] = array(

View file

@ -188,7 +188,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
public function getVersion() {
// The version number should be incremented whenever a new rule is added.
return '5';
return '6';
}
protected function resolveFuture($path, Future $future) {
@ -499,6 +499,21 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
}
}
// TODO: Technically, this will include function names. This is unlikely to
// cause any issues (unless, of course, there existed a function that had
// the same name as some constant).
$constants = $root->selectDescendantsOfType('n_SYMBOL_NAME');
foreach ($constants as $node) {
$name = $node->getConcreteString();
$version = idx($compat_info['constants'], $name);
if ($version && version_compare($version['min'], $required, '>')) {
$this->raiseLintAtNode(
$node,
self::LINT_PHP_53_FEATURES,
"This codebase targets PHP 5.2.3, but `{$name}` was not ".
"introduced until PHP {$version['min']}.");
}
}
}
public function lintPHP54Features(XHPASTNode $root) {