Skip to content

Commit

Permalink
report deprecated properties accessed by self
Browse files Browse the repository at this point in the history
  • Loading branch information
Khartir authored and ondrejmirtes committed Mar 17, 2023
1 parent e3761ea commit a22b36b
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Rules/Deprecations/AccessDeprecatedStaticPropertyRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function processNode(Node $node, Scope $scope): array
$referencedClasses = [];

if ($node->class instanceof Name) {
$referencedClasses[] = (string) $node->class;
$referencedClasses[] = $scope->resolveName($node->class);
} else {
$classTypeResult = $this->ruleLevelHelper->findTypeToCheck(
$scope,
Expand Down Expand Up @@ -87,14 +87,14 @@ static function (Type $type) use ($propertyName): bool {
return [sprintf(
'Access to deprecated static property $%s of class %s.',
$propertyName,
$referencedClass
$property->getDeclaringClass()->getName()
)];
}

return [sprintf(
"Access to deprecated static property $%s of class %s:\n%s",
$propertyName,
$referencedClass,
$property->getDeclaringClass()->getName(),
$description
)];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ public function testAccessDeprecatedStaticProperty(): void
"Access to deprecated static property \$deprecatedWithDescription of class AccessDeprecatedStaticProperty\Foo:\nThis is probably a singleton.",
33,
],
[
'Access to deprecated static property $deprecatedFoo of class AccessDeprecatedStaticProperty\Foo.',
117,
],
[
'Access to deprecated static property $deprecatedOtherFoo of class AccessDeprecatedStaticProperty\Child.',
118,
],
[
'Access to deprecated static property $deprecatedFoo of class AccessDeprecatedStaticProperty\Foo.',
119,
],
[
'Access to deprecated static property $deprecatedOtherFoo of class AccessDeprecatedStaticProperty\Child.',
120,
],
]
);
}
Expand Down
16 changes: 16 additions & 0 deletions tests/Rules/Deprecations/CallToDeprecatedStaticMethodRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ public function testDeprecatedStaticMethodCall(): void
'Call to deprecated method deprecatedFoo() of class CheckDeprecatedStaticMethodCall\Foo.',
33,
],
[
'Call to deprecated method deprecatedFoo() of class CheckDeprecatedStaticMethodCall\Foo.',
74,
],
[
'Call to deprecated method deprecatedOtherFoo() of class CheckDeprecatedStaticMethodCall\Child.',
75,
],
[
'Call to deprecated method deprecatedFoo() of class CheckDeprecatedStaticMethodCall\Foo.',
76,
],
[
'Call to deprecated method deprecatedOtherFoo() of class CheckDeprecatedStaticMethodCall\Child.',
77,
],
]
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,19 @@ public function foo()
}

}

class Child extends Foo
{
/**
* @deprecated
*/
public static $deprecatedOtherFoo;

public static function foo()
{
self::$deprecatedFoo;
self::$deprecatedOtherFoo;
static::$deprecatedFoo;
static::$deprecatedOtherFoo;
}
}
19 changes: 19 additions & 0 deletions tests/Rules/Deprecations/data/call-to-deprecated-static-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,22 @@ public static function foo()
}

}

class Child extends Foo
{
/**
* @deprecated
*/
public static function deprecatedOtherFoo()
{

}

public static function foo()
{
self::deprecatedFoo();
self::deprecatedOtherFoo();
static::deprecatedFoo();
static::deprecatedOtherFoo();
}
}

0 comments on commit a22b36b

Please sign in to comment.