Page MenuHomePhabricator

D13935.id33636.diff
No OneTemporary

D13935.id33636.diff

diff --git a/src/lint/linter/__tests__/xhpast/self-member-references.lint-test b/src/lint/linter/__tests__/xhpast/self-member-references.lint-test
--- a/src/lint/linter/__tests__/xhpast/self-member-references.lint-test
+++ b/src/lint/linter/__tests__/xhpast/self-member-references.lint-test
@@ -18,6 +18,10 @@
$x::bar();
}
+
+ public static function newInstance() {
+ return new Foo();
+ }
}
MyClass :: myMethod();
@@ -31,8 +35,9 @@
advice:12:14
advice:12:17
advice:17:10
-advice:23:8
-advice:23:11
+advice:23:16
+advice:27:8
+advice:27:11
~~~~~~~~~~
<?php
@@ -54,6 +59,10 @@
$x::bar();
}
+
+ public static function newInstance() {
+ return new self();
+ }
}
MyClass::myMethod();
diff --git a/src/lint/linter/xhpast/rules/ArcanistSelfMemberReferenceXHPASTLinterRule.php b/src/lint/linter/xhpast/rules/ArcanistSelfMemberReferenceXHPASTLinterRule.php
--- a/src/lint/linter/xhpast/rules/ArcanistSelfMemberReferenceXHPASTLinterRule.php
+++ b/src/lint/linter/xhpast/rules/ArcanistSelfMemberReferenceXHPASTLinterRule.php
@@ -72,9 +72,27 @@
strtolower($class_ref_name));
}
}
+
+ $instantiations = $class_declaration->selectDescendantsOfType('n_NEW');
+
+ foreach ($instantiations as $instantiation) {
+ $type = $instantiation->getChildByIndex(0);
+
+ if ($type->getTypeName() != 'n_CLASS_NAME') {
+ continue;
+ }
+
+ if (strtolower($type->getConcreteString()) == strtolower($class_name)) {
+ $this->raiseLintAtNode(
+ $type,
+ pht('Use `%s` to instantiate the current class.', 'self'),
+ 'self');
+ }
+ }
}
- $double_colons = $root->selectTokensOfType('T_PAAMAYIM_NEKUDOTAYIM');
+ $double_colons = $root
+ ->selectTokensOfType('T_PAAMAYIM_NEKUDOTAYIM');
foreach ($double_colons as $double_colon) {
$tokens = $double_colon->getNonsemanticTokensBefore() +

File Metadata

Mime Type
text/plain
Expires
Mon, Mar 24, 7:30 AM (1 w, 5 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7719824
Default Alt Text
D13935.id33636.diff (1 KB)

Event Timeline