This repository was archived by the owner on Jul 12, 2020. It is now read-only.
File tree 2 files changed +75
-0
lines changed
src/main/QafooLabs/Refactoring/Adapters/PHPParser/Visitor
2 files changed +75
-0
lines changed Original file line number Diff line number Diff line change @@ -197,3 +197,55 @@ Feature: Fix Class Names
197
197
-new Foo\Foo();
198
198
+new Foo\Bar();
199
199
"""
200
+ Scenario : "Rename class changes that is extended"
201
+ Given a PHP File named "src/Foo/Bar.php" with:
202
+ """
203
+ <?php
204
+ namespace Foo;
205
+
206
+ class Foo
207
+ {
208
+ }
209
+ """
210
+ Given a PHP File named "src/Foo/Baz.php" with:
211
+ """
212
+ <?php
213
+ namespace Foo;
214
+
215
+ class Baz extends Foo
216
+ {
217
+ }
218
+ """
219
+ When I use refactoring "fix-class-names" with:
220
+ | arg | value |
221
+ | dir | src / |
222
+ Then the PHP File "src/Foo.php" should be refactored:
223
+ """
224
+ --- a/src/Foo/Bar.php
225
+ +++ b/src/Foo/Bar.php
226
+ @@ -2,5 +2,5 @@
227
+ namespace Foo;
228
+
229
+ -class Foo
230
+ +class Bar
231
+ {
232
+ }
233
+ --- a/Foo/src/Foo/Bar.php
234
+ +++ b/Foo/src/Foo/Bar.php
235
+ @@ -2,5 +2,5 @@
236
+ namespace Foo;
237
+
238
+ -class Foo
239
+ +class Bar
240
+ {
241
+ }
242
+ --- a/Foo/Baz.php
243
+ +++ b/Foo/Baz.php
244
+ @@ -2,5 +2,5 @@
245
+ namespace Foo;
246
+
247
+ -class Baz extends Foo
248
+ +class Baz extends Bar
249
+ {
250
+ }
251
+ """
Original file line number Diff line number Diff line change 17
17
use PHPParser_Node_Name ;
18
18
use PHPParser_Node_Stmt_Namespace ;
19
19
use PHPParser_Node_Stmt_Use ;
20
+ use PHPParser_Node_Stmt_Class ;
20
21
use PHPParser_Node_Stmt_UseUse ;
21
22
use PHPParser_Node_Expr_New ;
22
23
use PHPParser_Node_Expr_StaticCall ;
@@ -63,6 +64,28 @@ public function enterNode(PHPParser_Node $node)
63
64
);
64
65
}
65
66
67
+ if ($ node instanceof PHPParser_Node_Stmt_Class) {
68
+ if ($ node ->extends ) {
69
+ $ usedAlias = implode ('\\' , $ node ->extends ->parts );
70
+
71
+ $ this ->nameDeclarations [] = array (
72
+ 'alias ' => $ usedAlias ,
73
+ 'fqcn ' => $ this ->fullyQualifiedNameFor ($ usedAlias ),
74
+ 'line ' => $ node ->extends ->getLine (),
75
+ );
76
+ }
77
+
78
+ foreach ($ node ->implements as $ implement ) {
79
+ $ usedAlias = implode ('\\' , $ implement ->parts );
80
+
81
+ $ this ->nameDeclarations [] = array (
82
+ 'alias ' => $ usedAlias ,
83
+ 'fqcn ' => $ this ->fullyQualifiedNameFor ($ usedAlias ),
84
+ 'line ' => $ implement ->getLine (),
85
+ );
86
+ }
87
+ }
88
+
66
89
if ($ node instanceof PHPParser_Node_Stmt_Namespace) {
67
90
$ this ->currentNamespace = implode ('\\' , $ node ->name ->parts );
68
91
$ this ->useStatements = array ();
You can’t perform that action at this time.
0 commit comments