Skip to content

Commit

Permalink
fix: drop parameters check
Browse files Browse the repository at this point in the history
Currently, each parameter attribute is assigned to method's parameter instead of method, makes this check useless
  • Loading branch information
fogrye committed Apr 7, 2024
1 parent 3692d2e commit 190ad43
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 26 deletions.
21 changes: 0 additions & 21 deletions src/AnnotationReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,27 +257,6 @@ public function getParameterAnnotationsPerParameter(array $refParameters): array
$method = $firstParam->getDeclaringFunction();
assert($method instanceof ReflectionMethod);

/** @var ParameterAnnotationInterface[] $parameterAnnotations */
$parameterAnnotations = $this->getMethodAnnotations($method, ParameterAnnotationInterface::class);

/** @var array<string, array<int,ParameterAnnotations>> $parameterAnnotationsPerParameter */
$parameterAnnotationsPerParameter = [];
foreach ($parameterAnnotations as $parameterAnnotation) {
$parameterAnnotationsPerParameter[$parameterAnnotation->getTarget()][] = $parameterAnnotation;
}

// Let's check that the referenced parameters actually do exist:
$parametersByKey = [];
foreach ($refParameters as $refParameter) {
$parametersByKey[$refParameter->getName()] = true;
}
$diff = array_diff_key($parameterAnnotationsPerParameter, $parametersByKey);
if (count($diff) > 0) {
foreach ($diff as $parameterName => $parameterAnnotations) {
throw InvalidParameterException::parameterNotFound($parameterName, get_class($parameterAnnotations[0]), $method);
}
}

foreach ($refParameters as $refParameter) {
$attributes = $refParameter->getAttributes();
$parameterAnnotationsPerParameter[$refParameter->getName()] = [...$parameterAnnotationsPerParameter[$refParameter->getName()] ??
Expand Down
5 changes: 0 additions & 5 deletions src/Annotations/Exceptions/InvalidParameterException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@

class InvalidParameterException extends BadMethodCallException
{
public static function parameterNotFound(string $parameter, string $annotationClass, ReflectionMethod $reflectionMethod): self
{
return new self(sprintf('Parameter "%s" declared in attribute "%s" of method "%s::%s()" does not exist.', $parameter, $annotationClass, $reflectionMethod->getDeclaringClass()->getName(), $reflectionMethod->getName()));
}

public static function parameterNotFoundFromSourceField(string $parameter, string $annotationClass, ReflectionMethod $reflectionMethod): self
{
return new self(sprintf('Could not find parameter "%s" declared in annotation "%s". This annotation is itself declared in a SourceField attribute targeting resolver "%s::%s()".', $parameter, $annotationClass, $reflectionMethod->getDeclaringClass()->getName(), $reflectionMethod->getName()));
Expand Down

0 comments on commit 190ad43

Please sign in to comment.