Skip to content

Commit 27397cd

Browse files
committed
DeprecatedScopeResolver - documentation in README
1 parent 9f4d1fd commit 27397cd

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

README.md

+45
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,48 @@ In case you don't own the code which you want to be considered deprecated, use [
3636
/** @deprecated */
3737
class ThirdPartyClass {}
3838
```
39+
40+
41+
## Custom deprecated scopes
42+
43+
Usage of deprecated code is not reported in code that is also deprecated:
44+
45+
```php
46+
/** @deprecated */
47+
function doFoo(): void
48+
{
49+
// not reported:
50+
anotherDeprecatedFunction();
51+
}
52+
```
53+
54+
If you have [a different way](https://github.com/phpstan/phpstan-deprecation-rules/issues/64) of marking code that calls deprecated symbols on purpose and you don't want these calls to be reported either, you can write an extension by implementing the [`DeprecatedScopeResolver`](https://github.com/phpstan/phpstan-deprecation-rules/blob/1.1.x/src/Rules/Deprecations/DeprecatedScopeResolver.php) interface.
55+
56+
For example if you mark your PHPUnit tests that test deprecated code with `@group legacy`, you can implement the extension this way:
57+
58+
```php
59+
class GroupLegacyScopeResolver implements DeprecatedScopeResolver
60+
{
61+
62+
public function isScopeDeprecated(Scope $scope): bool
63+
{
64+
$function = $scope->getFunction();
65+
return $function !== null
66+
&& $function->getDocComment() !== null
67+
&& strpos($function->getDocComment(), '@group legacy') !== false;
68+
}
69+
70+
}
71+
```
72+
73+
And register it in your [configuration file](https://phpstan.org/config-reference):
74+
75+
```neon
76+
services:
77+
-
78+
class: GroupLegacyScopeResolver
79+
tags:
80+
- phpstan.deprecations.deprecatedScopeResolver
81+
```
82+
83+
[Learn more about Scope](https://phpstan.org/developing-extensions/scope), a core concept for implementing custom PHPStan extensions.

0 commit comments

Comments
 (0)