Skip to content

Commit ca83487

Browse files
committed
Merge ParameterAttributeCollector into ClassAttributeCollector
1 parent e164e10 commit ca83487

File tree

2 files changed

+35
-56
lines changed

2 files changed

+35
-56
lines changed

src/ClassAttributeCollector.php

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,9 @@
1313
*/
1414
class ClassAttributeCollector
1515
{
16-
private ParameterAttributeCollector $parameterAttributeCollector;
17-
1816
public function __construct(
1917
private Logger $log,
2018
) {
21-
$this->parameterAttributeCollector = new ParameterAttributeCollector($this->log);
2219
}
2320

2421
/**
@@ -126,8 +123,6 @@ private static function isAttributeIgnored(ReflectionAttribute $attribute): bool
126123
/**
127124
* @param array<TransientTargetMethod> $methodAttributes
128125
* @param array<TransientTargetParameter> $parameterAttributes
129-
*
130-
* @return void
131126
*/
132127
private function collectMethodAndParameterAttributes(
133128
string $class,
@@ -153,7 +148,41 @@ private function collectMethodAndParameterAttributes(
153148

154149
$parameterAttributes = array_merge(
155150
$parameterAttributes,
156-
$this->parameterAttributeCollector->collectAttributes($methodReflection),
151+
$this->collectParameterAttributes($methodReflection),
157152
);
158153
}
154+
155+
/**
156+
* @return array<TransientTargetParameter>
157+
*/
158+
private function collectParameterAttributes(\ReflectionMethod $reflectionFunctionAbstract): array
159+
{
160+
$targets = [];
161+
$class = $reflectionFunctionAbstract->class;
162+
$method = $reflectionFunctionAbstract->name;
163+
164+
foreach ($reflectionFunctionAbstract->getParameters() as $parameter) {
165+
/** @var non-empty-string $name */
166+
$name = $parameter->name;
167+
168+
$paramLabel = $class . '::' . $method . '(' . $name . ')';
169+
170+
foreach ($parameter->getAttributes() as $attribute) {
171+
if (self::isAttributeIgnored($attribute)) {
172+
continue;
173+
}
174+
175+
$this->log->debug("Found attribute {$attribute->getName()} on $paramLabel");
176+
177+
$targets[] = new TransientTargetParameter(
178+
$attribute->getName(),
179+
$attribute->getArguments(),
180+
$method,
181+
$name
182+
);
183+
}
184+
}
185+
186+
return $targets;
187+
}
159188
}

src/ParameterAttributeCollector.php

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)