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

Commit 598cd98

Browse files
committed
Bugfix for #16 with default namespace and more tests.
1 parent ecb6735 commit 598cd98

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

features/fix_class_names.feature

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,76 @@ Feature: Fix Class Names
124124
-use Bar\Bar;
125125
+use Foo\Bar;
126126
"""
127+
128+
Scenario: "Rename class changes static occurances"
129+
Given a PHP File named "src/Foo/Bar.php" with:
130+
"""
131+
<?php
132+
namespace Foo;
133+
134+
class Foo
135+
{
136+
}
137+
"""
138+
Given a PHP File named "src/Foo.php" with:
139+
"""
140+
<?php
141+
Foo\Foo::bar();
142+
"""
143+
When I use refactoring "fix-class-names" with:
144+
| arg | value |
145+
| dir | src/ |
146+
Then the PHP File "src/Foo.php" should be refactored:
147+
"""
148+
--- a/src/Foo/Bar.php
149+
+++ b/src/Foo/Bar.php
150+
@@ -2,5 +2,5 @@
151+
namespace Foo;
152+
153+
-class Foo
154+
+class Bar
155+
{
156+
}
157+
--- a/Foo.php
158+
+++ b/Foo.php
159+
@@ -1,2 +1,2 @@
160+
<?php
161+
-Foo\Foo::bar();
162+
+Foo\Bar::bar();
163+
"""
164+
Scenario: "Rename class changes new instantiations"
165+
Given a PHP File named "src/Foo/Bar.php" with:
166+
"""
167+
<?php
168+
namespace Foo;
169+
170+
class Foo
171+
{
172+
}
173+
"""
174+
Given a PHP File named "src/Foo.php" with:
175+
"""
176+
<?php
177+
new Foo\Foo();
178+
"""
179+
When I use refactoring "fix-class-names" with:
180+
| arg | value |
181+
| dir | src/ |
182+
Then the PHP File "src/Foo.php" should be refactored:
183+
"""
184+
--- a/src/Foo/Bar.php
185+
+++ b/src/Foo/Bar.php
186+
@@ -2,5 +2,5 @@
187+
namespace Foo;
188+
189+
-class Foo
190+
+class Bar
191+
{
192+
}
193+
--- a/Foo.php
194+
+++ b/Foo.php
195+
@@ -1,2 +1,2 @@
196+
<?php
197+
-new Foo\Foo();
198+
+new Foo\Bar();
199+
"""

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private function fullyQualifiedNameFor($alias)
7878
} else if (isset($this->useStatements[$alias])) {
7979
$class = $this->useStatements[$alias];
8080
} else {
81-
$class = $this->currentNamespace . '\\' . $alias;
81+
$class = ltrim($this->currentNamespace . '\\' . $alias, '\\');
8282
}
8383

8484
return $class;

0 commit comments

Comments
 (0)