1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 12:24:49 +01:00

Add new suppressable error for missing closure return types

This commit is contained in:
Matthew Brown 2017-01-16 01:22:36 -05:00
parent 5315fd15ad
commit 2e2f2f4ffb
4 changed files with 23 additions and 1 deletions

View File

@ -102,6 +102,7 @@
<xs:element name="InvalidToString" type="IssueHandlerType" minOccurs="0" />
<xs:element name="MethodSignatureMismatch" type="IssueHandlerType" minOccurs="0" />
<xs:element name="MisplacedRequiredParam" type="IssueHandlerType" minOccurs="0" />
<xs:element name="MissingClosureReturnType" type="IssueHandlerType" minOccurs="0" />
<xs:element name="MissingPropertyDeclaration" type="IssueHandlerType" minOccurs="0" />
<xs:element name="MissingPropertyType" type="IssueHandlerType" minOccurs="0" />
<xs:element name="MissingReturnType" type="IssueHandlerType" minOccurs="0" />

View File

@ -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',

View File

@ -0,0 +1,6 @@
<?php
namespace Psalm\Issue;
class MissingClosureReturnType extends CodeError
{
}

View File

@ -126,7 +126,7 @@ class ClosureTest extends PHPUnit_Framework_TestCase
$bam = array_map(
/**
* @psalm-suppress MissingReturnType
* @psalm-suppress MissingClosureReturnType
*/
function(string $a) {
return $a . "blah";