Skip to content

Commit c45817f

Browse files
committed
Fix static analysis
1 parent dd4cca5 commit c45817f

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

src/Config/Parser/MetadataParser/MetadataParser.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -566,8 +566,6 @@ private static function getTypeFieldConfigurationFromReflector(ReflectionClass $
566566
$accessMetadata = self::getFirstMetadataMatching($metadatas, Metadata\Access::class);
567567
$publicMetadata = self::getFirstMetadataMatching($metadatas, Metadata\IsPublic::class);
568568

569-
$isMethod = $reflector instanceof ReflectionMethod;
570-
571569
if (null === $fieldMetadata) {
572570
if (null !== $accessMetadata || null !== $publicMetadata) {
573571
throw new InvalidArgumentException(sprintf('The metadatas %s and/or %s defined on "%s" are only usable in addition of metadata %s', self::formatMetadata('Access'), self::formatMetadata('Visible'), $reflector->getName(), self::formatMetadata('Field')));
@@ -576,7 +574,7 @@ private static function getTypeFieldConfigurationFromReflector(ReflectionClass $
576574
return [];
577575
}
578576

579-
if ($isMethod && !$reflector->isPublic()) {
577+
if ($reflector instanceof ReflectionMethod && !$reflector->isPublic()) {
580578
throw new InvalidArgumentException(sprintf('The metadata %s can only be applied to public method. The method "%s" is not public.', self::formatMetadata('Field'), $reflector->getName()));
581579
}
582580

@@ -594,10 +592,10 @@ private static function getTypeFieldConfigurationFromReflector(ReflectionClass $
594592
/** @var Metadata\Arg[] $argAnnotations */
595593
$argAnnotations = self::getMetadataMatching($metadatas, Metadata\Arg::class);
596594

597-
$validArgNames = array_map(fn (ReflectionParameter $parameter) => $parameter->getName(), $isMethod ? $reflector->getParameters() : []);
595+
$validArgNames = array_map(fn (ReflectionParameter $parameter) => $parameter->getName(), $reflector instanceof ReflectionMethod ? $reflector->getParameters() : []);
598596

599597
foreach ($argAnnotations as $arg) {
600-
if ($isMethod && !in_array($arg->name, $validArgNames, true)) {
598+
if ($reflector instanceof ReflectionMethod && !in_array($arg->name, $validArgNames, true)) {
601599
throw new InvalidArgumentException(sprintf('The argument "%s" defined with #[GQL\Arg] attribute/annotation on method "%s" does not match any parameter name in the method.', $arg->name, $reflector->getName()));
602600
}
603601

@@ -615,7 +613,7 @@ private static function getTypeFieldConfigurationFromReflector(ReflectionClass $
615613
}
616614
}
617615

618-
if ($isMethod) {
616+
if ($reflector instanceof ReflectionMethod) {
619617
$args = self::guessArgs($reflectionClass, $reflector, $args);
620618
}
621619

tests/Config/Parser/fixtures/annotations/Invalid/InvalidArgumentNaming.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ final class InvalidArgumentNaming
1616
* @GQL\Field(name="guessFailed")
1717
*
1818
* @GQL\Arg(name="missingParameter", type="String")
19-
*
20-
* @param mixed $test
2119
*/
2220
#[GQL\Field(name: 'guessFailed')]
2321
#[GQL\Arg(name: 'missingParameter', type: 'String')]

0 commit comments

Comments
 (0)