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

Commit 62eba36

Browse files
committed
[GH-28] Add one fix for TYPE_CLASS names.
1 parent 0b9a950 commit 62eba36

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/main/QafooLabs/Refactoring/Domain/Model/PhpName.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ public function change(PhpName $from, PhpName $to)
109109
if ($this->fullyQualifiedName === $this->relativeName) {
110110
$relativeNewParts = $newParts;
111111
} else {
112-
$diff = count($newParts) - $this->numParts();
112+
$diff = ($this->type === self::TYPE_CLASS)
113+
? 0
114+
: count($newParts) - $this->numParts();
115+
113116
$relativeNewParts = array_slice($newParts, -1 * (count(explode('\\', $this->relativeName))+$diff));
114117
}
115118

src/test/QafooLabs/Refactoring/Domain/Model/PhpNameTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,17 @@ public function testAddRelativeNameWhenNamespaceExpands()
171171
$this->assertEquals('Foo\Bar\Foo', $changed->fullyQualifiedName());
172172
$this->assertEquals('Bar\Foo', $changed->relativeName());
173173
}
174+
175+
public function testNotExpandWhenRelativeNameIsTypeClass()
176+
{
177+
$from = new PhpName('Foo', 'Foo');
178+
$to = new PhpName('Foo\Bar', 'Foo\Bar');
179+
180+
$name = new PhpName('Foo\Foo', 'Foo', PhpName::TYPE_CLASS);
181+
$changed = $name->change($from, $to);
182+
183+
$this->assertFalse($name->isAffectedByChangesTo($from));
184+
$this->assertEquals('Foo\Bar\Foo', $changed->fullyQualifiedName());
185+
$this->assertEquals('Foo', $changed->relativeName());
186+
}
174187
}

0 commit comments

Comments
 (0)