Page MenuHomePhabricator

D14558.id35222.diff
No OneTemporary

D14558.id35222.diff

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

Mime Type
text/plain
Expires
Sun, Oct 20, 8:39 AM (3 w, 2 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6713235
Default Alt Text
D14558.id35222.diff (3 KB)

Event Timeline