1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +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 { } else {
if (IssueBuffer::accepts( if (TypeAnalyzer::isContainedBy(
new ImplementedParamTypeMismatch( $codebase,
'Argument ' . ($i + 1) . ' of ' . $cased_implementer_method_id . ' has wrong type \'' . $implementer_method_storage_param_type,
$implementer_method_storage_param_type->getId() . '\', expecting \'' . $guide_method_storage_param_type,
$guide_method_storage_param_type->getId() . '\' as defined by ' . !$guide_classlike_storage->user_defined,
$cased_guide_method_id, !$guide_classlike_storage->user_defined
$implementer_method_storage->params[$i]->location
?: $code_location
),
$suppressed_issues
)) { )) {
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', 'error_message' => 'MethodSignatureMismatch',
['MoreSpecificImplementedParamType'] ['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' => [ 'preventImplementingSerializableWithType' => [
'<?php '<?php
class Foo implements \Serializable { class Foo implements \Serializable {