File tree Expand file tree Collapse file tree 3 files changed +28
-5
lines changed
tests/PHPStan/Rules/Comparison Expand file tree Collapse file tree 3 files changed +28
-5
lines changed Original file line number Diff line number Diff line change 1111use PHPStan \Analyser \TypeSpecifierContext ;
1212use PHPStan \Reflection \ReflectionProvider ;
1313use PHPStan \Type \Constant \ConstantArrayType ;
14+ use PHPStan \Type \Constant \ConstantBooleanType ;
1415use PHPStan \Type \Constant \ConstantStringType ;
1516use PHPStan \Type \MixedType ;
1617use PHPStan \Type \NeverType ;
@@ -63,7 +64,12 @@ public function findSpecifiedType(
6364 if ($ node ->name instanceof \PhpParser \Node \Name) {
6465 $ functionName = strtolower ((string ) $ node ->name );
6566 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 ();
6773 }
6874 if (in_array ($ functionName , [
6975 'class_exists ' ,
Original file line number Diff line number Diff line change @@ -234,10 +234,6 @@ public function testImpossibleCheckTypeFunctionCall(): void
234234 'Call to function property_exists() with CheckTypeFunctionCall\Bug2221 and \'foo \' will always evaluate to true. ' ,
235235 782 ,
236236 ],
237- [
238- 'Call to function assert() with bool will always evaluate to true. ' ,
239- 786 ,
240- ],
241237 [
242238 'Call to function property_exists() with CheckTypeFunctionCall\Bug2221 and \'foo \' will always evaluate to true. ' ,
243239 786 ,
@@ -382,4 +378,11 @@ public function testBug2550(): void
382378 $ this ->analyse ([__DIR__ . '/data/bug-2550.php ' ], []);
383379 }
384380
381+ public function testBug3994 (): void
382+ {
383+ $ this ->checkAlwaysTrueCheckTypeFunctionCall = true ;
384+ $ this ->treatPhpDocTypesAsCertain = true ;
385+ $ this ->analyse ([__DIR__ . '/data/bug-3994.php ' ], []);
386+ }
387+
385388}
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