]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Improvements to "self member reference" linter rule
authorJoshua Spence <josh@joshuaspence.com>
Mon, 13 Apr 2015 20:27:17 +0000 (06:27 +1000)
committerJoshua Spence <josh@joshuaspence.com>
Mon, 13 Apr 2015 20:27:17 +0000 (06:27 +1000)
Summary: Ref T7409. A few fixes and improvements to `ArcanistXHPASTLinter::LINT_SELF_MEMBER_REFERENCE`.

Test Plan: Added test cases.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T7409

Differential Revision: https://secure.phabricator.com/D12385

src/lint/linter/ArcanistXHPASTLinter.php
src/lint/linter/__tests__/xhpast/self-member-references.lint-test

index 18257e517822da1d7906a961dd113f20be8a8fa7..2ff9805fb95c2045ee4e1a11d299165c8feecfd7 100644 (file)
@@ -3407,14 +3407,16 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
 
       $class_static_accesses = $class_declaration
         ->selectDescendantsOfType('n_CLASS_STATIC_ACCESS');
-      $self_member_references = array();
 
       foreach ($class_static_accesses as $class_static_access) {
-        $double_colons     = $class_static_access
+        $double_colons = $class_static_access
           ->selectTokensOfType('T_PAAMAYIM_NEKUDOTAYIM');
-        $class_ref         = $class_static_access
-          ->getChildOfType(0, 'n_CLASS_NAME');
-        $class_ref_name    = $class_ref->getConcreteString();
+        $class_ref = $class_static_access->getChildByIndex(0);
+
+        if ($class_ref->getTypeName() != 'n_CLASS_NAME') {
+          continue;
+        }
+        $class_ref_name = $class_ref->getConcreteString();
 
         if (strtolower($class_name) == strtolower($class_ref_name)) {
           $this->raiseLintAtNode(
@@ -3441,20 +3443,23 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
             pht('PHP keywords should be lowercase.'),
             strtolower($class_ref_name));
         }
+      }
+    }
 
-        foreach ($double_colons as $double_colon) {
-          $tokens = $double_colon->getNonsemanticTokensBefore() +
-            $double_colon->getNonsemanticTokensAfter();
+    $double_colons = $root
+      ->selectTokensOfType('T_PAAMAYIM_NEKUDOTAYIM');
 
-          foreach ($tokens as $token) {
-            if ($token->isAnyWhitespace()) {
-              $this->raiseLintAtToken(
-                $token,
-                self::LINT_SELF_MEMBER_REFERENCE,
-                pht('Unnecessary whitespace around double colon operator.'),
-                '');
-            }
-          }
+    foreach ($double_colons as $double_colon) {
+      $tokens = $double_colon->getNonsemanticTokensBefore() +
+        $double_colon->getNonsemanticTokensAfter();
+
+      foreach ($tokens as $token) {
+        if ($token->isAnyWhitespace()) {
+          $this->raiseLintAtToken(
+            $token,
+            self::LINT_SELF_MEMBER_REFERENCE,
+            pht('Unnecessary whitespace around double colon operator.'),
+            '');
         }
       }
     }
index d60d857dee5dd146b5b95c16c25dc404499d486d..c4c1a9c64d84824808506256175141ae02963356 100644 (file)
@@ -12,11 +12,15 @@ class Foo extends Bar {
     echo Self :: FOOBAR;
   }
 
-  public function baz() {
+  public function baz(Foo $x) {
     echo static::FOOBAR;
     echo Foo::FOOBAR;
+
+    $x::bar();
   }
 }
+
+MyClass :: myMethod();
 ~~~~~~~~~~
 error:3:7
 advice:7:5
@@ -24,6 +28,8 @@ advice:12:10
 advice:12:14
 advice:12:17
 advice:17:10
+advice:23:8
+advice:23:11
 ~~~~~~~~~~
 <?php
 
@@ -39,8 +45,12 @@ class Foo extends Bar {
     echo self::FOOBAR;
   }
 
-  public function baz() {
+  public function baz(Foo $x) {
     echo static::FOOBAR;
     echo self::FOOBAR;
+
+    $x::bar();
   }
 }
+
+MyClass::myMethod();