From: epriestley Date: Wed, 10 Sep 2014 21:01:34 +0000 (-0700) Subject: Fix PHP version check for function calls with static/variable functions X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=e043d22afd26c4836e49428f4a33036143313ca3;p=arcanist.git Fix PHP version check for function calls with static/variable functions Summary: D10132 improved this check by eliminating some false postives, but assumes an `n_FUNCTION_CALL` always starts with `n_SYMBOL_NAME`. This is true for `f()`, but not true for `C::m()` or `$v()`. Test Plan: Added and ran unit tests. Reviewers: btrahan, joshuaspence Reviewed By: joshuaspence Subscribers: epriestley Differential Revision: https://secure.phabricator.com/D10467 --- diff --git a/src/lint/linter/ArcanistXHPASTLinter.php b/src/lint/linter/ArcanistXHPASTLinter.php index 04df53c0..1b65f6cf 100644 --- a/src/lint/linter/ArcanistXHPASTLinter.php +++ b/src/lint/linter/ArcanistXHPASTLinter.php @@ -384,9 +384,15 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter { continue; } - $function_name = $function - ->getChildOfType(0, 'n_SYMBOL_NAME') - ->getConcreteString(); + $function_token = $function + ->getChildByIndex(0); + + if ($function_token->getTypeName() != 'n_SYMBOL_NAME') { + // This may be `Class::method(...)` or `$var(...)`. + continue; + } + + $function_name = $function_token->getConcreteString(); switch ($function_name) { case 'class_exists': diff --git a/src/lint/linter/__tests__/xhpast/conditional-usage.lint-test b/src/lint/linter/__tests__/xhpast/conditional-usage.lint-test index 567d8dad..32dc71d9 100644 --- a/src/lint/linter/__tests__/xhpast/conditional-usage.lint-test +++ b/src/lint/linter/__tests__/xhpast/conditional-usage.lint-test @@ -11,6 +11,11 @@ if (class_exists('CURLFile')) { new CURLFile(''); new DateTimeImmutable(); } + +// These shouldn't fatal. +if (SomeClass::someStaticMethod($param)) {} +$var = 'some_func'; +if ($var()) {} ~~~~~~~~~~ error:5:3 error:7:3