Skip to content

Commit 6f9c366

Browse files
committed
Fixed multiple target classes applied twice
1 parent 4fbe869 commit 6f9c366

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/Service/TransformerContainer.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,18 @@ public static function matchTransformers(string $className): array
198198
foreach ($instance->transformerTargets as $target => $instances) {
199199
$regex = Regex::fromWildcard($target);
200200
if ($regex->matches($className)) {
201+
// Check if the transformer is already in the list
202+
$alreadyMatched = array_filter(
203+
$matchedInstances,
204+
function (Transformer $transformer) use ($instances) {
205+
return in_array($transformer, $instances, true);
206+
},
207+
);
208+
209+
if ($alreadyMatched) {
210+
continue;
211+
}
212+
201213
$matchedInstances = array_merge($matchedInstances, $instances);
202214
}
203215
}

tests/Stubs/Transformer/StringTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class StringTransformer extends Transformer
1414

1515
public function getTargetClass(): string|array
1616
{
17-
return [StringClass::class, MultipleTransformersClass::class];
17+
return [StringClass::class, 'Okapi*Tests*StringClass', MultipleTransformersClass::class];
1818
}
1919

2020
public function transform(Code $code): void

0 commit comments

Comments
 (0)