Skip to content
This repository was archived by the owner on Mar 6, 2022. It is now read-only.

Commit d839e22

Browse files
committed
Applies CS fixes
1 parent 09c0213 commit d839e22

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

lib/Pattern.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,29 @@ public function tokens(string $filePath): array
8484
* @param array<string,string> $tokens
8585
*/
8686
public function replaceTokens(array $tokens): string
87+
{
88+
return $this->cleanRemainingTokens($this->replaceTokensWithValues($tokens));
89+
}
90+
91+
public function toString(): string
92+
{
93+
return $this->pattern;
94+
}
95+
96+
/**
97+
* @param array<string,string> $tokens
98+
*/
99+
private function replaceTokensWithValues(array $tokens): string
87100
{
88101
return strtr($this->pattern, (array)array_combine(array_map(function (string $key) {
89102
return '<' . $key . '>';
90103
}, array_keys($tokens)), array_values($tokens)));
91104
}
92105

93-
public function toString(): string
106+
private function cleanRemainingTokens(string $filePath): string
94107
{
95-
return $this->pattern;
108+
return strtr($filePath, (array)array_combine(array_map(function (string $tokenName) {
109+
return '<' . $tokenName . '>';
110+
}, $this->tokenNames), array_fill(0, count($this->tokenNames), '')));
96111
}
97112
}

tests/Unit/PathFinderTest.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,31 @@ public function provideTeleport()
142142
'target2' => 'tests/Model/Abstractor/MyFile/Unit/ModuleOneTest.php',
143143
],
144144
];
145+
146+
yield 'multiple with missing placeholders' => [
147+
[
148+
'target1' => 'lib/<module>/<kernel>.php',
149+
'target2' => 'tests/Unit/<kernel>Test.php',
150+
],
151+
'lib/ModuleOne/Model/Abstractor/MyFile.php',
152+
[
153+
'target2' => 'tests/Unit/Model/Abstractor/MyFileTest.php',
154+
],
155+
];
156+
157+
yield 'multiple with non-correlating placeholders' => [
158+
[
159+
'target1' => 'lib/<foo>/<bar>.php',
160+
'target2' => 'tests/Unit/<kernel>Test.php',
161+
],
162+
'lib/ModuleOne/Model/Abstractor/MyFile.php',
163+
[
164+
'target2' => 'tests/Unit/Test.php',
165+
],
166+
];
145167
}
146168

147-
public function testNoMatchingTarget()
169+
public function testNoMatchingTarget(): void
148170
{
149171
$this->expectException(NoMatchingSourceException::class);
150172
$this->expectExceptionMessage('Could not find matching source pattern for "/lib/Foo.php", known patterns: "/soos/<kernel>/boos.php"');
@@ -156,7 +178,7 @@ public function testNoMatchingTarget()
156178
$teleport->destinationsFor('/lib/Foo.php');
157179
}
158180

159-
public function testDestinationWithNoKernel()
181+
public function testDestinationWithNoKernel(): void
160182
{
161183
$this->expectException(NoPlaceHoldersException::class);
162184
$this->expectExceptionMessage('File pattern "/soos/boos.php" does not contain any <placeholders>');

0 commit comments

Comments
 (0)