Skip to content

Commit 99cadb0

Browse files
committed
handle deprected methods in traits
1 parent 66ce943 commit 99cadb0

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

src/Rules/Deprecations/OverrideDeprecatedMethodRule.php

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ public function processNode(Node $node, Scope $scope): array
5959
continue;
6060
}
6161

62+
if ($ancestor->isTrait()) {
63+
continue;
64+
}
65+
6266
if (!$ancestor->hasMethod($methodName)) {
6367
continue;
6468
}

tests/Rules/Deprecations/OverrideDeprecatedMethodRuleTest.php

+10-3
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@ public function testDeprecatedMethodOverride(): void
2323
[
2424
[
2525
'Class OverrideDeprecatedMethod\Child overrides deprecated method deprecatedMethod of class OverrideDeprecatedMethod\Ancestor.',
26-
36,
26+
49,
2727
],
28-
2928
[
3029
'Class OverrideDeprecatedMethod\Child overrides deprecated method deprecatedInInterface of interface OverrideDeprecatedMethod\Deprecated.',
31-
48,
30+
61,
31+
],
32+
[
33+
'Class OverrideDeprecatedMethod\Child overrides deprecated method deprecatedInTrait of class OverrideDeprecatedMethod\Ancestor.',
34+
64,
35+
],
36+
[
37+
'Class OverrideDeprecatedMethod\GrandChild overrides deprecated method deprecatedInChild of class OverrideDeprecatedMethod\Child.',
38+
73,
3239
],
3340
]
3441
);

tests/Rules/Deprecations/data/override-deprecated-method.php

+19
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,18 @@
22

33
namespace OverrideDeprecatedMethod;
44

5+
trait DeprecationTrait
6+
{
7+
/**
8+
* @deprecated
9+
*/
10+
public function deprecatedInTrait(): void
11+
{}
12+
}
13+
514
class Ancestor
615
{
16+
use DeprecationTrait;
717
/**
818
* @deprecated
919
*/
@@ -33,6 +43,9 @@ public function deprecatedInInterface(): void;
3343

3444
class Child extends Ancestor implements Deprecated
3545
{
46+
use DeprecationTrait {
47+
deprecatedInTrait as deprecatedInChild;
48+
}
3649
public function deprecatedMethod(): void
3750
{}
3851

@@ -47,10 +60,16 @@ public function explicitlyNotDeprecatedMethod(): void
4760

4861
public function deprecatedInInterface(): void
4962
{}
63+
64+
public function deprecatedInTrait(): void
65+
{}
5066
}
5167

5268
class GrandChild extends Child
5369
{
5470
public function explicitlyNotDeprecatedMethod(): void
5571
{}
72+
73+
public function deprecatedInChild(): void
74+
{}
5675
}

0 commit comments

Comments
 (0)