File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed
rules-tests/CodeQuality/Rector/ClassMethod/AddInstanceofAssertForNullableInstanceRector/Fixture
rules/CodeQuality/NodeAnalyser Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Rector \PHPUnit \Tests \CodeQuality \Rector \ClassMethod \AddInstanceofAssertForNullableInstanceRector \Fixture ;
6+
7+ use PHPUnit \Framework \TestCase ;
8+ use Rector \PHPUnit \Tests \CodeQuality \Rector \ClassMethod \AddInstanceofAssertForNullableInstanceRector \Source \SomeClassUsedInTests ;
9+
10+ final class SkipWithIfElse extends TestCase
11+ {
12+ public function test (): void
13+ {
14+ $ someObject = $ this ->getSomeObject ();
15+ $ value = $ someObject ->getSomeMethod ();
16+
17+ if ($ value !== null ) {
18+ $ this ->assertSame (123 , $ value );
19+
20+ // we know the value here, no need to add instanceof
21+ $ value = $ someObject ->getSomeMethod ();
22+ } else {
23+ $ this ->assertNull ($ value );
24+ }
25+ }
26+
27+ private function getSomeObject (): ?SomeClassUsedInTests
28+ {
29+ if (mt_rand (0 , 1 )) {
30+ return new SomeClassUsedInTests ();
31+ }
32+
33+ return null ;
34+ }
35+ }
36+
37+ ?>
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ public function collect(ClassMethod|Foreach_ $stmtsAware): VariableNameToTypeCol
3737 // first round to collect assigns
3838 foreach ((array ) $ stmtsAware ->stmts as $ stmt ) {
3939 if (! $ stmt instanceof Expression) {
40- continue ;
40+ return new VariableNameToTypeCollection ([]) ;
4141 }
4242
4343 if (! $ stmt ->expr instanceof Assign) {
You can’t perform that action at this time.
0 commit comments