Skip to content
Permalink
Browse files

Use better metric for a properly mismatching type

  • Loading branch information...
muglug committed May 14, 2019
1 parent 91fbb97 commit e7f4a52d2b9f3f17f0e817a10d37e04da36e41e0
Showing with 48 additions and 11 deletions.
  1. +35 −11 src/Psalm/Internal/Analyzer/MethodAnalyzer.php
  2. +13 −0 tests/MethodSignatureTest.php
@@ -908,18 +908,42 @@ public static function compareMethods(
}
}
} 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;
}
}
}
}
@@ -943,6 +943,19 @@ public function f($f): void {}
'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 {

0 comments on commit e7f4a52

Please sign in to comment.
You can’t perform that action at this time.