From e043d22afd26c4836e49428f4a33036143313ca3 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 10 Sep 2014 14:01:34 -0700 Subject: [PATCH] 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 --- src/lint/linter/ArcanistXHPASTLinter.php | 12 +++++++++--- .../__tests__/xhpast/conditional-usage.lint-test | 5 +++++ 2 files changed, 14 insertions(+), 3 deletions(-) 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