Page MenuHomePhabricator

D11267.diff
No OneTemporary

D11267.diff

diff --git a/src/lint/linter/ArcanistXHPASTLinter.php b/src/lint/linter/ArcanistXHPASTLinter.php
--- a/src/lint/linter/ArcanistXHPASTLinter.php
+++ b/src/lint/linter/ArcanistXHPASTLinter.php
@@ -3004,20 +3004,36 @@
}
private function lintMethodModifier(XHPASTNode $root) {
+ static $visibilities = array(
+ 'public',
+ 'protected',
+ 'private',
+ );
+
$methods = $root->selectDescendantsOfType('n_METHOD_DECLARATION');
foreach ($methods as $method) {
- $modifier_list = $method->getChildOfType(
+ $modifiers_list = $method->getChildOfType(
0,
'n_METHOD_MODIFIER_LIST');
- if (!$modifier_list->getChildren()) {
- $this->raiseLintAtNode(
- $method,
- self::LINT_IMPLICIT_VISIBILITY,
- pht('Methods should have their visibility declared explicitly.'),
- 'public '.$method->getConcreteString());
+ foreach ($modifiers_list->getChildren() as $modifier) {
+ if (in_array($modifier->getConcreteString(), $visibilities)) {
+ continue 2;
+ }
}
+
+ if ($modifiers_list->getChildren()) {
+ $node = $modifiers_list;
+ } else {
+ $node = $method;
+ }
+
+ $this->raiseLintAtNode(
+ $node,
+ self::LINT_IMPLICIT_VISIBILITY,
+ pht('Methods should have their visibility declared explicitly.'),
+ 'public '.$node->getConcreteString());
}
}
diff --git a/src/lint/linter/__tests__/xhpast/implicit-visibility.lint-test b/src/lint/linter/__tests__/xhpast/implicit-visibility.lint-test
--- a/src/lint/linter/__tests__/xhpast/implicit-visibility.lint-test
+++ b/src/lint/linter/__tests__/xhpast/implicit-visibility.lint-test
@@ -2,6 +2,8 @@
final class Foo {
public function bar() {}
function baz() {}
+ abstract function a();
+ private static function b() {}
var $x;
static $y;
@@ -10,13 +12,16 @@
~~~~~~~~~~
error:2:13 XHP19
advice:4:3
-advice:6:3
-advice:7:3
+advice:5:3
+advice:8:3
+advice:9:3
~~~~~~~~~~
<?php
final class Foo {
public function bar() {}
public function baz() {}
+ public abstract function a();
+ private static function b() {}
public $x;
public static $y;

File Metadata

Mime Type
text/plain
Expires
Mar 6 2025, 1:06 PM (4 w, 3 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7256497
Default Alt Text
D11267.diff (2 KB)

Event Timeline