Page MenuHomePhabricator

D14516.diff
No OneTemporary

D14516.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
@@ -333,6 +333,8 @@
'ArcanistUnaryPrefixExpressionSpacingXHPASTLinterRuleTestCase' => 'lint/linter/xhpast/rules/__tests__/ArcanistUnaryPrefixExpressionSpacingXHPASTLinterRuleTestCase.php',
'ArcanistUndeclaredVariableXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistUndeclaredVariableXHPASTLinterRule.php',
'ArcanistUndeclaredVariableXHPASTLinterRuleTestCase' => 'lint/linter/xhpast/rules/__tests__/ArcanistUndeclaredVariableXHPASTLinterRuleTestCase.php',
+ 'ArcanistUnexpectedReturnValueXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistUnexpectedReturnValueXHPASTLinterRule.php',
+ 'ArcanistUnexpectedReturnValueXHPASTLinterRuleTestCase' => 'lint/linter/xhpast/rules/__tests__/ArcanistUnexpectedReturnValueXHPASTLinterRuleTestCase.php',
'ArcanistUnitConsoleRenderer' => 'unit/renderer/ArcanistUnitConsoleRenderer.php',
'ArcanistUnitRenderer' => 'unit/renderer/ArcanistUnitRenderer.php',
'ArcanistUnitTestEngine' => 'unit/engine/ArcanistUnitTestEngine.php',
@@ -707,6 +709,8 @@
'ArcanistUnaryPrefixExpressionSpacingXHPASTLinterRuleTestCase' => 'ArcanistXHPASTLinterRuleTestCase',
'ArcanistUndeclaredVariableXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistUndeclaredVariableXHPASTLinterRuleTestCase' => 'ArcanistXHPASTLinterRuleTestCase',
+ 'ArcanistUnexpectedReturnValueXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
+ 'ArcanistUnexpectedReturnValueXHPASTLinterRuleTestCase' => 'ArcanistXHPASTLinterRuleTestCase',
'ArcanistUnitConsoleRenderer' => 'ArcanistUnitRenderer',
'ArcanistUnitRenderer' => 'Phobject',
'ArcanistUnitTestEngine' => 'Phobject',
diff --git a/src/lint/linter/xhpast/rules/ArcanistUnexpectedReturnValueXHPASTLinterRule.php b/src/lint/linter/xhpast/rules/ArcanistUnexpectedReturnValueXHPASTLinterRule.php
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/xhpast/rules/ArcanistUnexpectedReturnValueXHPASTLinterRule.php
@@ -0,0 +1,48 @@
+<?php
+
+final class ArcanistUnexpectedReturnValueXHPASTLinterRule
+ extends ArcanistXHPASTLinterRule {
+
+ const ID = 92;
+
+ public function getLintName() {
+ return pht('Unexpected `%s` Value', 'return');
+ }
+
+ public function getLintSeverity() {
+ return ArcanistLintSeverity::SEVERITY_WARNING;
+ }
+
+ public function process(XHPASTNode $root) {
+ $methods = $root->selectDescendantsOfType('n_METHOD_DECLARATION');
+
+ foreach ($methods as $method) {
+ $method_name = $method
+ ->getChildOfType(2, 'n_STRING')
+ ->getConcreteString();
+
+ switch (strtolower($method_name)) {
+ case '__construct':
+ case '__destruct':
+ $returns = $method->selectDescendantsOfType('n_RETURN');
+
+ foreach ($returns as $return) {
+ $return_value = $return->getChildByIndex(0);
+
+ if ($return_value->getTypeName() == 'n_EMPTY') {
+ continue;
+ }
+
+ $this->raiseLintAtNode(
+ $return,
+ pht(
+ 'Unexpected `%s` value in `%s` method.',
+ 'return',
+ $method_name));
+ }
+ break;
+ }
+ }
+ }
+
+}
diff --git a/src/lint/linter/xhpast/rules/__tests__/ArcanistUnexpectedReturnValueXHPASTLinterRuleTestCase.php b/src/lint/linter/xhpast/rules/__tests__/ArcanistUnexpectedReturnValueXHPASTLinterRuleTestCase.php
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/xhpast/rules/__tests__/ArcanistUnexpectedReturnValueXHPASTLinterRuleTestCase.php
@@ -0,0 +1,11 @@
+<?php
+
+final class ArcanistUnexpectedReturnValueXHPASTLinterRuleTestCase
+ extends ArcanistXHPASTLinterRuleTestCase {
+
+ public function testLinter() {
+ $this->executeTestsInDirectory(
+ dirname(__FILE__).'/unexpected-return-value/');
+ }
+
+}
diff --git a/src/lint/linter/xhpast/rules/__tests__/unexpected-return-value/construct.lint-test b/src/lint/linter/xhpast/rules/__tests__/unexpected-return-value/construct.lint-test
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/xhpast/rules/__tests__/unexpected-return-value/construct.lint-test
@@ -0,0 +1,8 @@
+<?php
+class SomeClass {
+ public function __construct() {
+ return null;
+ }
+}
+~~~~~~~~~~
+warning:4:5
diff --git a/src/lint/linter/xhpast/rules/__tests__/unexpected-return-value/destruct.lint-test b/src/lint/linter/xhpast/rules/__tests__/unexpected-return-value/destruct.lint-test
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/xhpast/rules/__tests__/unexpected-return-value/destruct.lint-test
@@ -0,0 +1,8 @@
+<?php
+class SomeClass {
+ public function __destruct() {
+ return null;
+ }
+}
+~~~~~~~~~~
+warning:4:5
diff --git a/src/lint/linter/xhpast/rules/__tests__/unexpected-return-value/empty-return.lint-test b/src/lint/linter/xhpast/rules/__tests__/unexpected-return-value/empty-return.lint-test
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/xhpast/rules/__tests__/unexpected-return-value/empty-return.lint-test
@@ -0,0 +1,7 @@
+<?php
+class SomeClass {
+ public function __construct() {
+ return;
+ }
+}
+~~~~~~~~~~

File Metadata

Mime Type
text/plain
Expires
Tue, Dec 24, 7:10 PM (17 h, 30 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6923915
Default Alt Text
D14516.diff (5 KB)

Event Timeline