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

Commit dfe5485

Browse files
committed
Refactor aggregation of renames via new Set datatype.
1 parent 2238b0d commit dfe5485

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

src/main/QafooLabs/Refactoring/Application/FixClassNames.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace QafooLabs\Refactoring\Application;
1515

16+
use QafooLabs\Collections\Set;
1617
use QafooLabs\Refactoring\Domain\Model\Directory;
1718
use QafooLabs\Refactoring\Domain\Model\File;
1819
use QafooLabs\Refactoring\Domain\Model\PhpName;
@@ -35,7 +36,7 @@ public function refactor(Directory $directory)
3536
{
3637
$phpFiles = $directory->findAllPhpFilesRecursivly();
3738

38-
$renames = array();
39+
$renames = new Set();
3940
$occurances = array();
4041

4142
foreach ($phpFiles as $phpFile) {
@@ -59,19 +60,15 @@ public function refactor(Directory $directory)
5960

6061
$buffer->replaceString($line, $currentClassName->shortName(), $expectedClassName->shortName());
6162

62-
$rename = true;
63+
$renames->add(new PhpNameChange($currentClassName, $expectedClassName));
6364
}
6465

6566
if ($expectedClassName->namespaceName() !== $currentClassName->namespaceName()) {
6667
$namespaceLine = $class->namespaceDeclarationLine();
6768

6869
$buffer->replaceString($namespaceLine, $currentClassName->namespaceName(), $expectedClassName->namespaceName());
6970

70-
$rename = true;
71-
}
72-
73-
if ($rename) {
74-
$renames[] = new PhpNameChange($currentClassName, $expectedClassName);
71+
$renames->add(new PhpNameChange($currentClassName, $expectedClassName));
7572
}
7673
}
7774

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313

1414
namespace QafooLabs\Refactoring\Domain\Model;
1515

16+
use QafooLabs\Collections\Hashable;
17+
1618
/**
1719
* Representation of a Name in PHP
1820
*/
19-
class PhpName
21+
class PhpName implements Hashable
2022
{
2123
private $fullyQualifiedName;
2224
private $relativeName;
@@ -129,4 +131,9 @@ public function __toString()
129131
{
130132
return sprintf('%s[%s]', $this->fullyQualifiedName, $this->relativeName);
131133
}
134+
135+
public function hashCode()
136+
{
137+
return "1373136332" . $this->fullyQualifiedName . $this->relativeName;
138+
}
132139
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
namespace QafooLabs\Refactoring\Domain\Model;
1515

16-
class PhpNameChange
16+
use QafooLabs\Collections\Hashable;
17+
18+
class PhpNameChange implements Hashable
1719
{
1820
private $fromName;
1921
private $toName;
@@ -33,4 +35,9 @@ public function change(PhpName $name)
3335
{
3436
return $name->change($this->fromName, $this->toName);
3537
}
38+
39+
public function hashCode()
40+
{
41+
return "1373136290" . $this->fromName->hashCode() . $this->toName->hashCode();
42+
}
3643
}

0 commit comments

Comments
 (0)