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:
parent
f43b74c605
commit
6c759ae343
2 changed files with 9 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue