1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Use better metric for a properly mismatching type

This commit is contained in:
Brown 2019-05-14 16:15:31 -04:00
parent 91fbb976ab
commit e7f4a52d2b
2 changed files with 48 additions and 11 deletions

View File

@ -908,18 +908,42 @@ class MethodAnalyzer extends FunctionLikeAnalyzer
}
}
} else {
if (IssueBuffer::accepts(
new ImplementedParamTypeMismatch(
'Argument ' . ($i + 1) . ' of ' . $cased_implementer_method_id . ' has wrong type \'' .
$implementer_method_storage_param_type->getId() . '\', expecting \'' .
$guide_method_storage_param_type->getId() . '\' as defined by ' .
$cased_guide_method_id,
$implementer_method_storage->params[$i]->location
?: $code_location
),
$suppressed_issues
if (TypeAnalyzer::isContainedBy(
$codebase,
$implementer_method_storage_param_type,
$guide_method_storage_param_type,
!$guide_classlike_storage->user_defined,
!$guide_classlike_storage->user_defined
)) {
return false;
if (IssueBuffer::accepts(
new MoreSpecificImplementedParamType(
'Argument ' . ($i + 1) . ' of ' . $cased_implementer_method_id
. ' has the more specific type \'' .
$implementer_method_storage_param_type->getId() . '\', expecting \'' .
$guide_method_storage_param_type->getId() . '\' as defined by ' .
$cased_guide_method_id,
$implementer_method_storage->params[$i]->location
?: $code_location
),
$suppressed_issues
)) {
return false;
}
} else {
if (IssueBuffer::accepts(
new ImplementedParamTypeMismatch(
'Argument ' . ($i + 1) . ' of ' . $cased_implementer_method_id
. ' has wrong type \'' .
$implementer_method_storage_param_type->getId() . '\', expecting \'' .
$guide_method_storage_param_type->getId() . '\' as defined by ' .
$cased_guide_method_id,
$implementer_method_storage->params[$i]->location
?: $code_location
),
$suppressed_issues
)) {
return false;
}
}
}
}

View File

@ -943,6 +943,19 @@ class MethodSignatureTest extends TestCase
'error_message' => 'MethodSignatureMismatch',
['MoreSpecificImplementedParamType']
],
'preventOneOfUnionMoreSpecific' => [
'<?php
class A {
/** @param string|int $s */
public function foo($s) : void {}
}
class B extends A {
/** @param string $s */
public function foo($s) : void {}
}',
'error_message' => 'MoreSpecificImplementedParamType',
],
'preventImplementingSerializableWithType' => [
'<?php
class Foo implements \Serializable {