Page MenuHomePhabricator

D14564.id35228.diff
No OneTemporary

D14564.id35228.diff

diff --git a/src/lint/linter/xhpast/rules/ArcanistUnexpectedReturnValueXHPASTLinterRule.php b/src/lint/linter/xhpast/rules/ArcanistUnexpectedReturnValueXHPASTLinterRule.php
--- a/src/lint/linter/xhpast/rules/ArcanistUnexpectedReturnValueXHPASTLinterRule.php
+++ b/src/lint/linter/xhpast/rules/ArcanistUnexpectedReturnValueXHPASTLinterRule.php
@@ -33,6 +33,10 @@
continue;
}
+ if ($this->isInAnonymousFunction($return)) {
+ continue;
+ }
+
$this->raiseLintAtNode(
$return,
pht(
@@ -45,4 +49,15 @@
}
}
+ private function isInAnonymousFunction(XHPASTNode $node) {
+ while ($node) {
+ if ($node->getTypeName() == 'n_FUNCTION_DECLARATION' &&
+ $node->getChildByIndex(2)->getTypeName() == 'n_EMPTY') {
+ return true;
+ }
+
+ $node = $node->getParentNode();
+ }
+ }
+
}
diff --git a/src/lint/linter/xhpast/rules/__tests__/unexpected-return-value/closure.lint-test b/src/lint/linter/xhpast/rules/__tests__/unexpected-return-value/closure.lint-test
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/xhpast/rules/__tests__/unexpected-return-value/closure.lint-test
@@ -0,0 +1,11 @@
+<?php
+class SomeClass {
+ private $closure;
+
+ public function __construct() {
+ $this->closure = function() {
+ return null;
+ };
+ }
+}
+~~~~~~~~~~

File Metadata

Mime Type
text/plain
Expires
Fri, Mar 7, 10:33 AM (10 h, 52 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7332134
Default Alt Text
D14564.id35228.diff (1 KB)

Event Timeline