From d951e1db22ac39d11e6853385b85a9db1c728fbb Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Sat, 3 Dec 2016 23:07:37 -0500 Subject: [PATCH] Fix PHP 7 return type checks for functions without docblocks --- src/Psalm/Checker/FunctionChecker.php | 24 +++++++++++------------ src/Psalm/Checker/FunctionLikeChecker.php | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Psalm/Checker/FunctionChecker.php b/src/Psalm/Checker/FunctionChecker.php index d8b8a71ceb4..5e04a00f880 100644 --- a/src/Psalm/Checker/FunctionChecker.php +++ b/src/Psalm/Checker/FunctionChecker.php @@ -209,6 +209,18 @@ protected function registerFunction(PhpParser\Node\Stmt\Function_ $function, $fi $this->suppressed_issues = []; + if ($function->returnType) { + $return_type = Type::parseString( + is_string($function->returnType) + ? $function->returnType + : ClassLikeChecker::getFQCLNFromNameObject( + $function->returnType, + $this->namespace, + $this->getAliasedClasses() + ) + ); + } + $doc_comment = $function->getDocComment(); if ($doc_comment) { @@ -239,18 +251,6 @@ protected function registerFunction(PhpParser\Node\Stmt\Function_ $function, $fi $this->suppressed_issues = $docblock_info->suppress; - if ($function->returnType) { - $return_type = Type::parseString( - is_string($function->returnType) - ? $function->returnType - : ClassLikeChecker::getFQCLNFromNameObject( - $function->returnType, - $this->namespace, - $this->getAliasedClasses() - ) - ); - } - if ($config->use_docblock_types) { if ($docblock_info->return_type) { $return_type = diff --git a/src/Psalm/Checker/FunctionLikeChecker.php b/src/Psalm/Checker/FunctionLikeChecker.php index 1fbab9cf389..6286bc45efa 100644 --- a/src/Psalm/Checker/FunctionLikeChecker.php +++ b/src/Psalm/Checker/FunctionLikeChecker.php @@ -494,7 +494,7 @@ public function checkReturnTypes($update_docblock = false) if (IssueBuffer::accepts( new InvalidReturnType( - 'No return type was found for method ' . $cased_method_id . + 'No return statements were found for method ' . $cased_method_id . ' but return type \'' . $declared_return_type . '\' was expected', new CodeLocation($this, $this->function, true) )