File tree Expand file tree Collapse file tree
rules-tests/Php80/Rector/Switch_/ChangeSwitchToMatchRector/Fixture
rules/Php80/Rector/Switch_ Expand file tree Collapse file tree 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 1111use PhpParser \Node \Expr \Cast \Int_ ;
1212use PhpParser \Node \Expr \Cast \String_ ;
1313use PhpParser \Node \Expr \Match_ ;
14+ use PhpParser \Node \FunctionLike ;
1415use PhpParser \Node \Stmt \Expression ;
1516use PhpParser \Node \Stmt \Return_ ;
1617use PhpParser \Node \Stmt \Switch_ ;
18+ use PhpParser \NodeVisitor ;
1719use PHPStan \Type \ObjectType ;
1820use Rector \Contract \PhpParser \Node \StmtsAwareInterface ;
1921use Rector \NodeAnalyzer \ExprAnalyzer ;
@@ -81,13 +83,18 @@ public function getNodeTypes(): array
8183
8284 /**
8385 * @param StmtsAwareInterface $node
86+ * @return null|Node|NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN
8487 */
85- public function refactor (Node $ node ): ? Node
88+ public function refactor (Node $ node ): null | Node | int
8689 {
8790 if (! is_array ($ node ->stmts )) {
8891 return null ;
8992 }
9093
94+ if ($ node instanceof FunctionLike && $ node ->returnsByRef ()) {
95+ return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN ;
96+ }
97+
9198 $ hasChanged = false ;
9299
93100 foreach ($ node ->stmts as $ key => $ stmt ) {
You can’t perform that action at this time.
0 commit comments