File tree Expand file tree Collapse file tree
rules-tests/Php85/Rector/MethodCall/SleepToSerializeRector/Fixture
rules/Php85/Rector/ClassMethod Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+ declare (strict_types=1 );
3+
4+ namespace Rector \Tests \Php85 \Rector \MethodCall \NullDebugInfoReturnRector \Fixture ;
5+
6+ class User {
7+ private $ id ;
8+ private $ name ;
9+
10+ public function __sleep (): array {
11+ return [];
12+ }
13+ }
14+ ?>
15+ ?>
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -87,7 +87,7 @@ public function refactor(Node $node): ?Node
8787 return null ;
8888 }
8989
90- if (! $ this ->isName ($ node ->name , '__sleep ' )) {
90+ if ($ node -> returnType instanceof Identifier && $ this ->isName ($ node ->returnType , 'array ' )) {
9191 return null ;
9292 }
9393
@@ -97,11 +97,13 @@ public function refactor(Node $node): ?Node
9797 }
9898
9999 foreach ($ returns as $ return ) {
100- if (! $ return ->expr instanceof Array_) {
100+ if (! $ return ->expr instanceof Array_ ) {
101101 return null ;
102102 }
103- if (! empty ($ return ->expr ->items )) {
104103
104+ if (count ($ return ->expr ->items ) > 0 ) {
105+ $ newItems = [];
106+ $ hasChanged = false ;
105107 foreach ($ return ->expr ->items as $ item ) {
106108 if ($ item !== null && $ item ->value instanceof Node \Scalar \String_) {
107109 $ propName = $ item ->value ->value ;
@@ -111,14 +113,19 @@ public function refactor(Node $node): ?Node
111113 );
112114 }
113115 }
114- $ return ->expr ->items = $ newItems ;
116+ if (count ($ newItems ) > 0 ) {
117+ $ hasChanged = true ;
118+ $ return ->expr ->items = $ newItems ;
119+ }
115120 }
116-
117121 }
118122
119- $ node ->name = new Identifier ('__serialize ' );
120- $ node ->returnType = new Identifier ('array ' );
123+ if ($ hasChanged ){
124+ $ node ->name = new Identifier ('__serialize ' );
125+ $ node ->returnType = new Identifier ('array ' );
126+ return $ node ;
127+ }
121128
122- return $ node ;
129+ return null ;
123130 }
124131}
You can’t perform that action at this time.
0 commit comments