Skip to content

Commit

Permalink
Fix static analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincz committed Apr 2, 2024
1 parent dd4cca5 commit c45817f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
10 changes: 4 additions & 6 deletions src/Config/Parser/MetadataParser/MetadataParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,6 @@ private static function getTypeFieldConfigurationFromReflector(ReflectionClass $
$accessMetadata = self::getFirstMetadataMatching($metadatas, Metadata\Access::class);
$publicMetadata = self::getFirstMetadataMatching($metadatas, Metadata\IsPublic::class);

$isMethod = $reflector instanceof ReflectionMethod;

if (null === $fieldMetadata) {
if (null !== $accessMetadata || null !== $publicMetadata) {
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')));
Expand All @@ -576,7 +574,7 @@ private static function getTypeFieldConfigurationFromReflector(ReflectionClass $
return [];
}

if ($isMethod && !$reflector->isPublic()) {
if ($reflector instanceof ReflectionMethod && !$reflector->isPublic()) {
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()));
}

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

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

foreach ($argAnnotations as $arg) {
if ($isMethod && !in_array($arg->name, $validArgNames, true)) {
if ($reflector instanceof ReflectionMethod && !in_array($arg->name, $validArgNames, true)) {
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()));
}

Expand All @@ -615,7 +613,7 @@ private static function getTypeFieldConfigurationFromReflector(ReflectionClass $
}
}

if ($isMethod) {
if ($reflector instanceof ReflectionMethod) {
$args = self::guessArgs($reflectionClass, $reflector, $args);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ final class InvalidArgumentNaming
* @GQL\Field(name="guessFailed")
*
* @GQL\Arg(name="missingParameter", type="String")
*
* @param mixed $test
*/
#[GQL\Field(name: 'guessFailed')]
#[GQL\Arg(name: 'missingParameter', type: 'String')]
Expand Down

0 comments on commit c45817f

Please sign in to comment.