From 2e2f2f4ffbfa6703174a5c153ba8841949471174 Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Mon, 16 Jan 2017 01:22:36 -0500 Subject: [PATCH] Add new suppressable error for missing closure return types --- config.xsd | 1 + src/Psalm/Checker/FunctionLikeChecker.php | 15 +++++++++++++++ src/Psalm/Issue/MissingClosureReturnType.php | 6 ++++++ tests/ClosureTest.php | 2 +- 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/Psalm/Issue/MissingClosureReturnType.php diff --git a/config.xsd b/config.xsd index 6e2dce3b8..8a77b1224 100644 --- a/config.xsd +++ b/config.xsd @@ -102,6 +102,7 @@ + diff --git a/src/Psalm/Checker/FunctionLikeChecker.php b/src/Psalm/Checker/FunctionLikeChecker.php index 4b367903b..173453886 100644 --- a/src/Psalm/Checker/FunctionLikeChecker.php +++ b/src/Psalm/Checker/FunctionLikeChecker.php @@ -20,6 +20,7 @@ use Psalm\Issue\InvalidReturnType; use Psalm\Issue\InvalidToString; use Psalm\Issue\MethodSignatureMismatch; use Psalm\Issue\MisplacedRequiredParam; +use Psalm\Issue\MissingClosureReturnType; use Psalm\Issue\MissingReturnType; use Psalm\Issue\MixedInferredReturnType; use Psalm\Issue\OverriddenMethodAccess; @@ -785,6 +786,20 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo } if (!$return_type && !$update_docblock && !$is_to_string) { + if ($this->function instanceof Closure) { + if (IssueBuffer::accepts( + new MissingClosureReturnType( + 'Closure does not have a return type', + new CodeLocation($this, $this->function, true) + ), + $this->suppressed_issues + )) { + // fall through + } + + return null; + } + if (IssueBuffer::accepts( new MissingReturnType( 'Method ' . $cased_method_id . ' does not have a return type', diff --git a/src/Psalm/Issue/MissingClosureReturnType.php b/src/Psalm/Issue/MissingClosureReturnType.php new file mode 100644 index 000000000..019a059bf --- /dev/null +++ b/src/Psalm/Issue/MissingClosureReturnType.php @@ -0,0 +1,6 @@ +