File tree 3 files changed +28
-5
lines changed
tests/PHPStan/Rules/Comparison
3 files changed +28
-5
lines changed Original file line number Diff line number Diff line change 11
11
use PHPStan \Analyser \TypeSpecifierContext ;
12
12
use PHPStan \Reflection \ReflectionProvider ;
13
13
use PHPStan \Type \Constant \ConstantArrayType ;
14
+ use PHPStan \Type \Constant \ConstantBooleanType ;
14
15
use PHPStan \Type \Constant \ConstantStringType ;
15
16
use PHPStan \Type \MixedType ;
16
17
use PHPStan \Type \NeverType ;
@@ -63,7 +64,12 @@ public function findSpecifiedType(
63
64
if ($ node ->name instanceof \PhpParser \Node \Name) {
64
65
$ functionName = strtolower ((string ) $ node ->name );
65
66
if ($ functionName === 'assert ' ) {
66
- return $ this ->findSpecifiedType ($ scope , $ node ->args [0 ]->value );
67
+ $ assertValue = $ scope ->getType ($ node ->args [0 ]->value )->toBoolean ();
68
+ if (!$ assertValue instanceof ConstantBooleanType) {
69
+ return null ;
70
+ }
71
+
72
+ return $ assertValue ->getValue ();
67
73
}
68
74
if (in_array ($ functionName , [
69
75
'class_exists ' ,
Original file line number Diff line number Diff line change @@ -234,10 +234,6 @@ public function testImpossibleCheckTypeFunctionCall(): void
234
234
'Call to function property_exists() with CheckTypeFunctionCall\Bug2221 and \'foo \' will always evaluate to true. ' ,
235
235
782 ,
236
236
],
237
- [
238
- 'Call to function assert() with bool will always evaluate to true. ' ,
239
- 786 ,
240
- ],
241
237
[
242
238
'Call to function property_exists() with CheckTypeFunctionCall\Bug2221 and \'foo \' will always evaluate to true. ' ,
243
239
786 ,
@@ -382,4 +378,11 @@ public function testBug2550(): void
382
378
$ this ->analyse ([__DIR__ . '/data/bug-2550.php ' ], []);
383
379
}
384
380
381
+ public function testBug3994 (): void
382
+ {
383
+ $ this ->checkAlwaysTrueCheckTypeFunctionCall = true ;
384
+ $ this ->treatPhpDocTypesAsCertain = true ;
385
+ $ this ->analyse ([__DIR__ . '/data/bug-3994.php ' ], []);
386
+ }
387
+
385
388
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Bug3994 ;
4
+
5
+ class HelloWorld
6
+ {
7
+
8
+ public function split (string $ str ): void
9
+ {
10
+ $ parts = explode (". " , $ str );
11
+ assert (count ($ parts ) === 4 );
12
+ }
13
+
14
+ }
You can’t perform that action at this time.
0 commit comments