File tree Expand file tree Collapse file tree 12 files changed +64
-14
lines changed Expand file tree Collapse file tree 12 files changed +64
-14
lines changed Original file line number Diff line number Diff line change 20
20
"php" : " >=8.0"
21
21
},
22
22
"require-dev" : {
23
- "php-static-analysis/node-visitor" : " dev-main" ,
24
- "php-static-analysis/phpstan-extension" : " dev-main" ,
25
- "php-static-analysis/psalm-plugin" : " dev-main" ,
23
+ "php-static-analysis/node-visitor" : " ^0.3.2 || dev-main" ,
24
+ "php-static-analysis/phpstan-extension" : " ^0.3.2 || dev-main" ,
25
+ "php-static-analysis/psalm-plugin" : " ^0.3.2 || dev-main" ,
26
26
"phpstan/extension-installer" : " ^1.3" ,
27
- "phpstan/phpstan" : " ^1.8" ,
27
+ "phpstan/phpstan" : " ^1.8 | ^2.0 " ,
28
28
"phpunit/phpunit" : " ^9.0" ,
29
29
"symplify/easy-coding-standard" : " ^12.1" ,
30
30
"vimeo/psalm" : " ^5"
Original file line number Diff line number Diff line change @@ -3,15 +3,17 @@ parameters:
3
3
paths :
4
4
- src
5
5
- tests
6
- featureToggles :
7
- readOnlyByPhpDoc : true
8
6
9
7
ignoreErrors :
10
8
- ' #^Constructor of class PhpStaticAnalysis\\Attributes\\[a-zA-Z ]+ has an unused parameter \$[a-zA-Z ]+\.$ #'
11
9
- '#^ (Function|Method ) [a-zA-Z\ : ]+\ (\ ) return type has no value type specified in iterable type array.$ #'
12
10
- ' #^Parameter \ #1 \.*\$[a-zA-Z ]+ of attribute class PhpStaticAnalysis\\Attributes\\[a-zA-Z ]+ constructor expects string , int given.$ #'
13
- - ' #^PHPDoc tag @[a-z\-A-Z ]+ has invalid value \ (\ ): Unexpected token "\\n " , expected type at offset [0-9 ]+$ #'
14
11
- ' #^Attribute class PhpStaticAnalysis\\Attributes\\[a-zA-Z ]+ constructor invoked with [0-9 ]+ parameter (s )? , [0-9 ]+ required.$ #'
15
12
- ' #^Attribute class PhpStaticAnalysis\\Attributes\\[a-zA-Z ]+ is not repeatable but is already present above the (property|method ).$ #'
16
13
- ' #^Method [a-zA-Z\ : ]+\ (\ ) has parameter \$[a-zA-Z ]+ with generic class [a-zA-Z ]+ but does not specify its types : [a-zA-Z ]+$ #'
17
- - ' #^PHPDoc tag @phpstan-self-out contains generic type [a-zA-Z ]+<[a-zA-Z ]+> but class [a-zA-Z ]+ is not generic.$ #'
14
+ - ' #^PHPDoc tag @[a-z\-A-Z ]+ has invalid value \ (\ ): Unexpected token "\\n " , expected type at offset [0-9 ]+ ( on line [0-9 ]+ )?$ #'
15
+ - ' #^Possibly impure call to method [a-z\-A-Z ]+::[a-z\-A-Z ]+\ (\ ) in pure (method|function ) ([a-z\-A-Z ]+:: )?[a-z\-A-Z ]+\ (\ ).?$ #'
16
+ - ' #^Possibly impure instantiation of class [a-z\-A-Z ]+ in pure function [a-z\-A-Z ]+\ (\ ).?$ #'
17
+
18
+ includes :
19
+ - vendor/phpstan/phpstan/conf/bleedingEdge.neon
Original file line number Diff line number Diff line change @@ -107,3 +107,8 @@ function functionDeprecated(): bool
107
107
$ reflection = new ReflectionFunction (__FUNCTION__ );
108
108
return DeprecatedTest::getDeprecatedFromReflection ($ reflection );
109
109
}
110
+
111
+ class DeprecatedClass
112
+ {
113
+ use DeprecatedTestTrait;
114
+ }
Original file line number Diff line number Diff line change @@ -51,3 +51,8 @@ trait ImmutableTestTrait
51
51
interface ImmutableTestInterface
52
52
{
53
53
}
54
+
55
+ class ImmutableClass
56
+ {
57
+ use ImmutableTestTrait;
58
+ }
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ public static function getRequireExtendssFromReflection(
22
22
if ($ attribute ->getName () === RequireExtends::class) {
23
23
$ attribute ->newInstance ();
24
24
$ extends = $ attribute ->getArguments ()[0 ];
25
+ assert (is_string ($ extends ));
25
26
}
26
27
}
27
28
Original file line number Diff line number Diff line change @@ -95,6 +95,7 @@ public static function getReturnsFromReflection(
95
95
if ($ attribute ->getName () === Returns::class) {
96
96
$ attribute ->newInstance ();
97
97
$ returns = $ attribute ->getArguments ()[0 ];
98
+ assert (is_string ($ returns ));
98
99
}
99
100
}
100
101
Original file line number Diff line number Diff line change 3
3
declare (strict_types=1 );
4
4
5
5
use PhpStaticAnalysis \Attributes \SelfOut ;
6
+ use PhpStaticAnalysis \Attributes \Template ;
6
7
use PHPUnit \Framework \TestCase ;
7
8
9
+ #[Template('T ' )]
8
10
class SelfOutTest extends TestCase
9
11
{
10
12
public function testMethodSelfOut (): void
@@ -84,6 +86,7 @@ private function getSelfOut(string $methodName): string
84
86
if ($ attribute ->getName () === SelfOut::class) {
85
87
$ attribute ->newInstance ();
86
88
$ selfOut = $ attribute ->getArguments ()[0 ];
89
+ assert (is_string ($ selfOut ));
87
90
}
88
91
}
89
92
Original file line number Diff line number Diff line change 3
3
declare (strict_types=1 );
4
4
5
5
use PhpStaticAnalysis \Attributes \TemplateContravariant ;
6
+ use PhpStaticAnalysis \Attributes \TemplateUse ;
6
7
use PHPUnit \Framework \TestCase ;
7
8
8
9
#[TemplateContravariant('TClass ' , Exception::class)]
@@ -36,8 +37,11 @@ public static function getTemplateContravariantsFromReflection(
36
37
$ attribute ->newInstance ();
37
38
$ templateData = $ attribute ->getArguments ();
38
39
$ templateValue = $ templateData [0 ];
39
- if (isset ($ templateData [1 ]) && $ templateData [1 ] !== null ) {
40
- $ templateValue .= ' of ' . $ templateData [1 ];
40
+ assert (is_string ($ templateValue ));
41
+ if (isset ($ templateData [1 ])) {
42
+ $ className = $ templateData [1 ];
43
+ assert (is_string ($ className ));
44
+ $ templateValue .= ' of ' . $ className ;
41
45
}
42
46
$ templates [] = $ templateValue ;
43
47
}
@@ -56,3 +60,9 @@ trait TemplateContravariantTestTrait
56
60
interface TemplateContravariantTestInterface
57
61
{
58
62
}
63
+
64
+ #[TemplateUse('TemplateContravariantTestTrait<string> ' )]
65
+ class ContravariantClass
66
+ {
67
+ use TemplateContravariantTestTrait;
68
+ }
Original file line number Diff line number Diff line change 3
3
declare (strict_types=1 );
4
4
5
5
use PhpStaticAnalysis \Attributes \TemplateCovariant ;
6
+ use PhpStaticAnalysis \Attributes \TemplateUse ;
6
7
use PHPUnit \Framework \TestCase ;
7
8
8
9
#[TemplateCovariant('TClass ' , Exception::class)]
@@ -36,8 +37,11 @@ public static function getTemplateCovariantsFromReflection(
36
37
$ attribute ->newInstance ();
37
38
$ templateData = $ attribute ->getArguments ();
38
39
$ templateValue = $ templateData [0 ];
39
- if (isset ($ templateData [1 ]) && $ templateData [1 ] !== null ) {
40
- $ templateValue .= ' of ' . $ templateData [1 ];
40
+ assert (is_string ($ templateValue ));
41
+ if (isset ($ templateData [1 ])) {
42
+ $ className = $ templateData [1 ];
43
+ assert (is_string ($ className ));
44
+ $ templateValue .= ' of ' . $ className ;
41
45
}
42
46
$ templates [] = $ templateValue ;
43
47
}
@@ -56,3 +60,9 @@ trait TemplateCovariantTestTrait
56
60
interface TemplateCovariantTestInterface
57
61
{
58
62
}
63
+
64
+ #[TemplateUse('TemplateCovariantTestTrait<string> ' )]
65
+ class CovariantClass
66
+ {
67
+ use TemplateCovariantTestTrait;
68
+ }
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ public static function getTemplateExtendssFromReflection(
23
23
if ($ attribute ->getName () === TemplateExtends::class) {
24
24
$ attribute ->newInstance ();
25
25
$ extends = $ attribute ->getArguments ()[0 ];
26
+ assert (is_string ($ extends ));
26
27
}
27
28
}
28
29
Original file line number Diff line number Diff line change 4
4
5
5
use PhpStaticAnalysis \Attributes \Param ;
6
6
use PhpStaticAnalysis \Attributes \Template ;
7
+ use PhpStaticAnalysis \Attributes \TemplateUse ;
7
8
use PHPUnit \Framework \TestCase ;
8
9
9
10
#[Template('TClass ' )]
@@ -103,8 +104,11 @@ public static function getTemplatesFromReflection(
103
104
$ attribute ->newInstance ();
104
105
$ templateData = $ attribute ->getArguments ();
105
106
$ templateValue = $ templateData [0 ];
106
- if (isset ($ templateData [1 ]) && $ templateData [1 ] !== null ) {
107
- $ templateValue .= ' of ' . $ templateData [1 ];
107
+ assert (is_string ($ templateValue ));
108
+ if (isset ($ templateData [1 ])) {
109
+ $ className = $ templateData [1 ];
110
+ assert (is_string ($ className ));
111
+ $ templateValue .= ' of ' . $ className ;
108
112
}
109
113
$ templates [] = $ templateValue ;
110
114
}
@@ -124,6 +128,13 @@ interface TemplateTestInterface
124
128
{
125
129
}
126
130
131
+ #[TemplateUse('TemplateTestTrait<string> ' )]
132
+ class TemplateClass
133
+ {
134
+ use TemplateTestTrait;
135
+ }
136
+
137
+
127
138
#[Template('TFunction ' )]
128
139
#[Param(param: 'TFunction ' )]
129
140
function functionTemplate ($ param ): array
Original file line number Diff line number Diff line change @@ -138,6 +138,7 @@ public static function getTypeFromReflection(
138
138
if ($ attribute ->getName () === Type::class) {
139
139
$ attribute ->newInstance ();
140
140
$ type = $ attribute ->getArguments ()[0 ];
141
+ assert (is_string ($ type ));
141
142
}
142
143
}
143
144
You can’t perform that action at this time.
0 commit comments