Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F13980265
D14558.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D14558.id.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -9,6 +9,8 @@
phutil_register_library_map(array(
'__library_version__' => 2,
'class' => array(
+ 'ArcanistAbstractPrivateMethodXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistAbstractPrivateMethodXHPASTLinterRule.php',
+ 'ArcanistAbstractPrivateMethodXHPASTLinterRuleTestCase' => 'lint/linter/xhpast/rules/__tests__/ArcanistAbstractPrivateMethodXHPASTLinterRuleTestCase.php',
'ArcanistAliasFunctionXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistAliasFunctionXHPASTLinterRule.php',
'ArcanistAliasFunctionXHPASTLinterRuleTestCase' => 'lint/linter/xhpast/rules/__tests__/ArcanistAliasFunctionXHPASTLinterRuleTestCase.php',
'ArcanistAliasWorkflow' => 'workflow/ArcanistAliasWorkflow.php',
@@ -391,6 +393,8 @@
),
'function' => array(),
'xmap' => array(
+ 'ArcanistAbstractPrivateMethodXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
+ 'ArcanistAbstractPrivateMethodXHPASTLinterRuleTestCase' => 'ArcanistXHPASTLinterRuleTestCase',
'ArcanistAliasFunctionXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistAliasFunctionXHPASTLinterRuleTestCase' => 'ArcanistXHPASTLinterRuleTestCase',
'ArcanistAliasWorkflow' => 'ArcanistWorkflow',
diff --git a/src/lint/linter/xhpast/rules/ArcanistAbstractPrivateMethodXHPASTLinterRule.php b/src/lint/linter/xhpast/rules/ArcanistAbstractPrivateMethodXHPASTLinterRule.php
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/xhpast/rules/ArcanistAbstractPrivateMethodXHPASTLinterRule.php
@@ -0,0 +1,37 @@
+<?php
+
+final class ArcanistAbstractPrivateMethodXHPASTLinterRule
+ extends ArcanistXHPASTLinterRule {
+
+ const ID = 107;
+
+ public function getLintName() {
+ return pht('`%s` Method Cannot Be Declared `%s`', 'abstract', 'private');
+ }
+
+ public function process(XHPASTNode $root) {
+ $methods = $root->selectDescendantsOfType('n_METHOD_DECLARATION');
+
+ foreach ($methods as $method) {
+ $method_modifiers = $method
+ ->getChildOfType(0, 'n_METHOD_MODIFIER_LIST')
+ ->selectDescendantsOfType('n_STRING');
+ $modifiers = array();
+
+ foreach ($method_modifiers as $modifier) {
+ $modifiers[strtolower($modifier->getConcreteString())] = true;
+ }
+
+ if (idx($modifiers, 'abstract') && idx($modifiers, 'private')) {
+ $this->raiseLintAtNode(
+ $method,
+ pht(
+ '`%s` method cannot be declared `%s`. '.
+ 'This construct will cause a fatal error.',
+ 'abstract',
+ 'private'));
+ }
+ }
+ }
+
+}
diff --git a/src/lint/linter/xhpast/rules/__tests__/ArcanistAbstractPrivateMethodXHPASTLinterRuleTestCase.php b/src/lint/linter/xhpast/rules/__tests__/ArcanistAbstractPrivateMethodXHPASTLinterRuleTestCase.php
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/xhpast/rules/__tests__/ArcanistAbstractPrivateMethodXHPASTLinterRuleTestCase.php
@@ -0,0 +1,11 @@
+<?php
+
+final class ArcanistAbstractPrivateMethodXHPASTLinterRuleTestCase
+ extends ArcanistXHPASTLinterRuleTestCase {
+
+ public function testLinter() {
+ $this->executeTestsInDirectory(
+ dirname(__FILE__).'/abstract-private-method/');
+ }
+
+}
diff --git a/src/lint/linter/xhpast/rules/__tests__/abstract-private-method/abstract-private-method.lint-test b/src/lint/linter/xhpast/rules/__tests__/abstract-private-method/abstract-private-method.lint-test
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/xhpast/rules/__tests__/abstract-private-method/abstract-private-method.lint-test
@@ -0,0 +1,6 @@
+<?php
+abstract class SomeClass {
+ private abstract function someMethod();
+}
+~~~~~~~~~~
+error:3:3
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Oct 20, 9:26 AM (3 w, 2 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6713235
Default Alt Text
D14558.id.diff (3 KB)
Attached To
Mode
D14558: Add a linter rule for `abstract private` methods
Attached
Detach File
Event Timeline
Log In to Comment