mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Improve trait method mismatch failure rules
This commit is contained in:
parent
17857163fc
commit
257ebfd205
@ -594,6 +594,8 @@ class MethodAnalyzer extends FunctionLikeAnalyzer
|
||||
|
||||
if (!$is_contained_by) {
|
||||
if ($guide_classlike_storage->is_trait === $implementer_classlike_storage->is_trait
|
||||
|| !in_array($guide_classlike_storage->name, $implementer_classlike_storage->used_traits)
|
||||
|| $implementer_method_storage->defining_fqcln !== $implementer_classlike_storage->name
|
||||
|| (!$implementer_method_storage->abstract
|
||||
&& !$guide_method_storage->abstract)
|
||||
) {
|
||||
@ -912,6 +914,8 @@ class MethodAnalyzer extends FunctionLikeAnalyzer
|
||||
);
|
||||
if (!$is_contained_by) {
|
||||
if ($guide_classlike_storage->is_trait === $implementer_classlike_storage->is_trait
|
||||
|| !in_array($guide_classlike_storage->name, $implementer_classlike_storage->used_traits)
|
||||
|| $implementer_method_storage->defining_fqcln !== $implementer_classlike_storage->name
|
||||
|| (!$implementer_method_storage->abstract
|
||||
&& !$guide_method_storage->abstract)
|
||||
) {
|
||||
|
@ -885,7 +885,7 @@ class MethodSignatureTest extends TestCase
|
||||
class B extends A {
|
||||
use T;
|
||||
}',
|
||||
'error_message' => 'TraitMethodSignatureMismatch',
|
||||
'error_message' => 'MethodSignatureMismatch',
|
||||
],
|
||||
'abstractTraitMethodWithDifferentReturnType' => [
|
||||
'<?php
|
||||
@ -918,7 +918,7 @@ class MethodSignatureTest extends TestCase
|
||||
class B extends A {
|
||||
use T;
|
||||
}',
|
||||
'error_message' => 'TraitMethodSignatureMismatch',
|
||||
'error_message' => 'MethodSignatureMismatch',
|
||||
],
|
||||
'abstractTraitMethodWithDifferentParamType' => [
|
||||
'<?php
|
||||
@ -1168,6 +1168,36 @@ class MethodSignatureTest extends TestCase
|
||||
'error_message' => 'InvalidReturnType',
|
||||
2 => ['InvalidParent'],
|
||||
],
|
||||
'regularMethodMismatchFromParentUse' => [
|
||||
'<?php
|
||||
trait T2 {
|
||||
abstract public function test(int $x) : void;
|
||||
}
|
||||
|
||||
abstract class P2 {
|
||||
use T2;
|
||||
}
|
||||
|
||||
class C2 extends P2 {
|
||||
public function test(string $x) : void {}
|
||||
}',
|
||||
'error_message' => 'MethodSignatureMismatch',
|
||||
],
|
||||
'regularMethodMismatchFromChildUse' => [
|
||||
'<?php
|
||||
trait T3 {
|
||||
abstract public function test(int $x) : void;
|
||||
}
|
||||
|
||||
class P3 {
|
||||
public function test(string $x) : void {}
|
||||
}
|
||||
|
||||
class C3 extends P3 {
|
||||
use T3;
|
||||
}',
|
||||
'error_message' => 'MethodSignatureMismatch',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user