Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15311734
D14564.id35228.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D14564.id35228.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D14564: Improve the "unexpected return value" linter rule
Attached
Detach File
Event Timeline
Log In to Comment