]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Fix PHP version check for function calls with static/variable functions
authorepriestley <git@epriestley.com>
Wed, 10 Sep 2014 21:01:34 +0000 (14:01 -0700)
committerepriestley <git@epriestley.com>
Wed, 10 Sep 2014 21:01:34 +0000 (14:01 -0700)
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
src/lint/linter/__tests__/xhpast/conditional-usage.lint-test

index 04df53c063d82cad04b65b377aeeaeb1ff88b0c3..1b65f6cf1d8708fbebfbdf8335c4a145e81afc3e 100644 (file)
@@ -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':
index 567d8dad7ed4cd47a9b04c606ec031482be6bdc1..32dc71d9a163df32eec84904de995e3abbd31830 100644 (file)
@@ -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