File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed
rules-tests/Configs/Rector/Closure/FromServicePublicToDefaultsPublicRector/Fixture
rules/Configs/Rector/Closure Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Symfony \Tests \Configs \Rector \Closure \ServiceTagsToDefaultsAutoconfigureRector \Fixture ;
4+
5+ use Symfony \Component \DependencyInjection \Loader \Configurator \ContainerConfigurator ;
6+
7+ return static function (ContainerConfigurator $ containerConfigurator ): void {
8+ $ services = $ containerConfigurator ->services ();
9+
10+ $ services ->defaults ()->public ();
11+
12+ $ services ->set (NextCommand::class)
13+ ->public ();
14+ };
15+
16+ ?>
17+ -----
18+ <?php
19+
20+ namespace Rector \Symfony \Tests \Configs \Rector \Closure \ServiceTagsToDefaultsAutoconfigureRector \Fixture ;
21+
22+ use Symfony \Component \DependencyInjection \Loader \Configurator \ContainerConfigurator ;
23+
24+ return static function (ContainerConfigurator $ containerConfigurator ): void {
25+ $ services = $ containerConfigurator ->services ();
26+
27+ $ services ->defaults ()->public ();
28+
29+ $ services ->set (NextCommand::class);
30+ };
31+
32+ ?>
Original file line number Diff line number Diff line change @@ -98,6 +98,11 @@ public function refactor(Node $node): ?Node
9898 return null ;
9999 }
100100
101+ // not the ->defaults()->public()
102+ if ($ this ->isDefaultCall ($ node )) {
103+ return null ;
104+ }
105+
101106 $ hasChanged = true ;
102107
103108 return $ node ->var ;
@@ -113,4 +118,17 @@ public function refactor(Node $node): ?Node
113118
114119 return $ node ;
115120 }
121+
122+ public function isDefaultCall (MethodCall $ methodCall ): bool
123+ {
124+ $ currentMethodCall = $ methodCall ;
125+ while ($ currentMethodCall instanceof MethodCall) {
126+ if ($ this ->isName ($ currentMethodCall ->name , 'defaults ' )) {
127+ return true ;
128+ }
129+ $ currentMethodCall = $ currentMethodCall ->var ;
130+ }
131+
132+ return false ;
133+ }
116134}
You can’t perform that action at this time.
0 commit comments