Skip to content

Commit

Permalink
Fix PHP 7 return type checks for functions without docblocks
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Dec 4, 2016
1 parent a1acbfe commit d951e1d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
24 changes: 12 additions & 12 deletions src/Psalm/Checker/FunctionChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Checker/FunctionLikeChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand Down

0 comments on commit d951e1d

Please sign in to comment.