1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-21 22:32:41 +01:00

Improve useless overriding method linter rule

Summary:
Improve `ArcanistUselessOverridingMethodXHPASTLinterRule` by allowing overriding methods which set default values. For example, the following scenario is perfectly valid:

```lang=php

class SomeClass {
  public function __construct($x) {}
}

class SomeOtherClass extends Class {
  public function __construct($x = null) {
    parent::__construct($x);
  }
}
```

Test Plan: Added test case.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin

Differential Revision: https://secure.phabricator.com/D13840
This commit is contained in:
Joshua Spence 2015-08-11 06:49:20 +10:00
parent f43b74c605
commit 6c759ae343
2 changed files with 9 additions and 0 deletions

View file

@ -16,6 +16,10 @@ final class MyClass extends SomeOtherClass {
public function anotherMethod($x, &$y) {
return parent::anotherMethod($x, $y);
}
public function usefulMethodWithDefaultValue($x = null) {
return parent::usefulMethodWithDefaultValue($x);
}
}
~~~~~~~~~~
error:3:13

View file

@ -26,12 +26,17 @@ final class ArcanistUselessOverridingMethodXHPASTLinterRule
$parameters = array();
foreach ($parameter_list->getChildren() as $parameter) {
$default = $parameter->getChildByIndex(2);
$parameter = $parameter->getChildByIndex(1);
if ($parameter->getTypeName() == 'n_VARIABLE_REFERENCE') {
$parameter = $parameter->getChildOfType(0, 'n_VARIABLE');
}
if ($default->getTypeName() != 'n_EMPTY') {
continue 2;
}
$parameters[] = $parameter->getConcreteString();
}