Skip to content

Commit a22b36b

Browse files
Khartirondrejmirtes
authored andcommittedMar 17, 2023
report deprecated properties accessed by self
1 parent e3761ea commit a22b36b

5 files changed

+70
-3
lines changed
 

‎src/Rules/Deprecations/AccessDeprecatedStaticPropertyRule.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function processNode(Node $node, Scope $scope): array
5353
$referencedClasses = [];
5454

5555
if ($node->class instanceof Name) {
56-
$referencedClasses[] = (string) $node->class;
56+
$referencedClasses[] = $scope->resolveName($node->class);
5757
} else {
5858
$classTypeResult = $this->ruleLevelHelper->findTypeToCheck(
5959
$scope,
@@ -87,14 +87,14 @@ static function (Type $type) use ($propertyName): bool {
8787
return [sprintf(
8888
'Access to deprecated static property $%s of class %s.',
8989
$propertyName,
90-
$referencedClass
90+
$property->getDeclaringClass()->getName()
9191
)];
9292
}
9393

9494
return [sprintf(
9595
"Access to deprecated static property $%s of class %s:\n%s",
9696
$propertyName,
97-
$referencedClass,
97+
$property->getDeclaringClass()->getName(),
9898
$description
9999
)];
100100
}

‎tests/Rules/Deprecations/AccessDeprecatedStaticPropertyRuleTest.php

+16
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,22 @@ public function testAccessDeprecatedStaticProperty(): void
5959
"Access to deprecated static property \$deprecatedWithDescription of class AccessDeprecatedStaticProperty\Foo:\nThis is probably a singleton.",
6060
33,
6161
],
62+
[
63+
'Access to deprecated static property $deprecatedFoo of class AccessDeprecatedStaticProperty\Foo.',
64+
117,
65+
],
66+
[
67+
'Access to deprecated static property $deprecatedOtherFoo of class AccessDeprecatedStaticProperty\Child.',
68+
118,
69+
],
70+
[
71+
'Access to deprecated static property $deprecatedFoo of class AccessDeprecatedStaticProperty\Foo.',
72+
119,
73+
],
74+
[
75+
'Access to deprecated static property $deprecatedOtherFoo of class AccessDeprecatedStaticProperty\Child.',
76+
120,
77+
],
6278
]
6379
);
6480
}

‎tests/Rules/Deprecations/CallToDeprecatedStaticMethodRuleTest.php

+16
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,22 @@ public function testDeprecatedStaticMethodCall(): void
6767
'Call to deprecated method deprecatedFoo() of class CheckDeprecatedStaticMethodCall\Foo.',
6868
33,
6969
],
70+
[
71+
'Call to deprecated method deprecatedFoo() of class CheckDeprecatedStaticMethodCall\Foo.',
72+
74,
73+
],
74+
[
75+
'Call to deprecated method deprecatedOtherFoo() of class CheckDeprecatedStaticMethodCall\Child.',
76+
75,
77+
],
78+
[
79+
'Call to deprecated method deprecatedFoo() of class CheckDeprecatedStaticMethodCall\Foo.',
80+
76,
81+
],
82+
[
83+
'Call to deprecated method deprecatedOtherFoo() of class CheckDeprecatedStaticMethodCall\Child.',
84+
77,
85+
],
7086
]
7187
);
7288
}

‎tests/Rules/Deprecations/data/access-deprecated-static-property.php

+16
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,19 @@ public function foo()
104104
}
105105

106106
}
107+
108+
class Child extends Foo
109+
{
110+
/**
111+
* @deprecated
112+
*/
113+
public static $deprecatedOtherFoo;
114+
115+
public static function foo()
116+
{
117+
self::$deprecatedFoo;
118+
self::$deprecatedOtherFoo;
119+
static::$deprecatedFoo;
120+
static::$deprecatedOtherFoo;
121+
}
122+
}

‎tests/Rules/Deprecations/data/call-to-deprecated-static-method.php

+19
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,22 @@ public static function foo()
5858
}
5959

6060
}
61+
62+
class Child extends Foo
63+
{
64+
/**
65+
* @deprecated
66+
*/
67+
public static function deprecatedOtherFoo()
68+
{
69+
70+
}
71+
72+
public static function foo()
73+
{
74+
self::deprecatedFoo();
75+
self::deprecatedOtherFoo();
76+
static::deprecatedFoo();
77+
static::deprecatedOtherFoo();
78+
}
79+
}

0 commit comments

Comments
 (0)
Failed to load comments.