File tree Expand file tree Collapse file tree 2 files changed +39
-1
lines changed
rules-tests/Php80/Rector/Switch_/ChangeSwitchToMatchRector/Fixture
rules/Php80/Rector/Switch_ Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Rector \Tests \Php80 \Rector \Switch_ \ChangeSwitchToMatchRector \Fixture ;
4
+
5
+ /**
6
+ * @see https://3v4l.org/7CEb0
7
+ */
8
+ final class SkipByRefMethod {
9
+ private int $ monday = 0 ;
10
+ private int $ tuesday = 0 ;
11
+ // ...
12
+
13
+ private function &getRef (int $ index ): int {
14
+ switch ($ index ) {
15
+ case 0 :
16
+ return $ this ->monday ;
17
+ case 1 :
18
+ return $ this ->tuesday ;
19
+ // ...
20
+ default :
21
+ throw new LogicException ();
22
+ }
23
+ }
24
+
25
+ public function setAtIndex (int $ index , int $ value ) {
26
+ $ ref = &$ this ->getRef ($ index );
27
+ $ ref = $ value ;
28
+ }
29
+ }
30
+
31
+ ?>
Original file line number Diff line number Diff line change 11
11
use PhpParser \Node \Expr \Cast \Int_ ;
12
12
use PhpParser \Node \Expr \Cast \String_ ;
13
13
use PhpParser \Node \Expr \Match_ ;
14
+ use PhpParser \Node \FunctionLike ;
14
15
use PhpParser \Node \Stmt \Expression ;
15
16
use PhpParser \Node \Stmt \Return_ ;
16
17
use PhpParser \Node \Stmt \Switch_ ;
18
+ use PhpParser \NodeVisitor ;
17
19
use PHPStan \Type \ObjectType ;
18
20
use Rector \Contract \PhpParser \Node \StmtsAwareInterface ;
19
21
use Rector \NodeAnalyzer \ExprAnalyzer ;
@@ -81,13 +83,18 @@ public function getNodeTypes(): array
81
83
82
84
/**
83
85
* @param StmtsAwareInterface $node
86
+ * @return null|Node|NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN
84
87
*/
85
- public function refactor (Node $ node ): ? Node
88
+ public function refactor (Node $ node ): null | Node | int
86
89
{
87
90
if (! is_array ($ node ->stmts )) {
88
91
return null ;
89
92
}
90
93
94
+ if ($ node instanceof FunctionLike && $ node ->returnsByRef ()) {
95
+ return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN ;
96
+ }
97
+
91
98
$ hasChanged = false ;
92
99
93
100
foreach ($ node ->stmts as $ key => $ stmt ) {
You can’t perform that action at this time.
0 commit comments