From fbb20d267a7fd832f0984a64c012a6a080e17a11 Mon Sep 17 00:00:00 2001 From: Jacob Thomason Date: Wed, 18 Dec 2024 07:50:08 -0500 Subject: [PATCH] PHP 8.4 Support (#722) * PHP 8.4 Support Add PHP 8.4 to list of CI runners and confirm PHP 8.4 support * Updated dependencies and resolved PHPStan errors * Downgrade symfony/var-dumper for PHP 8.1 support * Support phpunit 10.5 for PHP 8.1 * Corrected call for enum interface inconsistency * Resolved PHPCS errors --- .github/workflows/continuous_integration.yml | 2 +- composer.json | 17 +++++----- phpstan.neon | 7 ++-- src/Annotations/Security.php | 6 ---- src/Exceptions/GraphQLAggregateException.php | 8 ++++- src/FactoryContext.php | 2 +- src/FieldsBuilder.php | 12 +++---- src/Http/Psr15GraphQLMiddlewareBuilder.php | 1 + src/Http/WebonyxGraphqlMiddleware.php | 22 ++++--------- src/InputTypeUtils.php | 1 - src/Mappers/Parameters/TypeHandler.php | 23 ++++--------- .../Proxys/MutableInterfaceTypeAdapter.php | 17 ++-------- .../Proxys/MutableObjectTypeAdapter.php | 2 +- src/Mappers/RecursiveTypeMapper.php | 3 +- src/Mappers/Root/EnumTypeMapper.php | 10 +++--- src/Mappers/Root/IteratorTypeMapper.php | 2 +- .../StaticClassListTypeMapperFactory.php | 2 +- src/Middlewares/SecurityFieldMiddleware.php | 32 ++++++------------- .../SecurityInputFieldMiddleware.php | 3 -- src/Schema.php | 6 +--- src/Types/EnumType.php | 2 +- src/Types/ID.php | 3 +- src/Types/TypeAnnotatedObjectType.php | 1 - tests/Integration/EndToEndTest.php | 1 - 24 files changed, 64 insertions(+), 121 deletions(-) diff --git a/.github/workflows/continuous_integration.yml b/.github/workflows/continuous_integration.yml index f975c8b9af..e7d5c579ba 100644 --- a/.github/workflows/continuous_integration.yml +++ b/.github/workflows/continuous_integration.yml @@ -18,7 +18,7 @@ jobs: strategy: matrix: install-args: ['', '--prefer-lowest'] - php-version: ['8.1', '8.2', '8.3'] + php-version: ['8.1', '8.2', '8.3', '8.4'] fail-fast: false steps: diff --git a/composer.json b/composer.json index d4ef009482..33751a0af7 100644 --- a/composer.json +++ b/composer.json @@ -27,17 +27,16 @@ "kcs/class-finder": "^0.6.0" }, "require-dev": { - "beberlei/porpaginas": "^1.2 || ^2.0", - "doctrine/coding-standard": "^11.0 || ^12.0", + "beberlei/porpaginas": "^2.0", + "doctrine/coding-standard": "^12.0", "ecodev/graphql-upload": "^7.0", - "laminas/laminas-diactoros": "^2 || ^3", + "laminas/laminas-diactoros": "^3.5", "myclabs/php-enum": "^1.6.6", - "php-coveralls/php-coveralls": "^2.1", - "phpstan/extension-installer": "^1.1", - "phpstan/phpstan": "^1.11", - "phpunit/phpunit": "^10.1 || ^11.0", - "symfony/var-dumper": "^5.4 || ^6.0 || ^7", - "thecodingmachine/phpstan-strict-rules": "^1.0" + "php-coveralls/php-coveralls": "^2.7", + "phpstan/extension-installer": "^1.4", + "phpstan/phpstan": "^2.0", + "phpunit/phpunit": "^10.5 || ^11.0", + "symfony/var-dumper": "^6.4" }, "suggest": { "beberlei/porpaginas": "If you want automatic pagination in your GraphQL types", diff --git a/phpstan.neon b/phpstan.neon index 86c9770f50..11a355ed6b 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -4,12 +4,7 @@ parameters: tmpDir: .phpstan-cache paths: - src - excludePaths: - # TODO: exlude only for PHP < 8.1 - - src/Mappers/Root/EnumTypeMapper.php - - src/Types/EnumType.php level: 8 - checkGenericClassInNonGenericObjectType: false reportUnmatchedIgnoredErrors: false treatPhpDocTypesAsCertain: false ignoreErrors: @@ -42,3 +37,5 @@ parameters: - message: '#Call to an undefined method object::__toString\(\)#' path : src/Types/ID.php + - + identifier: missingType.generics diff --git a/src/Annotations/Security.php b/src/Annotations/Security.php index c41c396f60..6e334e3e45 100644 --- a/src/Annotations/Security.php +++ b/src/Annotations/Security.php @@ -6,13 +6,9 @@ use Attribute; use BadMethodCallException; -use TypeError; use function array_key_exists; -use function gettype; -use function is_array; use function is_string; -use function sprintf; #[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] class Security implements MiddlewareAnnotationInterface @@ -37,8 +33,6 @@ public function __construct(array|string $data = [], string|null $expression = n { if (is_string($data)) { $data = ['expression' => $data]; - } elseif (! is_array($data)) { - throw new TypeError(sprintf('"%s": Argument $data is expected to be a string or array, got "%s".', __METHOD__, gettype($data))); } $this->expression = $data['value'] ?? $data['expression'] ?? $expression; diff --git a/src/Exceptions/GraphQLAggregateException.php b/src/Exceptions/GraphQLAggregateException.php index d63ca3a0c3..5c7c1909b8 100644 --- a/src/Exceptions/GraphQLAggregateException.php +++ b/src/Exceptions/GraphQLAggregateException.php @@ -6,6 +6,7 @@ use Exception; use GraphQL\Error\ClientAware; +use RuntimeException; use Throwable; use function array_map; @@ -22,7 +23,7 @@ class GraphQLAggregateException extends Exception implements GraphQLAggregateExc /** @param (ClientAware&Throwable)[] $exceptions */ public function __construct(iterable $exceptions = []) { - parent::__construct('Many exceptions have be thrown:'); + parent::__construct('Many exceptions have been thrown:'); foreach ($exceptions as $exception) { $this->add($exception); @@ -56,6 +57,11 @@ private function updateCode(): void $codes = array_map(static function (Throwable $t) { return $t->getCode(); }, $this->exceptions); + + if (count($codes) === 0) { + throw new RuntimeException('Unable to determine code for exception'); + } + $this->code = max($codes); } diff --git a/src/FactoryContext.php b/src/FactoryContext.php index 0aaf40ac42..672d90ca99 100644 --- a/src/FactoryContext.php +++ b/src/FactoryContext.php @@ -103,7 +103,7 @@ public function getClassFinderComputedCache(): ClassFinderComputedCache return $this->classFinderComputedCache; } - public function getClassBoundCache(): ClassBoundCache|null + public function getClassBoundCache(): ClassBoundCache { return $this->classBoundCache; } diff --git a/src/FieldsBuilder.php b/src/FieldsBuilder.php index d8ab99cc6b..10b0c620ae 100644 --- a/src/FieldsBuilder.php +++ b/src/FieldsBuilder.php @@ -497,6 +497,7 @@ private function getFieldsByMethodAnnotations( $resolver = is_string($controller) ? new SourceMethodResolver($refMethod) + /** @phpstan-ignore argument.type */ : new ServiceResolver([$controller, $methodName]); $fieldDescriptor = new QueryFieldDescriptor( @@ -512,7 +513,7 @@ private function getFieldsByMethodAnnotations( ); $field = $this->fieldMiddleware->process($fieldDescriptor, new class implements FieldHandlerInterface { - public function handle(QueryFieldDescriptor $fieldDescriptor): FieldDefinition|null + public function handle(QueryFieldDescriptor $fieldDescriptor): FieldDefinition { return QueryField::fromFieldDescriptor($fieldDescriptor); } @@ -605,7 +606,7 @@ private function getFieldsByPropertyAnnotations( ); $field = $this->fieldMiddleware->process($fieldDescriptor, new class implements FieldHandlerInterface { - public function handle(QueryFieldDescriptor $fieldDescriptor): FieldDefinition|null + public function handle(QueryFieldDescriptor $fieldDescriptor): FieldDefinition { return QueryField::fromFieldDescriptor($fieldDescriptor); } @@ -744,7 +745,7 @@ private function getQueryFieldsFromSourceFields( ->withMiddlewareAnnotations($sourceField->getMiddlewareAnnotations()); $field = $this->fieldMiddleware->process($fieldDescriptor, new class implements FieldHandlerInterface { - public function handle(QueryFieldDescriptor $fieldDescriptor): FieldDefinition|null + public function handle(QueryFieldDescriptor $fieldDescriptor): FieldDefinition { return QueryField::fromFieldDescriptor($fieldDescriptor); } @@ -822,7 +823,6 @@ private function resolvePhpType( $context = $this->docBlockFactory->createContext($refClass); $phpdocType = $typeResolver->resolve($phpTypeStr, $context); - assert($phpdocType !== null); $fakeDocBlock = new DocBlock('', null, [new DocBlock\Tags\Return_($phpdocType)], $context); return $this->typeMapper->mapReturnType($refMethod, $fakeDocBlock); @@ -1080,7 +1080,7 @@ private function getInputFieldsByMethodAnnotations( ); $field = $this->inputFieldMiddleware->process($inputFieldDescriptor, new class implements InputFieldHandlerInterface { - public function handle(InputFieldDescriptor $inputFieldDescriptor): InputField|null + public function handle(InputFieldDescriptor $inputFieldDescriptor): InputField { return InputField::fromFieldDescriptor($inputFieldDescriptor); } @@ -1175,7 +1175,7 @@ private function getInputFieldsByPropertyAnnotations( ); $field = $this->inputFieldMiddleware->process($inputFieldDescriptor, new class implements InputFieldHandlerInterface { - public function handle(InputFieldDescriptor $inputFieldDescriptor): InputField|null + public function handle(InputFieldDescriptor $inputFieldDescriptor): InputField { return InputField::fromFieldDescriptor($inputFieldDescriptor); } diff --git a/src/Http/Psr15GraphQLMiddlewareBuilder.php b/src/Http/Psr15GraphQLMiddlewareBuilder.php index 76bb4d6de8..c36ee03633 100644 --- a/src/Http/Psr15GraphQLMiddlewareBuilder.php +++ b/src/Http/Psr15GraphQLMiddlewareBuilder.php @@ -51,6 +51,7 @@ public function __construct(Schema $schema) $this->config->setSchema($schema); $this->config->setDebugFlag(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS); $this->config->setErrorFormatter([WebonyxErrorHandler::class, 'errorFormatter']); + /** @phpstan-ignore argument.type */ $this->config->setErrorsHandler([WebonyxErrorHandler::class, 'errorHandler']); $this->config->setContext(new Context()); $this->config->setPersistedQueryLoader(new NotSupportedPersistedQueryLoader()); diff --git a/src/Http/WebonyxGraphqlMiddleware.php b/src/Http/WebonyxGraphqlMiddleware.php index ac49cc2939..0bd7fa095e 100644 --- a/src/Http/WebonyxGraphqlMiddleware.php +++ b/src/Http/WebonyxGraphqlMiddleware.php @@ -19,6 +19,7 @@ use TheCodingMachine\GraphQLite\Context\ResetableContextInterface; use function array_map; +use function count; use function explode; use function in_array; use function is_array; @@ -99,11 +100,7 @@ private function processResult(ExecutionResult|array|Promise $result): array }, $result); } - if ($result instanceof Promise) { - throw new RuntimeException('Only SyncPromiseAdapter is supported'); - } - - throw new RuntimeException('Unexpected response from StandardServer::executePsrRequest'); // @codeCoverageIgnore + throw new RuntimeException('Only SyncPromiseAdapter is supported'); } /** @param ExecutionResult|array|Promise $result */ @@ -118,19 +115,14 @@ private function decideHttpCode(ExecutionResult|array|Promise $result): int return $this->httpCodeDecider->decideHttpStatusCode($executionResult); }, $result); - return (int) max($codes); - } + if (count($codes) === 0) { + throw new RuntimeException('Unable to determine HTTP status code'); + } - // @codeCoverageIgnoreStart - // Code unreachable because exceptions will be triggered in processResult first. - // We keep it for defensive programming purpose - if ($result instanceof Promise) { - throw new RuntimeException('Only SyncPromiseAdapter is supported'); + return (int) max($codes); } - throw new RuntimeException('Unexpected response from StandardServer::executePsrRequest'); - - // @codeCoverageIgnoreEnd + throw new RuntimeException('Only SyncPromiseAdapter is supported'); } private function isGraphqlRequest(ServerRequestInterface $request): bool diff --git a/src/InputTypeUtils.php b/src/InputTypeUtils.php index 3e4ad37fbb..319fc7eebf 100644 --- a/src/InputTypeUtils.php +++ b/src/InputTypeUtils.php @@ -73,7 +73,6 @@ private function validateReturnType(ReflectionMethod $refMethod): Fqsen $typeResolver = new TypeResolver(); $phpdocType = $typeResolver->resolve($type); - assert($phpdocType !== null); $phpdocType = $this->resolveSelf($phpdocType, $refMethod->getDeclaringClass()); if (! $phpdocType instanceof Object_) { throw MissingTypeHintRuntimeException::invalidReturnType($refMethod); diff --git a/src/Mappers/Parameters/TypeHandler.php b/src/Mappers/Parameters/TypeHandler.php index b4b8d098ee..393368fa2e 100644 --- a/src/Mappers/Parameters/TypeHandler.php +++ b/src/Mappers/Parameters/TypeHandler.php @@ -53,7 +53,6 @@ use function explode; use function in_array; use function iterator_to_array; -use function method_exists; use function reset; use function trim; @@ -74,7 +73,10 @@ public function __construct( $this->phpDocumentorTypeResolver = new PhpDocumentorTypeResolver(); } - public function mapReturnType(ReflectionMethod $refMethod, DocBlock $docBlockObj): GraphQLType&OutputType + public function mapReturnType( + ReflectionMethod $refMethod, + DocBlock $docBlockObj, + ): GraphQLType&OutputType { $returnType = $refMethod->getReturnType(); if ($returnType !== null) { @@ -94,7 +96,7 @@ public function mapReturnType(ReflectionMethod $refMethod, DocBlock $docBlockObj $refMethod, $docBlockObj, ); - assert($type instanceof GraphQLType && $type instanceof OutputType); + assert(! $type instanceof InputType); } catch (CannotMapTypeExceptionInterface $e) { $e->addReturnInfo($refMethod); throw $e; @@ -318,21 +320,14 @@ public function mapInputProperty( } if ($isNullable === null) { - $isNullable = false; - // getType function on property reflection is available only since PHP 7.4 - if (method_exists($refProperty, 'getType')) { - $refType = $refProperty->getType(); - if ($refType !== null) { - $isNullable = $refType->allowsNull(); - } - } + $isNullable = $refProperty->getType()?->allowsNull() ?? false; } if ($inputTypeName) { $inputType = $this->typeResolver->mapNameToInputType($inputTypeName); } else { $inputType = $this->mapPropertyType($refProperty, $docBlock, true, $argumentName, $isNullable); - assert($inputType instanceof InputType && $inputType instanceof GraphQLType); + assert(! $inputType instanceof OutputType); } $hasDefault = $defaultValue !== null || $isNullable; @@ -452,8 +447,6 @@ private function reflectionTypeToPhpDocType(ReflectionType $type, ReflectionClas assert($type instanceof ReflectionNamedType || $type instanceof ReflectionUnionType); if ($type instanceof ReflectionNamedType) { $phpdocType = $this->phpDocumentorTypeResolver->resolve($type->getName()); - assert($phpdocType !== null); - $phpdocType = $this->resolveSelf($phpdocType, $reflectionClass); if ($type->allowsNull()) { @@ -467,8 +460,6 @@ private function reflectionTypeToPhpDocType(ReflectionType $type, ReflectionClas function ($namedType) use ($reflectionClass): Type { assert($namedType instanceof ReflectionNamedType); $phpdocType = $this->phpDocumentorTypeResolver->resolve($namedType->getName()); - assert($phpdocType !== null); - $phpdocType = $this->resolveSelf($phpdocType, $reflectionClass); if ($namedType->allowsNull()) { diff --git a/src/Mappers/Proxys/MutableInterfaceTypeAdapter.php b/src/Mappers/Proxys/MutableInterfaceTypeAdapter.php index 2f179ab4e1..ffa954aa91 100644 --- a/src/Mappers/Proxys/MutableInterfaceTypeAdapter.php +++ b/src/Mappers/Proxys/MutableInterfaceTypeAdapter.php @@ -3,22 +3,9 @@ namespace TheCodingMachine\GraphQLite\Mappers\Proxys; -use Exception; -use GraphQL\Error\InvariantViolation; -use GraphQL\Type\Definition\FieldDefinition; use GraphQL\Type\Definition\InterfaceType; -use GraphQL\Type\Definition\ObjectType; -use GraphQL\Type\Definition\ResolveInfo; -use GraphQL\Utils\Utils; -use RuntimeException; -use TheCodingMachine\GraphQLite\Types\MutableInterface; +use TheCodingMachine\GraphQLite\Mappers\Proxys\MutableAdapterTrait; use TheCodingMachine\GraphQLite\Types\MutableInterfaceType; -use TheCodingMachine\GraphQLite\Types\NoFieldsException; -use function call_user_func; -use function is_array; -use function is_callable; -use function is_string; -use function sprintf; /** * An adapter class (actually a proxy) that adds the "mutable" feature to any Webonyx ObjectType. @@ -27,7 +14,6 @@ */ final class MutableInterfaceTypeAdapter extends MutableInterfaceType { - /** @use MutableAdapterTrait */ use MutableAdapterTrait; public function __construct(InterfaceType $type, ?string $className = null) @@ -35,6 +21,7 @@ public function __construct(InterfaceType $type, ?string $className = null) $this->type = $type; $this->className = $className; $this->name = $type->name; + $this->description = $type->description; $this->config = $type->config; $this->astNode = $type->astNode; $this->extensionASTNodes = $type->extensionASTNodes; diff --git a/src/Mappers/Proxys/MutableObjectTypeAdapter.php b/src/Mappers/Proxys/MutableObjectTypeAdapter.php index b4256631a8..53ac3e4fc6 100644 --- a/src/Mappers/Proxys/MutableObjectTypeAdapter.php +++ b/src/Mappers/Proxys/MutableObjectTypeAdapter.php @@ -6,6 +6,7 @@ use GraphQL\Type\Definition\InterfaceType; use GraphQL\Type\Definition\ObjectType; use GraphQL\Type\Definition\ResolveInfo; +use TheCodingMachine\GraphQLite\Mappers\Proxys\MutableAdapterTrait; use TheCodingMachine\GraphQLite\Types\MutableObjectType; use function assert; @@ -16,7 +17,6 @@ */ final class MutableObjectTypeAdapter extends MutableObjectType { - /** @use MutableAdapterTrait */ use MutableAdapterTrait; public function __construct(ObjectType $type, ?string $className = null) diff --git a/src/Mappers/RecursiveTypeMapper.php b/src/Mappers/RecursiveTypeMapper.php index f55c341419..12f6d8af43 100644 --- a/src/Mappers/RecursiveTypeMapper.php +++ b/src/Mappers/RecursiveTypeMapper.php @@ -237,7 +237,6 @@ public function findInterfaces(string $className): array { $interfaces = []; - /** @var array> $implements */ $implements = class_implements($className); foreach ($implements as $interface) { if (! $this->typeMapper->canMapClassToType($interface)) { @@ -359,7 +358,7 @@ public function mapClassToInterfaceOrType(string $className, OutputType|null $su $supportedClasses = $this->getClassTree(); if ($objectType instanceof ObjectFromInterfaceType) { $this->interfaces[$cacheKey] = $objectType->getInterfaces()[0]; - } elseif ($objectType instanceof MutableObjectType && isset($supportedClasses[$closestClassName]) && ! empty($supportedClasses[$closestClassName]->getChildren())) { + } elseif (isset($supportedClasses[$closestClassName]) && ! empty($supportedClasses[$closestClassName]->getChildren())) { // Cast as an interface $this->interfaces[$cacheKey] = new InterfaceFromObjectType($this->namingStrategy->getInterfaceNameFromConcreteName($objectType->name), $objectType, $subType, $this); $this->typeRegistry->registerType($this->interfaces[$cacheKey]); diff --git a/src/Mappers/Root/EnumTypeMapper.php b/src/Mappers/Root/EnumTypeMapper.php index 64d4696b9c..87e575bb6c 100644 --- a/src/Mappers/Root/EnumTypeMapper.php +++ b/src/Mappers/Root/EnumTypeMapper.php @@ -17,6 +17,7 @@ use ReflectionMethod; use ReflectionProperty; use TheCodingMachine\GraphQLite\AnnotationReader; +use TheCodingMachine\GraphQLite\Annotations\Type as TypeAnnotation; use TheCodingMachine\GraphQLite\Discovery\Cache\ClassFinderComputedCache; use TheCodingMachine\GraphQLite\Discovery\ClassFinder; use TheCodingMachine\GraphQLite\Reflection\DocBlock\DocBlockFactory; @@ -119,10 +120,11 @@ private function mapByClassName(string $enumClass): EnumType|null $typeName = $typeAnnotation?->getName() ?? $reflectionEnum->getShortName(); // Expose values instead of names if specifically configured to and if enum is string-backed - $useValues = $typeAnnotation !== null && - $typeAnnotation->useEnumValues() && - $reflectionEnum->isBacked() && - (string) $reflectionEnum->getBackingType() === 'string'; + $useValues = $typeAnnotation !== null + && $typeAnnotation instanceof TypeAnnotation + && $typeAnnotation->useEnumValues() + && $reflectionEnum->isBacked() + && (string) $reflectionEnum->getBackingType() === 'string'; $enumDescription = $this->docBlockFactory ->create($reflectionEnum) diff --git a/src/Mappers/Root/IteratorTypeMapper.php b/src/Mappers/Root/IteratorTypeMapper.php index 8d9f9fb1da..767f0489f6 100644 --- a/src/Mappers/Root/IteratorTypeMapper.php +++ b/src/Mappers/Root/IteratorTypeMapper.php @@ -146,7 +146,7 @@ private function toGraphQLType(Compound $type, Closure $topToGraphQLType, bool $ // By convention, we trim the NonNull part of the "$subGraphQlType" if ($subGraphQlType instanceof NonNull) { $subGraphQlType = $subGraphQlType->getWrappedType(); - assert($subGraphQlType instanceof OutputType && $subGraphQlType instanceof GraphQLType); + assert($subGraphQlType instanceof OutputType); } } else { $subGraphQlType = null; diff --git a/src/Mappers/StaticClassListTypeMapperFactory.php b/src/Mappers/StaticClassListTypeMapperFactory.php index 09fca187ae..4e82017f20 100644 --- a/src/Mappers/StaticClassListTypeMapperFactory.php +++ b/src/Mappers/StaticClassListTypeMapperFactory.php @@ -16,7 +16,7 @@ final class StaticClassListTypeMapperFactory implements TypeMapperFactoryInterfa /** * StaticClassListTypeMapperFactory constructor. * - * @param array $classList The list of classes to be scanned. + * @param list $classList The list of classes to be scanned. */ public function __construct( private array $classList, diff --git a/src/Middlewares/SecurityFieldMiddleware.php b/src/Middlewares/SecurityFieldMiddleware.php index d9fabaa0c1..f9d744afa7 100644 --- a/src/Middlewares/SecurityFieldMiddleware.php +++ b/src/Middlewares/SecurityFieldMiddleware.php @@ -19,19 +19,23 @@ use function array_combine; use function array_keys; use function assert; -use function is_array; /** * A field middleware that reads "Security" Symfony annotations. */ class SecurityFieldMiddleware implements FieldMiddlewareInterface { - public function __construct(private readonly ExpressionLanguage $language, private readonly AuthenticationServiceInterface $authenticationService, private readonly AuthorizationServiceInterface $authorizationService/*, ?LoggerInterface $logger = null*/) - { - /*$this->logger = $logger;*/ + public function __construct( + private readonly ExpressionLanguage $language, + private readonly AuthenticationServiceInterface $authenticationService, + private readonly AuthorizationServiceInterface $authorizationService, + ) { } - public function process(QueryFieldDescriptor $queryFieldDescriptor, FieldHandlerInterface $fieldHandler): FieldDefinition|null + public function process( + QueryFieldDescriptor $queryFieldDescriptor, + FieldHandlerInterface $fieldHandler, + ): FieldDefinition|null { $annotations = $queryFieldDescriptor->getMiddlewareAnnotations(); /** @var Security[] $securityAnnotations */ @@ -116,24 +120,6 @@ private function getVariables(array $args, array $parameters, object|null $sourc $argsName = array_keys($parameters); $argsByName = array_combine($argsName, $args); - assert(is_array($argsByName)); - - /*if ($diff = array_intersect(array_keys($variables), array_keys($argsName))) { - foreach ($diff as $key => $variableName) { - if ($variables[$variableName] !== $argsByName[$variableName]) { - continue; - } - - unset($diff[$key]); - } - - if ($diff) { - $singular = count($diff) === 1; - if ($this->logger !== null) { - $this->logger->warning(sprintf('Controller argument%s "%s" collided with the built-in security expression variables. The built-in value%s are being used for the @Security expression.', $singular ? '' : 's', implode('", "', $diff), $singular ? 's' : '')); - } - } - }*/ return $variables + $argsByName; } diff --git a/src/Middlewares/SecurityInputFieldMiddleware.php b/src/Middlewares/SecurityInputFieldMiddleware.php index 9eaba0b626..c2e77c207b 100644 --- a/src/Middlewares/SecurityInputFieldMiddleware.php +++ b/src/Middlewares/SecurityInputFieldMiddleware.php @@ -15,8 +15,6 @@ use function array_combine; use function array_keys; -use function assert; -use function is_array; /** * A field input middleware that reads "Security" Symfony annotations. @@ -85,7 +83,6 @@ private function getVariables(array $args, array $parameters, object|null $sourc $argsName = array_keys($parameters); $argsByName = array_combine($argsName, $args); - assert(is_array($argsByName)); return $variables + $argsByName; } diff --git a/src/Schema.php b/src/Schema.php index 2e53d3c1c7..f90c7fbbff 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -11,8 +11,6 @@ use TheCodingMachine\GraphQLite\Mappers\Root\RootTypeMapperInterface; use TheCodingMachine\GraphQLite\Types\TypeResolver; -use function assert; - /** * A GraphQL schema that takes into constructor argument a QueryProvider. * @@ -112,9 +110,7 @@ public function __construct( return $subscription; } - $type = $rootTypeMapper->mapNameToType($name); - assert($type instanceof Type); - return $type; + return $rootTypeMapper->mapNameToType($name); }); $typeResolver->registerSchema($this); diff --git a/src/Types/EnumType.php b/src/Types/EnumType.php index 9e48f98d22..25ff52af43 100644 --- a/src/Types/EnumType.php +++ b/src/Types/EnumType.php @@ -19,7 +19,7 @@ class EnumType extends BaseEnumType { /** * @param class-string $enumName - * @param array $caseDescriptions + * @param array $caseDescriptions * @param array $caseDeprecationReasons */ public function __construct( diff --git a/src/Types/ID.php b/src/Types/ID.php index 950214a4ed..64cf0599c4 100644 --- a/src/Types/ID.php +++ b/src/Types/ID.php @@ -7,7 +7,6 @@ use InvalidArgumentException; use function is_bool; -use function is_object; use function is_scalar; use function method_exists; @@ -21,7 +20,7 @@ class ID */ public function __construct(private readonly bool|float|int|string|object $value) { - if (! is_scalar($value) && (! is_object($value) || ! method_exists($value, '__toString'))) { + if (! is_scalar($value) && ! method_exists($value, '__toString')) { throw new InvalidArgumentException('ID constructor cannot be passed a non scalar value.'); } } diff --git a/src/Types/TypeAnnotatedObjectType.php b/src/Types/TypeAnnotatedObjectType.php index 9954c4daef..0fcf296432 100644 --- a/src/Types/TypeAnnotatedObjectType.php +++ b/src/Types/TypeAnnotatedObjectType.php @@ -61,7 +61,6 @@ public static function createFromAnnotatedClass(string $typeName, string $classN // FIXME: add an interface with a @Type that is implemented by noone. // Check that it does not trigger an exception. - /** @var array> $interfaces */ $interfaces = class_implements($className); foreach ($interfaces as $interface) { if (! $recursiveTypeMapper->canMapClassToType($interface)) { diff --git a/tests/Integration/EndToEndTest.php b/tests/Integration/EndToEndTest.php index 24a055dd1a..2423be089d 100644 --- a/tests/Integration/EndToEndTest.php +++ b/tests/Integration/EndToEndTest.php @@ -29,7 +29,6 @@ use TheCodingMachine\GraphQLite\Loggers\ExceptionLogger; use TheCodingMachine\GraphQLite\Mappers\CannotMapTypeException; use TheCodingMachine\GraphQLite\Middlewares\MissingAuthorizationException; -use TheCodingMachine\GraphQLite\Middlewares\PrefetchFieldMiddleware; use TheCodingMachine\GraphQLite\Schema; use TheCodingMachine\GraphQLite\SchemaFactory; use TheCodingMachine\GraphQLite\Security\AuthenticationServiceInterface;