1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Add separate issues for implemented return type mismatch

This commit is contained in:
Matthew Brown 2017-11-30 00:01:41 -05:00
parent 0ea6540018
commit 52f9225356
5 changed files with 19 additions and 3 deletions

View File

@ -95,6 +95,7 @@
<xs:element name="DuplicateClass" type="IssueHandlerType" minOccurs="0" /> <xs:element name="DuplicateClass" type="IssueHandlerType" minOccurs="0" />
<xs:element name="EmptyArrayAccess" type="IssueHandlerType" minOccurs="0" /> <xs:element name="EmptyArrayAccess" type="IssueHandlerType" minOccurs="0" />
<xs:element name="ForbiddenCode" type="IssueHandlerType" minOccurs="0" /> <xs:element name="ForbiddenCode" type="IssueHandlerType" minOccurs="0" />
<xs:element name="ImplementedReturnTypeMismatch" type="IssueHandlerType" minOccurs="0" />
<xs:element name="ImplicitToStringCast" type="IssueHandlerType" minOccurs="0" /> <xs:element name="ImplicitToStringCast" type="IssueHandlerType" minOccurs="0" />
<xs:element name="InaccessibleClassConstant" type="IssueHandlerType" minOccurs="0" /> <xs:element name="InaccessibleClassConstant" type="IssueHandlerType" minOccurs="0" />
<xs:element name="InaccessibleMethod" type="IssueHandlerType" minOccurs="0" /> <xs:element name="InaccessibleMethod" type="IssueHandlerType" minOccurs="0" />
@ -144,6 +145,7 @@
<xs:element name="MixedStringOffsetAssignment" type="IssueHandlerType" minOccurs="0" /> <xs:element name="MixedStringOffsetAssignment" type="IssueHandlerType" minOccurs="0" />
<xs:element name="MixedTypeCoercion" type="IssueHandlerType" minOccurs="0" /> <xs:element name="MixedTypeCoercion" type="IssueHandlerType" minOccurs="0" />
<xs:element name="MoreSpecificReturnType" type="IssueHandlerType" minOccurs="0" /> <xs:element name="MoreSpecificReturnType" type="IssueHandlerType" minOccurs="0" />
<xs:element name="MoreSpecificImplementedReturnType" type="IssueHandlerType" minOccurs="0" />
<xs:element name="NoInterfaceProperties" type="IssueHandlerType" minOccurs="0" /> <xs:element name="NoInterfaceProperties" type="IssueHandlerType" minOccurs="0" />
<xs:element name="NonStaticSelfCall" type="IssueHandlerType" minOccurs="0" /> <xs:element name="NonStaticSelfCall" type="IssueHandlerType" minOccurs="0" />
<xs:element name="NullArgument" type="IssueHandlerType" minOccurs="0" /> <xs:element name="NullArgument" type="IssueHandlerType" minOccurs="0" />

View File

@ -13,6 +13,7 @@ use Psalm\Context;
use Psalm\EffectsAnalyser; use Psalm\EffectsAnalyser;
use Psalm\FileManipulation\FunctionDocblockManipulator; use Psalm\FileManipulation\FunctionDocblockManipulator;
use Psalm\FunctionLikeParameter; use Psalm\FunctionLikeParameter;
use Psalm\Issue\ImplementedReturnTypeMismatch;
use Psalm\Issue\InvalidDocblock; use Psalm\Issue\InvalidDocblock;
use Psalm\Issue\InvalidParamDefault; use Psalm\Issue\InvalidParamDefault;
use Psalm\Issue\InvalidReturnType; use Psalm\Issue\InvalidReturnType;
@ -22,6 +23,7 @@ use Psalm\Issue\MethodSignatureMismatch;
use Psalm\Issue\MissingClosureReturnType; use Psalm\Issue\MissingClosureReturnType;
use Psalm\Issue\MissingReturnType; use Psalm\Issue\MissingReturnType;
use Psalm\Issue\MixedInferredReturnType; use Psalm\Issue\MixedInferredReturnType;
use Psalm\Issue\MoreSpecificImplementedReturnType;
use Psalm\Issue\MoreSpecificReturnType; use Psalm\Issue\MoreSpecificReturnType;
use Psalm\Issue\OverriddenMethodAccess; use Psalm\Issue\OverriddenMethodAccess;
use Psalm\Issue\PossiblyUnusedVariable; use Psalm\Issue\PossiblyUnusedVariable;
@ -643,7 +645,7 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo
// is the declared return type more specific than the inferred one? // is the declared return type more specific than the inferred one?
if ($type_coerced) { if ($type_coerced) {
if (IssueBuffer::accepts( if (IssueBuffer::accepts(
new MoreSpecificReturnType( new MoreSpecificImplementedReturnType(
'The return type \'' . $guide_method_storage->return_type 'The return type \'' . $guide_method_storage->return_type
. '\' for ' . $cased_guide_method_id . ' is more specific than the implemented ' . '\' for ' . $cased_guide_method_id . ' is more specific than the implemented '
. 'return type for ' . $implementer_declaring_method_id . ' \'' . 'return type for ' . $implementer_declaring_method_id . ' \''
@ -656,7 +658,7 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo
} }
} else { } else {
if (IssueBuffer::accepts( if (IssueBuffer::accepts(
new InvalidReturnType( new ImplementedReturnTypeMismatch(
'The return type \'' . $guide_method_storage->return_type 'The return type \'' . $guide_method_storage->return_type
. '\' for ' . $cased_guide_method_id . ' is different to the implemented ' . '\' for ' . $cased_guide_method_id . ' is different to the implemented '
. 'return type for ' . $implementer_declaring_method_id . ' \'' . 'return type for ' . $implementer_declaring_method_id . ' \''

View File

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

View File

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

View File

@ -416,7 +416,7 @@ class InterfaceTest extends TestCase
return "hello"; return "hello";
} }
}', }',
'error_message' => 'InvalidReturnType', 'error_message' => 'ImplementedReturnTypeMismatch',
], ],
'abstractInterfaceImplementsButCallUndefinedMethod' => [ 'abstractInterfaceImplementsButCallUndefinedMethod' => [
'<?php '<?php