File tree Expand file tree Collapse file tree 8 files changed +129
-14
lines changed
tests/src/DeprecatedScope Expand file tree Collapse file tree 8 files changed +129
-14
lines changed Original file line number Diff line number Diff line change @@ -49,19 +49,8 @@ parameters:
49
49
50
50
## Deprecation testing
51
51
52
- Add the deprecation rules to your Drupal project's dependencies
53
-
54
- ```
55
- composer require --dev phpstan/phpstan-deprecation-rules
56
- ```
57
-
58
- Edit your ` phpstan.neon ` to look like the following:
59
-
60
- ```
61
- includes:
62
- - vendor/mglaman/phpstan-drupal/extension.neon
63
- - vendor/phpstan/phpstan-deprecation-rules/rules.neon
64
- ```
52
+ This project depends on ` phpstan/phpstan-deprecation-rules ` which adds deprecation rules. We provide Drupal-specific
53
+ deprecated scope resolvers.
65
54
66
55
To only handle deprecation testing, use a ` phpstan.neon ` like this:
67
56
@@ -80,6 +69,22 @@ includes:
80
69
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
81
70
```
82
71
72
+ To disable deprecation rules while using ` phpstan/extension-installer ` , you can do the following:
73
+
74
+ ``` json
75
+ {
76
+ "extra" : {
77
+ "phpstan/extension-installer" : {
78
+ "ignore" : [
79
+ " phpstan/phpstan-deprecation-rules"
80
+ ]
81
+ }
82
+ }
83
+ }
84
+ ```
85
+
86
+ See the ` extension-installer ` documentation for more information: https://github.com/phpstan/extension-installer#ignoring-a-particular-extension
87
+
83
88
## Adapting to your project
84
89
85
90
### Specifying your Drupal project's root
Original file line number Diff line number Diff line change 13
13
"php" : " ^7.4 || ^8.0" ,
14
14
"symfony/finder" : " ~3.4.5 ||^4.2 || ^5.0 || ^6.0" ,
15
15
"phpstan/phpstan" : " ^1.10.1" ,
16
+ "phpstan/phpstan-deprecation-rules" : " ^1.1.4" ,
16
17
"symfony/yaml" : " ~3.4.5 || ^4.2|| ^5.0 || ^6.0" ,
17
18
"webflo/drupal-finder" : " ^1.2"
18
19
},
22
23
"drupal/core-recommended" : " ^8.8@alpha || ^9.0" ,
23
24
"drush/drush" : " ^9.6 || ^10.0 || ^11" ,
24
25
"phpstan/extension-installer" : " ^1.1" ,
25
- "phpstan/phpstan-deprecation-rules" : " ^1.0" ,
26
26
"phpstan/phpstan-strict-rules" : " ^1.0" ,
27
27
"phpunit/phpunit" : " ^6.5 || ^7.5 || ^8.0 || ^9" ,
28
28
"slevomat/coding-standard" : " ^7.1" ,
Original file line number Diff line number Diff line change @@ -298,3 +298,7 @@ services:
298
298
class : mglaman\PHPStanDrupal\Type\EntityQuery\AccessCheckTypeSpecifyingExtension
299
299
tags :
300
300
- phpstan.typeSpecifier.methodTypeSpecifyingExtension
301
+ -
302
+ class : mglaman\PHPStanDrupal\DeprecatedScope\GroupLegacyScope
303
+ tags :
304
+ - phpstan.deprecations.deprecatedScopeResolver
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ parameters:
11
11
- tests/src/data/*.php
12
12
- tests/src/Type/data/*.php
13
13
- tests/src/Rules/data/*.php
14
+ - tests/src/DeprecatedScope/data/*.php
14
15
dynamicConstantNames :
15
16
- Drupal::VERSION
16
17
includes :
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace mglaman \PHPStanDrupal \DeprecatedScope ;
6
+
7
+ use PHPStan \Analyser \Scope ;
8
+ use PHPStan \Rules \Deprecations \DeprecatedScopeResolver ;
9
+
10
+ final class GroupLegacyScope implements DeprecatedScopeResolver
11
+ {
12
+
13
+ public function isScopeDeprecated (Scope $ scope ): bool
14
+ {
15
+ if ($ scope ->isInClass ()) {
16
+ $ class = $ scope ->getClassReflection ();
17
+ $ phpDoc = $ class ->getResolvedPhpDoc ();
18
+ if ($ phpDoc !== null && strpos ($ phpDoc ->getPhpDocString (), '@group legacy ' ) !== false ) {
19
+ return true ;
20
+ }
21
+ }
22
+
23
+ $ function = $ scope ->getFunction ();
24
+ return $ function !== null
25
+ && $ function ->getDocComment () !== null
26
+ && strpos ($ function ->getDocComment (), '@group legacy ' ) !== false ;
27
+ }
28
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace mglaman \PHPStanDrupal \Tests \DeprecatedScope ;
6
+
7
+ use mglaman \PHPStanDrupal \Tests \DrupalRuleTestCase ;
8
+ use PHPStan \Rules \Deprecations \CallToDeprecatedFunctionRule ;
9
+ use PHPStan \Rules \Deprecations \DeprecatedScopeHelper ;
10
+ use PHPStan \Rules \Rule ;
11
+
12
+ final class GlobalLegacyScopeTest extends DrupalRuleTestCase {
13
+
14
+ protected function getRule (): Rule
15
+ {
16
+ // @phpstan-ignore-next-line
17
+ return new CallToDeprecatedFunctionRule (
18
+ self ::createReflectionProvider (),
19
+ self ::getContainer ()->getByType (DeprecatedScopeHelper::class)
20
+ );
21
+ }
22
+
23
+ public function testCustomScope (): void
24
+ {
25
+ require_once __DIR__ . '/data/deprecated-data-definition.php ' ;
26
+ $ this ->analyse (
27
+ [__DIR__ . '/data/group-legacy.php ' ],
28
+ [
29
+ [
30
+ 'Call to deprecated function Deprecated\deprecated_function(). ' ,
31
+ 21 ,
32
+ ],
33
+ ]
34
+ );
35
+ }
36
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Deprecated ;
4
+
5
+ /**
6
+ * @deprecated
7
+ */
8
+ function deprecated_function (): void {
9
+
10
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace GroupLegacy ;
4
+
5
+ use function Deprecated \deprecated_function ;
6
+
7
+ /**
8
+ * @group legacy
9
+ */
10
+ final class FooTest {
11
+
12
+ public function foo (): void {
13
+ deprecated_function ();
14
+ }
15
+
16
+ }
17
+
18
+ final class BarTest {
19
+
20
+ public function bar (): void {
21
+ deprecated_function ();
22
+ }
23
+
24
+ /**
25
+ * @group legacy
26
+ */
27
+ public function barNot (): void {
28
+ deprecated_function ();
29
+ }
30
+
31
+ }
You can’t perform that action at this time.
0 commit comments