diff --git a/src/lint/linter/ArcanistXHPASTLinter.php b/src/lint/linter/ArcanistXHPASTLinter.php index 18257e51..2ff9805f 100644 --- a/src/lint/linter/ArcanistXHPASTLinter.php +++ b/src/lint/linter/ArcanistXHPASTLinter.php @@ -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.'), + ''); } } } diff --git a/src/lint/linter/__tests__/xhpast/self-member-references.lint-test b/src/lint/linter/__tests__/xhpast/self-member-references.lint-test index d60d857d..c4c1a9c6 100644 --- a/src/lint/linter/__tests__/xhpast/self-member-references.lint-test +++ b/src/lint/linter/__tests__/xhpast/self-member-references.lint-test @@ -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 ~~~~~~~~~~