3
3
namespace PHPStan \Type \PHPUnit \Assert ;
4
4
5
5
use PhpParser \Node \Arg ;
6
+ use PhpParser \Node \Expr \BinaryOp \Identical ;
7
+ use PhpParser \Node \Expr \FuncCall ;
8
+ use PhpParser \Node \Expr \Instanceof_ ;
6
9
use PhpParser \Node \Name ;
7
10
use PHPStan \Analyser \Scope ;
8
11
use PHPStan \Analyser \SpecifiedTypes ;
@@ -117,7 +120,7 @@ private static function getExpressionResolvers(): array
117
120
{
118
121
if (self ::$ resolvers === null ) {
119
122
self ::$ resolvers = [
120
- 'InstanceOf ' => function (Scope $ scope , Arg $ class , Arg $ object ) {
123
+ 'InstanceOf ' => function (Scope $ scope , Arg $ class , Arg $ object ): ? Instanceof_ {
121
124
$ classType = $ scope ->getType ($ class ->value );
122
125
if (!$ classType instanceof ConstantStringType) {
123
126
return null ;
@@ -128,64 +131,64 @@ private static function getExpressionResolvers(): array
128
131
new \PhpParser \Node \Name ($ classType ->getValue ())
129
132
);
130
133
},
131
- 'Same ' => function (Scope $ scope , Arg $ expected , Arg $ actual ) {
134
+ 'Same ' => function (Scope $ scope , Arg $ expected , Arg $ actual ): Identical {
132
135
return new \PhpParser \Node \Expr \BinaryOp \Identical (
133
136
$ expected ->value ,
134
137
$ actual ->value
135
138
);
136
139
},
137
- 'True ' => function (Scope $ scope , Arg $ actual ) {
140
+ 'True ' => function (Scope $ scope , Arg $ actual ): Identical {
138
141
return new \PhpParser \Node \Expr \BinaryOp \Identical (
139
142
$ actual ->value ,
140
143
new \PhpParser \Node \Expr \ConstFetch (new Name ('true ' ))
141
144
);
142
145
},
143
- 'False ' => function (Scope $ scope , Arg $ actual ) {
146
+ 'False ' => function (Scope $ scope , Arg $ actual ): Identical {
144
147
return new \PhpParser \Node \Expr \BinaryOp \Identical (
145
148
$ actual ->value ,
146
149
new \PhpParser \Node \Expr \ConstFetch (new Name ('false ' ))
147
150
);
148
151
},
149
- 'Null ' => function (Scope $ scope , Arg $ actual ) {
152
+ 'Null ' => function (Scope $ scope , Arg $ actual ): Identical {
150
153
return new \PhpParser \Node \Expr \BinaryOp \Identical (
151
154
$ actual ->value ,
152
155
new \PhpParser \Node \Expr \ConstFetch (new Name ('null ' ))
153
156
);
154
157
},
155
- 'IsArray ' => function (Scope $ scope , Arg $ actual ) {
158
+ 'IsArray ' => function (Scope $ scope , Arg $ actual ): FuncCall {
156
159
return new \PhpParser \Node \Expr \FuncCall (new Name ('is_array ' ), [$ actual ]);
157
160
},
158
- 'IsBool ' => function (Scope $ scope , Arg $ actual ) {
161
+ 'IsBool ' => function (Scope $ scope , Arg $ actual ): FuncCall {
159
162
return new \PhpParser \Node \Expr \FuncCall (new Name ('is_bool ' ), [$ actual ]);
160
163
},
161
- 'IsCallable ' => function (Scope $ scope , Arg $ actual ) {
164
+ 'IsCallable ' => function (Scope $ scope , Arg $ actual ): FuncCall {
162
165
return new \PhpParser \Node \Expr \FuncCall (new Name ('is_callable ' ), [$ actual ]);
163
166
},
164
- 'IsFloat ' => function (Scope $ scope , Arg $ actual ) {
167
+ 'IsFloat ' => function (Scope $ scope , Arg $ actual ): FuncCall {
165
168
return new \PhpParser \Node \Expr \FuncCall (new Name ('is_float ' ), [$ actual ]);
166
169
},
167
- 'IsInt ' => function (Scope $ scope , Arg $ actual ) {
170
+ 'IsInt ' => function (Scope $ scope , Arg $ actual ): FuncCall {
168
171
return new \PhpParser \Node \Expr \FuncCall (new Name ('is_int ' ), [$ actual ]);
169
172
},
170
- 'IsIterable ' => function (Scope $ scope , Arg $ actual ) {
173
+ 'IsIterable ' => function (Scope $ scope , Arg $ actual ): FuncCall {
171
174
return new \PhpParser \Node \Expr \FuncCall (new Name ('is_iterable ' ), [$ actual ]);
172
175
},
173
- 'IsNumeric ' => function (Scope $ scope , Arg $ actual ) {
176
+ 'IsNumeric ' => function (Scope $ scope , Arg $ actual ): FuncCall {
174
177
return new \PhpParser \Node \Expr \FuncCall (new Name ('is_numeric ' ), [$ actual ]);
175
178
},
176
- 'IsObject ' => function (Scope $ scope , Arg $ actual ) {
179
+ 'IsObject ' => function (Scope $ scope , Arg $ actual ): FuncCall {
177
180
return new \PhpParser \Node \Expr \FuncCall (new Name ('is_object ' ), [$ actual ]);
178
181
},
179
- 'IsResource ' => function (Scope $ scope , Arg $ actual ) {
182
+ 'IsResource ' => function (Scope $ scope , Arg $ actual ): FuncCall {
180
183
return new \PhpParser \Node \Expr \FuncCall (new Name ('is_resource ' ), [$ actual ]);
181
184
},
182
- 'IsString ' => function (Scope $ scope , Arg $ actual ) {
185
+ 'IsString ' => function (Scope $ scope , Arg $ actual ): FuncCall {
183
186
return new \PhpParser \Node \Expr \FuncCall (new Name ('is_string ' ), [$ actual ]);
184
187
},
185
- 'IsScalar ' => function (Scope $ scope , Arg $ actual ) {
188
+ 'IsScalar ' => function (Scope $ scope , Arg $ actual ): FuncCall {
186
189
return new \PhpParser \Node \Expr \FuncCall (new Name ('is_scalar ' ), [$ actual ]);
187
190
},
188
- 'InternalType ' => function (Scope $ scope , Arg $ type , Arg $ value ) {
191
+ 'InternalType ' => function (Scope $ scope , Arg $ type , Arg $ value ): ? FuncCall {
189
192
$ typeType = $ scope ->getType ($ type ->value );
190
193
if (!$ typeType instanceof ConstantStringType) {
191
194
return null ;
0 commit comments