mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-22 06:42:41 +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:
parent
8f8ab969db
commit
36698b92af
3 changed files with 6118 additions and 1 deletions
File diff suppressed because it is too large
Load diff
|
@ -14,6 +14,8 @@ $output['params'] = array();
|
||||||
$output['functions'] = array();
|
$output['functions'] = array();
|
||||||
$output['classes'] = array();
|
$output['classes'] = array();
|
||||||
$output['interfaces'] = array();
|
$output['interfaces'] = array();
|
||||||
|
$output['constants'] = array();
|
||||||
|
$output['classMethods'] = array();
|
||||||
|
|
||||||
$references = array(
|
$references = array(
|
||||||
new \Bartlett\CompatInfo\Reference\Extension\ApcExtension(),
|
new \Bartlett\CompatInfo\Reference\Extension\ApcExtension(),
|
||||||
|
@ -71,12 +73,34 @@ foreach ($references as $reference) {
|
||||||
'max' => nonempty($compat['php.max'], null),
|
'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['params']);
|
||||||
ksort($output['functions']);
|
ksort($output['functions']);
|
||||||
ksort($output['classes']);
|
ksort($output['classes']);
|
||||||
ksort($output['interfaces']);
|
ksort($output['interfaces']);
|
||||||
|
ksort($output['constants']);
|
||||||
|
ksort($output['classMethods']);
|
||||||
|
|
||||||
// Grepped from PHP Manual.
|
// Grepped from PHP Manual.
|
||||||
$output['functions_windows'] = array(
|
$output['functions_windows'] = array(
|
||||||
|
|
|
@ -188,7 +188,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
|
||||||
|
|
||||||
public function getVersion() {
|
public function getVersion() {
|
||||||
// The version number should be incremented whenever a new rule is added.
|
// The version number should be incremented whenever a new rule is added.
|
||||||
return '5';
|
return '6';
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function resolveFuture($path, Future $future) {
|
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) {
|
public function lintPHP54Features(XHPASTNode $root) {
|
||||||
|
|
Loading…
Reference in a new issue