]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Improve linter rule for useless overriding methods
authorJoshua Spence <josh@joshuaspence.com>
Thu, 14 May 2015 21:10:28 +0000 (07:10 +1000)
committerJoshua Spence <josh@joshuaspence.com>
Thu, 14 May 2015 21:10:28 +0000 (07:10 +1000)
Summary: Ref T7409. This linter rule was added in D12419, but fails in some specific cases. Improve the handling of `n_DECLARATION_PARAMETER_LIST`.

Test Plan: Added unit tests.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T7409

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

src/lint/linter/ArcanistXHPASTLinter.php
src/lint/linter/__tests__/xhpast/useless-overriding-method.lint-test

index 248e439992cfdb2447f396b6e504268a39756f95..380cbd8cf7fe9c6f1063ee7a35a1ee47ce44da22 100644 (file)
@@ -3788,9 +3788,13 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
       $parameters = array();
 
       foreach ($parameter_list->getChildren() as $parameter) {
-        $parameters[] = $parameter
-          ->getChildOfType(1, 'n_VARIABLE')
-          ->getConcreteString();
+        $parameter = $parameter->getChildByIndex(1);
+
+        if ($parameter->getTypeName() == 'n_VARIABLE_REFERENCE') {
+          $parameter = $parameter->getChildOfType(0, 'n_VARIABLE');
+        }
+
+        $parameters[] = $parameter->getConcreteString();
       }
 
       $statements = $method->getChildByIndex(5);
index a6e2780f1f7d346bf790b0b68fbb83010224d1d6..308bf76f18929702929e3f7b867232fd806acd6d 100644 (file)
@@ -12,8 +12,13 @@ final class MyClass extends SomeOtherClass {
   public function usefulMethod($x, array $y) {
     return parent::usefulMethod($x, null);
   }
+
+  public function anotherMethod($x, &$y) {
+    return parent::anotherMethod($x, $y);
+  }
 }
 ~~~~~~~~~~
 error:3:13
 advice:4:3
 advice:8:3
+advice:16:3