Skip to content
This repository was archived by the owner on Jul 12, 2020. It is now read-only.

Commit 99fc415

Browse files
committed
Add support for extends/implements renaming
1 parent cbeac85 commit 99fc415

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

features/fix_class_names.feature

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,55 @@ Feature: Fix Class Names
197197
-new Foo\Foo();
198198
+new Foo\Bar();
199199
"""
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+
"""

src/main/QafooLabs/Refactoring/Adapters/PHPParser/Visitor/PhpNameCollector.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use PHPParser_Node_Name;
1818
use PHPParser_Node_Stmt_Namespace;
1919
use PHPParser_Node_Stmt_Use;
20+
use PHPParser_Node_Stmt_Class;
2021
use PHPParser_Node_Stmt_UseUse;
2122
use PHPParser_Node_Expr_New;
2223
use PHPParser_Node_Expr_StaticCall;
@@ -63,6 +64,28 @@ public function enterNode(PHPParser_Node $node)
6364
);
6465
}
6566

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+
6689
if ($node instanceof PHPParser_Node_Stmt_Namespace) {
6790
$this->currentNamespace = implode('\\', $node->name->parts);
6891
$this->useStatements = array();

0 commit comments

Comments
 (0)