From a5a9a1c7f851071f080ee5d0f542cb8abf56f1c7 Mon Sep 17 00:00:00 2001 From: bladl Date: Fri, 21 Oct 2022 16:49:14 +0300 Subject: [PATCH 01/11] psr/container v2 --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index cf01bcdfa0..aeeb57ed84 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "composer/package-versions-deprecated": "^1.8", "phpdocumentor/reflection-docblock": "^4.3 || ^5.0", "phpdocumentor/type-resolver": "^1.4", - "psr/container": "^1", + "psr/container": "^1 || ^2", "psr/http-factory": "^1", "psr/http-message": "^1.0.1", "psr/http-server-handler": "^1", @@ -33,7 +33,6 @@ "doctrine/coding-standard": "^9.0 || ^10.0", "ecodev/graphql-upload": "^6.1", "laminas/laminas-diactoros": "^2", - "mouf/picotainer": "^1.1", "myclabs/php-enum": "^1.6.6", "php-coveralls/php-coveralls": "^2.1", "phpstan/extension-installer": "^1.1", From d33dc1a077a4b207524fbcd42ccfec98f2ddc404 Mon Sep 17 00:00:00 2001 From: bladl Date: Fri, 21 Oct 2022 17:18:38 +0300 Subject: [PATCH 02/11] Implement replacement for Picotainer --- src/Containers/LazyContainer.php | 58 ++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/Containers/LazyContainer.php diff --git a/src/Containers/LazyContainer.php b/src/Containers/LazyContainer.php new file mode 100644 index 0000000000..7bbbfccf07 --- /dev/null +++ b/src/Containers/LazyContainer.php @@ -0,0 +1,58 @@ + + */ + protected array $callbacks; + + /** + * The array of entries once they have been instantiated. + * + * @var array + */ + protected array $objects; + private ContainerInterface $delegateLookupContainer; + + /** + * Instantiate the container. + * + * @param array $entries The array of closures defining each entry of the container. Entries must be passed as an array of anonymous functions. + * @param ContainerInterface|null $delegateLookupContainer Optional delegate lookup container. + */ + public function __construct(private array $entries, ContainerInterface|null $delegateLookupContainer = null) + { + $this->delegateLookupContainer = $delegateLookupContainer ?: $this; + } + + public function get(string $id): mixed + { + if (isset($this->objects[$id])) { + return $this->objects[$id]; + } + if (! isset($this->entries[$id])) { + throw throw NotFoundException::notFoundInContainer($id); + } + + return $this->objects[$id] = $this->callbacks[$id]($this->delegateLookupContainer); + } + + public function has(string $id): bool + { + return isset($this->entries[$id]) || isset($this->objects[$id]); + } +} From 6109c7dc7947f332044d0d26aeec21e048541dd2 Mon Sep 17 00:00:00 2001 From: bladl Date: Fri, 21 Oct 2022 17:27:06 +0300 Subject: [PATCH 03/11] Replace Picotainer with LazyContainer in tests and documentation for version >=6 --- tests/AbstractQueryProviderTest.php | 4 +- tests/Integration/EndToEndTest.php | 10 ++--- tests/Mappers/GlobTypeMapperTest.php | 41 ++++++++----------- tests/Mappers/RecursiveTypeMapperTest.php | 3 +- tests/TypeGeneratorTest.php | 7 ++-- .../version-6.0/other-frameworks.mdx | 11 +++-- .../version-6.1/other-frameworks.mdx | 10 ++--- 7 files changed, 38 insertions(+), 48 deletions(-) diff --git a/tests/AbstractQueryProviderTest.php b/tests/AbstractQueryProviderTest.php index 1cc51f130e..9d69dbf545 100644 --- a/tests/AbstractQueryProviderTest.php +++ b/tests/AbstractQueryProviderTest.php @@ -8,7 +8,6 @@ use GraphQL\Type\Definition\ObjectType; use GraphQL\Type\Definition\OutputType; use GraphQL\Type\Definition\Type; -use Mouf\Picotainer\Picotainer; use phpDocumentor\Reflection\TypeResolver as PhpDocumentorTypeResolver; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; @@ -16,6 +15,7 @@ use Symfony\Component\Cache\Adapter\Psr16Adapter; use Symfony\Component\Cache\Psr16Cache; use Symfony\Component\ExpressionLanguage\ExpressionLanguage; +use TheCodingMachine\GraphQLite\Containers\LazyContainer; use TheCodingMachine\GraphQLite\Fixtures\Mocks\MockResolvableInputObjectType; use TheCodingMachine\GraphQLite\Fixtures\TestObject; use TheCodingMachine\GraphQLite\Fixtures\TestObject2; @@ -243,7 +243,7 @@ protected function getArgumentResolver(): ArgumentResolver protected function getRegistry() { if ($this->registry === null) { - $this->registry = $this->buildAutoWiringContainer(new Picotainer([])); + $this->registry = $this->buildAutoWiringContainer(new LazyContainer([])); } return $this->registry; } diff --git a/tests/Integration/EndToEndTest.php b/tests/Integration/EndToEndTest.php index b541d3828d..c5756cc58b 100644 --- a/tests/Integration/EndToEndTest.php +++ b/tests/Integration/EndToEndTest.php @@ -6,7 +6,6 @@ use GraphQL\Error\DebugFlag; use GraphQL\Executor\ExecutionResult; use GraphQL\GraphQL; -use Mouf\Picotainer\Picotainer; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; use stdClass; @@ -16,6 +15,7 @@ use Symfony\Component\ExpressionLanguage\ExpressionLanguage; use TheCodingMachine\GraphQLite\AggregateQueryProvider; use TheCodingMachine\GraphQLite\AnnotationReader; +use TheCodingMachine\GraphQLite\Containers\LazyContainer; use TheCodingMachine\GraphQLite\Context\Context; use TheCodingMachine\GraphQLite\FieldsBuilder; use TheCodingMachine\GraphQLite\GlobControllerQueryProvider; @@ -80,10 +80,8 @@ class EndToEndTest extends TestCase { - /** - * @var ContainerInterface - */ - private $mainContainer; + + private ContainerInterface $mainContainer; public function setUp(): void { @@ -344,7 +342,7 @@ public function createContainer(array $overloadedServices = []): ContainerInterf }; } - $container = new Picotainer($overloadedServices + $services); + $container = new LazyContainer($overloadedServices + $services); $container->get(TypeResolver::class)->registerSchema($container->get(Schema::class)); $container->get(TypeMapperInterface::class)->addTypeMapper($container->get(GlobTypeMapper::class)); $container->get(TypeMapperInterface::class)->addTypeMapper($container->get(GlobTypeMapper::class.'2')); diff --git a/tests/Mappers/GlobTypeMapperTest.php b/tests/Mappers/GlobTypeMapperTest.php index b9fd62b3d7..937f71004e 100644 --- a/tests/Mappers/GlobTypeMapperTest.php +++ b/tests/Mappers/GlobTypeMapperTest.php @@ -4,15 +4,12 @@ use Doctrine\Common\Annotations\AnnotationReader; use GraphQL\Type\Definition\Type; -use Mouf\Picotainer\Picotainer; use Symfony\Component\Cache\Adapter\ArrayAdapter; use Symfony\Component\Cache\Adapter\NullAdapter; use Symfony\Component\Cache\Psr16Cache; -use Symfony\Component\Cache\Simple\ArrayCache; -use Symfony\Component\Cache\Simple\NullCache; -use Test; use TheCodingMachine\GraphQLite\AbstractQueryProviderTest; use TheCodingMachine\GraphQLite\Annotations\Exceptions\ClassNotFoundException; +use TheCodingMachine\GraphQLite\Containers\LazyContainer; use TheCodingMachine\GraphQLite\FailedResolvingInputType; use TheCodingMachine\GraphQLite\Fixtures\BadExtendType\BadExtendType; use TheCodingMachine\GraphQLite\Fixtures\BadExtendType2\BadExtendType2; @@ -26,20 +23,16 @@ use TheCodingMachine\GraphQLite\Fixtures\Types\FooExtendType; use TheCodingMachine\GraphQLite\Fixtures\Types\FooType; use TheCodingMachine\GraphQLite\Fixtures\Types\TestFactory; -use TheCodingMachine\GraphQLite\Fixtures\Types\TestFactoryNoType; use TheCodingMachine\GraphQLite\GraphQLRuntimeException; use TheCodingMachine\GraphQLite\NamingStrategy; -use TheCodingMachine\GraphQLite\TypeGenerator; use GraphQL\Type\Definition\ObjectType; use TheCodingMachine\GraphQLite\Types\MutableObjectType; -use TheCodingMachine\GraphQLite\Types\ResolvableMutableInputObjectType; -use function array_keys; class GlobTypeMapperTest extends AbstractQueryProviderTest { public function testGlobTypeMapper(): void { - $container = new Picotainer([ + $container = new LazyContainer([ FooType::class => function () { return new FooType(); } @@ -70,7 +63,7 @@ public function testGlobTypeMapper(): void public function testGlobTypeMapperDuplicateTypesException(): void { - $container = new Picotainer([ + $container = new LazyContainer([ TestType::class => function () { return new TestType(); } @@ -86,7 +79,7 @@ public function testGlobTypeMapperDuplicateTypesException(): void public function testGlobTypeMapperDuplicateInputsException(): void { - $container = new Picotainer([ + $container = new LazyContainer([ TestInput::class => function () { return new TestInput(); } @@ -102,7 +95,7 @@ public function testGlobTypeMapperDuplicateInputsException(): void public function testGlobTypeMapperDuplicateInputTypesException(): void { - $container = new Picotainer([ + $container = new LazyContainer([ /*TestType::class => function() { return new TestType(); }*/ @@ -129,7 +122,7 @@ public function testGlobTypeMapperDuplicateInputTypesException(): void public function testGlobTypeMapperInheritedInputTypesException(): void { - $container = new Picotainer([ + $container = new LazyContainer([ ChildTestFactory::class => function() { return new ChildTestFactory(); } @@ -147,7 +140,7 @@ public function testGlobTypeMapperInheritedInputTypesException(): void public function testGlobTypeMapperClassNotFoundException(): void { - $container = new Picotainer([ + $container = new LazyContainer([ TestType::class => function () { return new TestType(); } @@ -164,7 +157,7 @@ public function testGlobTypeMapperClassNotFoundException(): void public function testGlobTypeMapperNameNotFoundException(): void { - $container = new Picotainer([ + $container = new LazyContainer([ FooType::class => function () { return new FooType(); } @@ -180,7 +173,7 @@ public function testGlobTypeMapperNameNotFoundException(): void public function testGlobTypeMapperInputType(): void { - $container = new Picotainer([ + $container = new LazyContainer([ FooType::class => function () { return new FooType(); }, @@ -214,7 +207,7 @@ public function testGlobTypeMapperInputType(): void public function testGlobTypeMapperExtend(): void { - $container = new Picotainer([ + $container = new LazyContainer([ FooType::class => function () { return new FooType(); }, @@ -249,7 +242,7 @@ public function testGlobTypeMapperExtend(): void public function testEmptyGlobTypeMapper(): void { - $container = new Picotainer([]); + $container = new LazyContainer([]); $typeGenerator = $this->getTypeGenerator(); $inputTypeGenerator = $this->getInputTypeGenerator(); @@ -263,7 +256,7 @@ public function testEmptyGlobTypeMapper(): void public function testGlobTypeMapperDecorate(): void { - $container = new Picotainer([ + $container = new LazyContainer([ FilterDecorator::class => function () { return new FilterDecorator(); } @@ -289,7 +282,7 @@ public function testGlobTypeMapperDecorate(): void public function testInvalidName(): void { - $container = new Picotainer([ + $container = new LazyContainer([ FooType::class => function () { return new FooType(); } @@ -306,7 +299,7 @@ public function testInvalidName(): void public function testGlobTypeMapperExtendBadName(): void { - $container = new Picotainer([ + $container = new LazyContainer([ FooType::class => function () { return new FooType(); }, @@ -339,7 +332,7 @@ public function testGlobTypeMapperExtendBadName(): void public function testGlobTypeMapperExtendBadClass(): void { - $container = new Picotainer([ + $container = new LazyContainer([ FooType::class => function () { return new FooType(); }, @@ -372,7 +365,7 @@ public function testGlobTypeMapperExtendBadClass(): void public function testNonInstantiableType(): void { - $container = new Picotainer([ + $container = new LazyContainer([ FooType::class => function () { return new FooType(); } @@ -392,7 +385,7 @@ public function testNonInstantiableType(): void public function testNonInstantiableInput(): void { - $container = new Picotainer([]); + $container = new LazyContainer([]); $typeGenerator = $this->getTypeGenerator(); $inputTypeGenerator = $this->getInputTypeGenerator(); diff --git a/tests/Mappers/RecursiveTypeMapperTest.php b/tests/Mappers/RecursiveTypeMapperTest.php index 90a02765b4..4d1af1acc7 100644 --- a/tests/Mappers/RecursiveTypeMapperTest.php +++ b/tests/Mappers/RecursiveTypeMapperTest.php @@ -13,6 +13,7 @@ use Symfony\Component\Cache\Simple\ArrayCache; use Symfony\Component\Cache\Simple\NullCache; use TheCodingMachine\GraphQLite\AbstractQueryProviderTest; +use TheCodingMachine\GraphQLite\Containers\LazyContainer; use TheCodingMachine\GraphQLite\Fixtures\Integration\Models\Filter; use TheCodingMachine\GraphQLite\Fixtures\Interfaces\ClassA; use TheCodingMachine\GraphQLite\Fixtures\Interfaces\ClassB; @@ -125,7 +126,7 @@ public function testMapClassToInputType(): void protected function getTypeMapper() { if ($this->typeMapper === null) { - $container = new Picotainer([ + $container = new LazyContainer([ ClassAType::class => function () { return new ClassAType(); }, diff --git a/tests/TypeGeneratorTest.php b/tests/TypeGeneratorTest.php index b5580e177e..9f4077bda5 100644 --- a/tests/TypeGeneratorTest.php +++ b/tests/TypeGeneratorTest.php @@ -2,18 +2,19 @@ namespace TheCodingMachine\GraphQLite; -use Mouf\Picotainer\Picotainer; +use Psr\Container\ContainerInterface; use stdClass; +use TheCodingMachine\GraphQLite\Containers\LazyContainer; use TheCodingMachine\GraphQLite\Fixtures\TypeFoo; use TheCodingMachine\GraphQLite\Types\MutableObjectType; class TypeGeneratorTest extends AbstractQueryProviderTest { - private $container; + private ContainerInterface$container; public function setUp(): void { - $this->container = new Picotainer([ + $this->container = new LazyContainer([ TypeFoo::class => function() { return new TypeFoo(); }, stdClass::class => function() { return new stdClass(); } ]); diff --git a/website/versioned_docs/version-6.0/other-frameworks.mdx b/website/versioned_docs/version-6.0/other-frameworks.mdx index 0685d4f83a..b1e5930706 100644 --- a/website/versioned_docs/version-6.0/other-frameworks.mdx +++ b/website/versioned_docs/version-6.0/other-frameworks.mdx @@ -171,7 +171,6 @@ $builder->setHttpCodeDecider(new HttpCodeDecider()); // Set a class in charge of In this example, we will focus on getting a working version of GraphQLite using: - [Zend Stratigility](https://docs.zendframework.com/zend-stratigility/) as a PSR-15 server -- `mouf/picotainer` (a micro-container) for the PSR-11 container - `symfony/cache ` for the PSR-16 cache The choice of the libraries is really up to you. You can adapt it based on your needs. @@ -188,7 +187,6 @@ The choice of the libraries is really up to you. You can adapt it based on your "zendframework/zend-diactoros": "^2", "zendframework/zend-stratigility": "^3", "zendframework/zend-httphandlerrunner": "^1.0", - "mouf/picotainer": "^1.1", "symfony/cache": "^4.2" }, "minimum-stability": "dev", @@ -235,16 +233,17 @@ This `MiddlewarePipe` comes from the container declared in the `config/container function(ContainerInterface $container) { $pipe = new MiddlewarePipe(); $pipe->pipe($container->get(WebonyxGraphqlMiddleware::class)); @@ -325,7 +324,7 @@ class MyController ```php title="config/container.php" use App\Controllers\MyController; -return new Picotainer([ +return new LazyContainer([ // ... // We declare the controller in the container. diff --git a/website/versioned_docs/version-6.1/other-frameworks.mdx b/website/versioned_docs/version-6.1/other-frameworks.mdx index 84873fca28..a79d5585bc 100644 --- a/website/versioned_docs/version-6.1/other-frameworks.mdx +++ b/website/versioned_docs/version-6.1/other-frameworks.mdx @@ -171,7 +171,6 @@ $builder->setHttpCodeDecider(new HttpCodeDecider()); // Set a class in charge of In this example, we will focus on getting a working version of GraphQLite using: - [Zend Stratigility](https://docs.zendframework.com/zend-stratigility/) as a PSR-15 server -- `mouf/picotainer` (a micro-container) for the PSR-11 container - `symfony/cache ` for the PSR-16 cache The choice of the libraries is really up to you. You can adapt it based on your needs. @@ -188,7 +187,6 @@ The choice of the libraries is really up to you. You can adapt it based on your "zendframework/zend-diactoros": "^2", "zendframework/zend-stratigility": "^3", "zendframework/zend-httphandlerrunner": "^1.0", - "mouf/picotainer": "^1.1", "symfony/cache": "^4.2" }, "minimum-stability": "dev", @@ -235,7 +233,7 @@ This `MiddlewarePipe` comes from the container declared in the `config/container function(ContainerInterface $container) { $pipe = new MiddlewarePipe(); $pipe->pipe($container->get(WebonyxGraphqlMiddleware::class)); @@ -294,7 +292,7 @@ class MyController ```php title="config/container.php" use App\Controllers\MyController; -return new Picotainer([ +return new LazyContainer([ // ... // We declare the controller in the container. From 5c78848ef9bed257116ee1a88c5d714eb0ed6cda Mon Sep 17 00:00:00 2001 From: bladl Date: Fri, 21 Oct 2022 17:35:42 +0300 Subject: [PATCH 04/11] Fix tests for phpdocumentor/type-resolver minor update --- src/Containers/LazyContainer.php | 9 +----- tests/AbstractQueryProviderTest.php | 28 +++++++++---------- tests/Mappers/Root/BaseTypeMapperTest.php | 2 +- tests/Mappers/Root/IteratorTypeMapperTest.php | 2 +- 4 files changed, 16 insertions(+), 25 deletions(-) diff --git a/src/Containers/LazyContainer.php b/src/Containers/LazyContainer.php index 7bbbfccf07..01218097f7 100644 --- a/src/Containers/LazyContainer.php +++ b/src/Containers/LazyContainer.php @@ -13,13 +13,6 @@ */ class LazyContainer implements ContainerInterface { - /** - * The array of closures defining each entry of the container. - * - * @var array - */ - protected array $callbacks; - /** * The array of entries once they have been instantiated. * @@ -48,7 +41,7 @@ public function get(string $id): mixed throw throw NotFoundException::notFoundInContainer($id); } - return $this->objects[$id] = $this->callbacks[$id]($this->delegateLookupContainer); + return $this->objects[$id] = $this->entries[$id]($this->delegateLookupContainer); } public function has(string $id): bool diff --git a/tests/AbstractQueryProviderTest.php b/tests/AbstractQueryProviderTest.php index 9d69dbf545..2970f7cf6a 100644 --- a/tests/AbstractQueryProviderTest.php +++ b/tests/AbstractQueryProviderTest.php @@ -147,20 +147,22 @@ public function mapClassToType(string $className, ?OutputType $subType): Mutable { if ($className === TestObject::class) { return $this->testObjectType; - } elseif ($className === TestObject2::class) { + } + + if ($className === TestObject2::class) { return $this->testObjectType2; - } else { - throw CannotMapTypeException::createForType($className); } + + throw CannotMapTypeException::createForType($className); } public function mapClassToInputType(string $className): ResolvableMutableInputInterface { if ($className === TestObject::class) { return $this->inputTestObjectType; - } else { - throw CannotMapTypeException::createForInputType($className); } + + throw CannotMapTypeException::createForInputType($className); } public function canMapClassToType(string $className): bool @@ -180,16 +182,12 @@ public function getSupportedClasses(): array public function mapNameToType(string $typeName): Type { - switch ($typeName) { - case 'TestObject': - return $this->testObjectType; - case 'TestObject2': - return $this->testObjectType2; - case 'TestObjectInput': - return $this->inputTestObjectType; - default: - throw CannotMapTypeException::createForName($typeName); - } + return match ($typeName) { + 'TestObject' => $this->testObjectType, + 'TestObject2' => $this->testObjectType2, + 'TestObjectInput' => $this->inputTestObjectType, + default => throw CannotMapTypeException::createForName($typeName), + }; } public function canMapNameToType(string $typeName): bool diff --git a/tests/Mappers/Root/BaseTypeMapperTest.php b/tests/Mappers/Root/BaseTypeMapperTest.php index 11b9eb9bef..947fe76d86 100644 --- a/tests/Mappers/Root/BaseTypeMapperTest.php +++ b/tests/Mappers/Root/BaseTypeMapperTest.php @@ -83,7 +83,7 @@ public function testOutputGenericIterables(string $phpdocType, string $expectedI public function genericIterablesProvider(): iterable { - yield '\ArrayIterator with nullable int item' => ['\ArrayIterator', IntType::class]; + yield '\ArrayIterator with nullable int item' => ['\ArrayIterator', IntType::class]; yield '\ArrayIterator with int item' => ['\ArrayIterator', NonNull::class, IntType::class]; // key information cannot be presented in GQL types for now diff --git a/tests/Mappers/Root/IteratorTypeMapperTest.php b/tests/Mappers/Root/IteratorTypeMapperTest.php index 88ad950acb..a3da01b008 100644 --- a/tests/Mappers/Root/IteratorTypeMapperTest.php +++ b/tests/Mappers/Root/IteratorTypeMapperTest.php @@ -27,7 +27,7 @@ public function testOutputNullableValueIterator(): void { $typeMapper = $this->getRootTypeMapper(); - $result = $typeMapper->toGraphQLOutputType($this->resolveType('ArrayObject|array'), null, new ReflectionMethod(__CLASS__, 'testInputIterator'), new DocBlock()); + $result = $typeMapper->toGraphQLOutputType($this->resolveType('ArrayObject|array'), null, new ReflectionMethod(__CLASS__, 'testInputIterator'), new DocBlock()); $this->assertInstanceOf(NonNull::class, $result); $this->assertInstanceOf(ListOfType::class, $result->getWrappedType()); $this->assertInstanceOf(IntType::class, $result->getWrappedType()->getWrappedType()); From f67c09c99e0da84432ee1d04c56aba6dca7924f4 Mon Sep 17 00:00:00 2001 From: bladl Date: Fri, 21 Oct 2022 17:40:09 +0300 Subject: [PATCH 05/11] run cs-fix script --- src/AggregateControllerQueryProvider.php | 8 +-- src/AggregateQueryProvider.php | 12 +--- src/AnnotationReader.php | 43 ++++++-------- src/Annotations/AbstractRequest.php | 14 ++--- src/Annotations/Autowire.php | 6 +- src/Annotations/EnumType.php | 8 +-- src/Annotations/ExtendType.php | 10 ++-- src/Annotations/Factory.php | 8 +-- src/Annotations/FailWith.php | 4 +- src/Annotations/Field.php | 14 ++--- src/Annotations/HideParameter.php | 4 +- src/Annotations/InjectUser.php | 4 +- src/Annotations/Input.php | 26 ++++----- src/Annotations/MagicField.php | 18 +++--- src/Annotations/MiddlewareAnnotations.php | 6 +- src/Annotations/ParameterAnnotations.php | 10 +--- src/Annotations/Security.php | 2 +- src/Annotations/SourceField.php | 26 ++++----- src/Annotations/SourceFieldInterface.php | 12 ++-- src/Annotations/Type.php | 12 ++-- src/Annotations/TypeInterface.php | 6 +- src/Containers/BasicAutoWiringContainer.php | 4 +- src/Exceptions/GraphQLAggregateException.php | 12 +--- .../GraphQLAggregateExceptionInterface.php | 4 +- src/Exceptions/GraphQLException.php | 6 +- src/Exceptions/WebonyxErrorHandler.php | 4 +- src/FactoryContext.php | 12 ++-- src/FieldNotFoundException.php | 4 +- src/FieldsBuilder.php | 42 +++++++------- src/GlobControllerQueryProvider.php | 26 +++------ src/Http/Psr15GraphQLMiddlewareBuilder.php | 4 +- src/Http/WebonyxGraphqlMiddleware.php | 10 +--- src/InputField.php | 4 +- src/InputFieldDescriptor.php | 30 ++++------ src/InputTypeGenerator.php | 14 ++--- src/InputTypeUtils.php | 6 +- src/Mappers/AbstractTypeMapper.php | 10 ++-- src/Mappers/CannotMapTypeException.php | 24 +++----- .../CannotMapTypeExceptionInterface.php | 12 +--- src/Mappers/CannotMapTypeTrait.php | 14 ++--- src/Mappers/CompositeTypeMapper.php | 4 +- src/Mappers/DuplicateMappingException.php | 8 +-- src/Mappers/GlobAnnotationsCache.php | 30 ++++------ src/Mappers/GlobExtendAnnotationsCache.php | 6 +- src/Mappers/GlobExtendTypeMapperCache.php | 12 ++-- src/Mappers/GlobTypeMapper.php | 6 +- src/Mappers/GlobTypeMapperCache.php | 42 +++++--------- src/Mappers/MappedClass.php | 24 ++------ .../Parameters/ContainerParameterHandler.php | 2 +- .../Parameters/InjectUserParameterHandler.php | 2 +- src/Mappers/Parameters/Next.php | 2 +- .../Parameters/ParameterHandlerInterface.php | 2 +- .../ParameterMiddlewareInterface.php | 2 +- .../Parameters/ParameterMiddlewarePipe.php | 2 +- .../ResolveInfoParameterHandler.php | 2 +- src/Mappers/Parameters/TypeHandler.php | 42 +++++++------- src/Mappers/PorpaginasTypeMapper.php | 2 +- src/Mappers/RecursiveTypeMapper.php | 50 +++++------------ src/Mappers/RecursiveTypeMapperInterface.php | 6 +- src/Mappers/Root/BaseTypeMapper.php | 12 ++-- src/Mappers/Root/CompoundTypeMapper.php | 4 +- src/Mappers/Root/EnumTypeMapper.php | 28 ++++------ src/Mappers/Root/FinalRootTypeMapper.php | 8 +-- src/Mappers/Root/IteratorTypeMapper.php | 22 +++----- src/Mappers/Root/MyCLabsEnumTypeMapper.php | 24 +++----- .../Root/NullableTypeMapperAdapter.php | 2 +- .../Root/RootTypeMapperFactoryContext.php | 8 +-- src/Mappers/Root/RootTypeMapperInterface.php | 4 +- src/Mappers/StaticClassListTypeMapper.php | 8 +-- .../StaticClassListTypeMapperFactory.php | 4 +- src/Mappers/StaticTypeMapper.php | 2 +- src/Mappers/TypeMapperInterface.php | 2 +- .../AuthorizationFieldMiddleware.php | 6 +- .../AuthorizationInputFieldMiddleware.php | 10 ++-- src/Middlewares/FieldHandlerInterface.php | 6 +- src/Middlewares/FieldMiddlewareInterface.php | 2 +- src/Middlewares/FieldMiddlewarePipe.php | 2 +- .../InputFieldHandlerInterface.php | 2 +- .../InputFieldMiddlewareInterface.php | 2 +- src/Middlewares/InputFieldMiddlewarePipe.php | 2 +- src/Middlewares/InputNext.php | 2 +- src/Middlewares/MissingMagicGetException.php | 4 +- src/Middlewares/Next.php | 2 +- src/Middlewares/SecurityFieldMiddleware.php | 2 +- .../SecurityInputFieldMiddleware.php | 4 +- src/Middlewares/ServiceResolver.php | 4 +- .../SourceInputPropertyResolver.php | 2 +- src/Middlewares/SourcePropertyResolver.php | 2 +- src/Middlewares/SourceResolver.php | 2 +- src/NamingStrategyInterface.php | 4 +- src/Parameters/ContainerParameter.php | 6 +- src/Parameters/DefaultValueParameter.php | 6 +- src/Parameters/InjectUserParameter.php | 6 +- src/Parameters/InputTypeParameter.php | 12 ++-- .../InputTypeParameterInterface.php | 10 +--- src/Parameters/InputTypeProperty.php | 4 +- src/Parameters/MissingArgumentException.php | 6 +- src/Parameters/ParameterInterface.php | 6 +- src/Parameters/PrefetchDataParameter.php | 6 +- src/Parameters/ResolveInfoParameter.php | 6 +- src/Parameters/SourceParameter.php | 6 +- src/PrefetchBuffer.php | 24 ++------ src/QueryField.php | 6 +- src/QueryFieldDescriptor.php | 56 ++++++++----------- src/QueryProviderInterface.php | 8 +-- src/Reflection/CachedDocBlockFactory.php | 10 +--- src/Schema.php | 2 +- src/SchemaFactory.php | 40 ++++++------- .../AuthenticationServiceInterface.php | 6 +- .../AuthorizationServiceInterface.php | 4 +- src/Security/FailAuthenticationService.php | 2 +- .../SecurityExpressionLanguageProvider.php | 4 +- src/Security/VoidAuthenticationService.php | 2 +- src/TypeGenerator.php | 2 +- src/TypeRegistry.php | 8 +-- src/Types/ArgumentResolver.php | 2 +- src/Types/DateTimeType.php | 4 +- src/Types/EnumType.php | 8 +-- src/Types/InputType.php | 14 ++--- src/Types/InterfaceFromObjectType.php | 2 +- src/Types/MutableInputObjectType.php | 6 +- src/Types/MutableInterfaceType.php | 2 +- src/Types/MutableObjectType.php | 2 +- src/Types/MutableTrait.php | 16 +++--- src/Types/ObjectFromInterfaceType.php | 4 +- src/Types/ResolvableMutableInputInterface.php | 2 +- .../ResolvableMutableInputObjectType.php | 22 +++----- src/Types/TypeAnnotatedObjectType.php | 10 +--- src/Types/TypeResolver.php | 18 ++---- src/Types/UnionType.php | 4 +- src/Utils/Namespaces/NS.php | 8 +-- src/Utils/Namespaces/NamespaceFactory.php | 6 +- src/Utils/PropertyAccessor.php | 8 +-- 133 files changed, 488 insertions(+), 827 deletions(-) diff --git a/src/AggregateControllerQueryProvider.php b/src/AggregateControllerQueryProvider.php index 75f2a490ae..61135bacb7 100644 --- a/src/AggregateControllerQueryProvider.php +++ b/src/AggregateControllerQueryProvider.php @@ -33,9 +33,7 @@ public function __construct(private iterable $controllers, private FieldsBuilder { } - /** - * @return array - */ + /** @return array */ public function getQueries(): array { $queryList = []; @@ -48,9 +46,7 @@ public function getQueries(): array return $this->flattenList($queryList); } - /** - * @return array - */ + /** @return array */ public function getMutations(): array { $mutationList = []; diff --git a/src/AggregateQueryProvider.php b/src/AggregateQueryProvider.php index c74b7b58bb..fe4d51fd94 100644 --- a/src/AggregateQueryProvider.php +++ b/src/AggregateQueryProvider.php @@ -17,17 +17,13 @@ class AggregateQueryProvider implements QueryProviderInterface /** @var QueryProviderInterface[] */ private array $queryProviders; - /** - * @param QueryProviderInterface[] $queryProviders - */ + /** @param QueryProviderInterface[] $queryProviders */ public function __construct(iterable $queryProviders) { $this->queryProviders = is_array($queryProviders) ? $queryProviders : iterator_to_array($queryProviders); } - /** - * @return QueryField[] - */ + /** @return QueryField[] */ public function getQueries(): array { $queriesArray = array_map(static function (QueryProviderInterface $queryProvider) { @@ -40,9 +36,7 @@ public function getQueries(): array return array_merge(...$queriesArray); } - /** - * @return QueryField[] - */ + /** @return QueryField[] */ public function getMutations(): array { $mutationsArray = array_map(static function (QueryProviderInterface $queryProvider) { diff --git a/src/AnnotationReader.php b/src/AnnotationReader.php index e4ee41ea2b..08f8112375 100644 --- a/src/AnnotationReader.php +++ b/src/AnnotationReader.php @@ -49,6 +49,7 @@ class AnnotationReader { // In this mode, no exceptions will be thrown for incorrect annotations (unless the name of the annotation we are looking for is part of the docblock) public const LAX_MODE = 'LAX_MODE'; + // In this mode, exceptions will be thrown for any incorrect annotations. public const STRICT_MODE = 'STRICT_MODE'; @@ -86,7 +87,7 @@ public function __construct(private Reader $reader, private string $mode = self: * * @template T of object */ - private function getClassAnnotation(ReflectionClass $refClass, string $annotationClass): ?object + private function getClassAnnotation(ReflectionClass $refClass, string $annotationClass): object|null { try { $attribute = $refClass->getAttributes($annotationClass)[0] ?? null; @@ -123,7 +124,7 @@ private function getClassAnnotation(ReflectionClass $refClass, string $annotatio * * @throws AnnotationException */ - private function getMethodAnnotation(ReflectionMethod $refMethod, string $annotationClass): ?object + private function getMethodAnnotation(ReflectionMethod $refMethod, string $annotationClass): object|null { $cacheKey = $refMethod->getDeclaringClass()->getName() . '::' . $refMethod->getName() . '_' . $annotationClass; if (array_key_exists($cacheKey, $this->methodAnnotationCache)) { @@ -200,7 +201,7 @@ static function ($attribute) { }, array_filter($refClass->getAttributes(), static function ($annotation) use ($annotationClass): bool { return is_a($annotation->getName(), $annotationClass, true); - }) + }), ); $toAddAnnotations[] = $attributes; @@ -231,7 +232,7 @@ static function ($attribute) { * * @template T of object */ - public function getTypeAnnotation(ReflectionClass $refClass): ?TypeInterface + public function getTypeAnnotation(ReflectionClass $refClass): TypeInterface|null { try { $type = $this->getClassAnnotation($refClass, Type::class) @@ -276,7 +277,7 @@ public function getInputAnnotations(ReflectionClass $refClass): array * * @template T of object */ - public function getExtendTypeAnnotation(ReflectionClass $refClass): ?ExtendType + public function getExtendTypeAnnotation(ReflectionClass $refClass): ExtendType|null { try { $extendType = $this->getClassAnnotation($refClass, ExtendType::class); @@ -287,15 +288,13 @@ public function getExtendTypeAnnotation(ReflectionClass $refClass): ?ExtendType return $extendType; } - public function getEnumTypeAnnotation(ReflectionClass $refClass): ?EnumType + public function getEnumTypeAnnotation(ReflectionClass $refClass): EnumType|null { return $this->getClassAnnotation($refClass, EnumType::class); } - /** - * @param class-string $annotationClass - */ - public function getRequestAnnotation(ReflectionMethod $refMethod, string $annotationClass): ?AbstractRequest + /** @param class-string $annotationClass */ + public function getRequestAnnotation(ReflectionMethod $refMethod, string $annotationClass): AbstractRequest|null { $queryAnnotation = $this->getMethodAnnotation($refMethod, $annotationClass); assert($queryAnnotation instanceof AbstractRequest || $queryAnnotation === null); @@ -318,7 +317,7 @@ public function getSourceFields(ReflectionClass $refClass): array return $sourceFields; } - public function getFactoryAnnotation(ReflectionMethod $refMethod): ?Factory + public function getFactoryAnnotation(ReflectionMethod $refMethod): Factory|null { $factoryAnnotation = $this->getMethodAnnotation($refMethod, Factory::class); assert($factoryAnnotation instanceof Factory || $factoryAnnotation === null); @@ -326,7 +325,7 @@ public function getFactoryAnnotation(ReflectionMethod $refMethod): ?Factory return $factoryAnnotation; } - public function getDecorateAnnotation(ReflectionMethod $refMethod): ?Decorate + public function getDecorateAnnotation(ReflectionMethod $refMethod): Decorate|null { $decorateAnnotation = $this->getMethodAnnotation($refMethod, Decorate::class); assert($decorateAnnotation instanceof Decorate || $decorateAnnotation === null); @@ -376,9 +375,7 @@ public function getParameterAnnotationsPerParameter(array $refParameters): array /** @var ParameterAnnotationInterface[] $parameterAnnotations */ $parameterAnnotations = $this->getMethodAnnotations($method, ParameterAnnotationInterface::class); - /** - * @var array> $parameterAnnotationsPerParameter - */ + /** @var array> $parameterAnnotationsPerParameter */ $parameterAnnotationsPerParameter = []; foreach ($parameterAnnotations as $parameterAnnotation) { $parameterAnnotationsPerParameter[$parameterAnnotation->getTarget()][] = $parameterAnnotation; @@ -406,25 +403,21 @@ static function ($attribute) { }, array_filter($attributes, static function ($annotation): bool { return is_a($annotation->getName(), ParameterAnnotationInterface::class, true); - }) + }), ), ]; } return array_map( static function (array $parameterAnnotations): ParameterAnnotations { - /** - * @var ParameterAnnotationInterface[] $parameterAnnotations - */ + /** @var ParameterAnnotationInterface[] $parameterAnnotations */ return new ParameterAnnotations($parameterAnnotations); }, - $parameterAnnotationsPerParameter + $parameterAnnotationsPerParameter, ); } - /** - * @throws AnnotationException - */ + /** @throws AnnotationException */ public function getMiddlewareAnnotations(ReflectionMethod|ReflectionProperty $reflection): MiddlewareAnnotations { if ($reflection instanceof ReflectionMethod) { @@ -469,7 +462,7 @@ static function ($attribute) { }, array_filter($attributes, static function ($annotation) use ($annotationClass): bool { return is_a($annotation->getName(), $annotationClass, true); - }) + }), ), ]; } catch (AnnotationException $e) { @@ -525,7 +518,7 @@ static function ($attribute) { }, array_filter($attributes, static function ($annotation) use ($annotationClass): bool { return is_a($annotation->getName(), $annotationClass, true); - }) + }), ), ]; } catch (AnnotationException $e) { diff --git a/src/Annotations/AbstractRequest.php b/src/Annotations/AbstractRequest.php index 40b4c152c6..cf0f858b55 100644 --- a/src/Annotations/AbstractRequest.php +++ b/src/Annotations/AbstractRequest.php @@ -6,14 +6,12 @@ abstract class AbstractRequest { - private ?string $outputType; + private string|null $outputType; - private ?string $name; + private string|null $name; - /** - * @param mixed[] $attributes - */ - public function __construct(array $attributes = [], ?string $name = null, ?string $outputType = null) + /** @param mixed[] $attributes */ + public function __construct(array $attributes = [], string|null $name = null, string|null $outputType = null) { $this->outputType = $outputType ?? $attributes['outputType'] ?? null; $this->name = $name ?? $attributes['name'] ?? null; @@ -23,7 +21,7 @@ public function __construct(array $attributes = [], ?string $name = null, ?strin * Returns the GraphQL return type of the request (as a string). * The string can represent the FQCN of the type or an entry in the container resolving to the GraphQL type. */ - public function getOutputType(): ?string + public function getOutputType(): string|null { return $this->outputType; } @@ -32,7 +30,7 @@ public function getOutputType(): ?string * Returns the name of the GraphQL query/mutation/field. * If not specified, the name of the method should be used instead. */ - public function getName(): ?string + public function getName(): string|null { return $this->name; } diff --git a/src/Annotations/Autowire.php b/src/Annotations/Autowire.php index a9160b32e7..5974b96a6d 100644 --- a/src/Annotations/Autowire.php +++ b/src/Annotations/Autowire.php @@ -28,9 +28,7 @@ class Autowire implements ParameterAnnotationInterface /** @var string|null */ private $identifier; - /** - * @param array|string $identifier - */ + /** @param array|string $identifier */ public function __construct(array|string $identifier = []) { $values = $identifier; @@ -52,7 +50,7 @@ public function getTarget(): string return $this->for; } - public function getIdentifier(): ?string + public function getIdentifier(): string|null { return $this->identifier; } diff --git a/src/Annotations/EnumType.php b/src/Annotations/EnumType.php index ad63e47778..77f624bd6e 100644 --- a/src/Annotations/EnumType.php +++ b/src/Annotations/EnumType.php @@ -26,10 +26,8 @@ class EnumType /** @var bool */ private $useValues; - /** - * @param mixed[] $attributes - */ - public function __construct(array $attributes = [], ?string $name = null, ?bool $useValues = null) + /** @param mixed[] $attributes */ + public function __construct(array $attributes = [], string|null $name = null, bool|null $useValues = null) { $this->name = $name ?? $attributes['name'] ?? null; $this->useValues = $useValues ?? $attributes['useValues'] ?? false; @@ -38,7 +36,7 @@ public function __construct(array $attributes = [], ?string $name = null, ?bool /** * Returns the GraphQL name for this type. */ - public function getName(): ?string + public function getName(): string|null { return $this->name; } diff --git a/src/Annotations/ExtendType.php b/src/Annotations/ExtendType.php index 67ff4e715e..40592090fd 100644 --- a/src/Annotations/ExtendType.php +++ b/src/Annotations/ExtendType.php @@ -30,10 +30,8 @@ class ExtendType /** @var string|null */ private $name; - /** - * @param mixed[] $attributes - */ - public function __construct(array $attributes = [], ?string $class = null, ?string $name = null) + /** @param mixed[] $attributes */ + public function __construct(array $attributes = [], string|null $class = null, string|null $name = null) { $className = isset($attributes['class']) ? ltrim($attributes['class'], '\\') : null; $className = $className ?? $class; @@ -53,12 +51,12 @@ public function __construct(array $attributes = [], ?string $class = null, ?stri * * @return class-string|null */ - public function getClass(): ?string + public function getClass(): string|null { return $this->class; } - public function getName(): ?string + public function getName(): string|null { return $this->name; } diff --git a/src/Annotations/Factory.php b/src/Annotations/Factory.php index 39a7eff16d..457eb087ed 100644 --- a/src/Annotations/Factory.php +++ b/src/Annotations/Factory.php @@ -25,10 +25,8 @@ class Factory /** @var bool */ private $default; - /** - * @param mixed[] $attributes - */ - public function __construct(array $attributes = [], ?string $name = null, ?bool $default = null) + /** @param mixed[] $attributes */ + public function __construct(array $attributes = [], string|null $name = null, bool|null $default = null) { $this->name = $name ?? $attributes['name'] ?? null; // This IS the default if no name is set and no "default" attribute is passed. @@ -43,7 +41,7 @@ public function __construct(array $attributes = [], ?string $name = null, ?bool * Returns the name of the GraphQL input type. * If not specified, the name of the method should be used instead. */ - public function getName(): ?string + public function getName(): string|null { return $this->name; } diff --git a/src/Annotations/FailWith.php b/src/Annotations/FailWith.php index c245028bb6..7e153a5e50 100644 --- a/src/Annotations/FailWith.php +++ b/src/Annotations/FailWith.php @@ -28,9 +28,7 @@ class FailWith implements MiddlewareAnnotationInterface */ private $value; - /** - * @throws BadMethodCallException - */ + /** @throws BadMethodCallException */ public function __construct(mixed $values = [], mixed $value = '__fail__with__magic__key__') { if ($value !== '__fail__with__magic__key__') { diff --git a/src/Annotations/Field.php b/src/Annotations/Field.php index 9975c39ded..b64ed5d3a0 100644 --- a/src/Annotations/Field.php +++ b/src/Annotations/Field.php @@ -41,7 +41,7 @@ class Field extends AbstractRequest * @param mixed[] $attributes * @param string|string[] $for */ - public function __construct(array $attributes = [], ?string $name = null, ?string $outputType = null, ?string $prefetchMethod = null, string|array|null $for = null, ?string $description = null, ?string $inputType = null) + public function __construct(array $attributes = [], string|null $name = null, string|null $outputType = null, string|null $prefetchMethod = null, string|array|null $for = null, string|null $description = null, string|null $inputType = null) { parent::__construct($attributes, $name, $outputType); $this->prefetchMethod = $prefetchMethod ?? $attributes['prefetchMethod'] ?? null; @@ -59,25 +59,23 @@ public function __construct(array $attributes = [], ?string $name = null, ?strin /** * Returns the prefetch method name (the method that will be called to fetch many records at once) */ - public function getPrefetchMethod(): ?string + public function getPrefetchMethod(): string|null { return $this->prefetchMethod; } - /** - * @return string[]|null - */ - public function getFor(): ?array + /** @return string[]|null */ + public function getFor(): array|null { return $this->for; } - public function getDescription(): ?string + public function getDescription(): string|null { return $this->description; } - public function getInputType(): ?string + public function getInputType(): string|null { return $this->inputType; } diff --git a/src/Annotations/HideParameter.php b/src/Annotations/HideParameter.php index 970b8850ac..2c14fe4f7a 100644 --- a/src/Annotations/HideParameter.php +++ b/src/Annotations/HideParameter.php @@ -25,9 +25,7 @@ class HideParameter implements ParameterAnnotationInterface /** @var string */ private $for; - /** - * @param array $values - */ + /** @param array $values */ public function __construct(array $values = []) { if (! isset($values['for'])) { diff --git a/src/Annotations/InjectUser.php b/src/Annotations/InjectUser.php index f7e3da3521..7d050b3c52 100644 --- a/src/Annotations/InjectUser.php +++ b/src/Annotations/InjectUser.php @@ -25,9 +25,7 @@ class InjectUser implements ParameterAnnotationInterface /** @var string */ private $for; - /** - * @param array $values - */ + /** @param array $values */ public function __construct(array $values = []) { if (! isset($values['for'])) { diff --git a/src/Annotations/Input.php b/src/Annotations/Input.php index 22a5f21e42..abe22a97d7 100644 --- a/src/Annotations/Input.php +++ b/src/Annotations/Input.php @@ -24,25 +24,23 @@ class Input implements TypeInterface { /** @var class-string|null */ - private ?string $class = null; + private string|null $class = null; - private ?string $name = null; + private string|null $name = null; private bool $default; - private ?string $description = null; + private string|null $description = null; private bool $update; - /** - * @param mixed[] $attributes - */ + /** @param mixed[] $attributes */ public function __construct( array $attributes = [], - ?string $name = null, - ?bool $default = null, - ?string $description = null, - ?bool $update = null + string|null $name = null, + bool|null $default = null, + string|null $description = null, + bool|null $update = null, ) { $this->name = $name ?? $attributes['name'] ?? null; $this->default = $default ?? $attributes['default'] ?? $this->name === null; @@ -64,9 +62,7 @@ public function getClass(): string return $this->class; } - /** - * @param class-string $class - */ + /** @param class-string $class */ public function setClass(string $class): void { $this->class = $class; @@ -75,7 +71,7 @@ public function setClass(string $class): void /** * Returns the GraphQL input name for this type. */ - public function getName(): ?string + public function getName(): string|null { return $this->name; } @@ -91,7 +87,7 @@ public function isDefault(): bool /** * Returns description about this input type. */ - public function getDescription(): ?string + public function getDescription(): string|null { return $this->description; } diff --git a/src/Annotations/MagicField.php b/src/Annotations/MagicField.php index fdaae62ae2..d48359beaf 100644 --- a/src/Annotations/MagicField.php +++ b/src/Annotations/MagicField.php @@ -46,10 +46,8 @@ class MagicField implements SourceFieldInterface /** @var array */ private $parameterAnnotations; - /** - * @param mixed[] $attributes - */ - public function __construct(array $attributes = [], ?string $name = null, ?string $outputType = null, ?string $phpType = null, ?string $description = null, ?string $sourceName = null) + /** @param mixed[] $attributes */ + public function __construct(array $attributes = [], string|null $name = null, string|null $outputType = null, string|null $phpType = null, string|null $description = null, string|null $sourceName = null) { $this->name = $attributes['name'] ?? $name; $this->outputType = $attributes['outputType'] ?? $outputType ?? null; @@ -96,7 +94,7 @@ public function getName(): string * Returns the GraphQL return type of the property (as a string). * The string is the GraphQL output type name. */ - public function getOutputType(): ?string + public function getOutputType(): string|null { return $this->outputType; } @@ -105,7 +103,7 @@ public function getOutputType(): ?string * Returns the PHP return type of the property (as a string). * The string is the PHPDoc for the PHP type. */ - public function getPhpType(): ?string + public function getPhpType(): string|null { return $this->phpType; } @@ -113,7 +111,7 @@ public function getPhpType(): ?string /** * Returns the description of the GraphQL query/mutation/field. */ - public function getDescription(): ?string + public function getDescription(): string|null { return $this->description; } @@ -121,7 +119,7 @@ public function getDescription(): ?string /** * Returns the property name in the source class */ - public function getSourceName(): ?string + public function getSourceName(): string|null { return $this->sourceName; } @@ -131,9 +129,7 @@ public function getMiddlewareAnnotations(): MiddlewareAnnotations return $this->middlewareAnnotations; } - /** - * @return array Key: the name of the attribute - */ + /** @return array Key: the name of the attribute */ public function getParameterAnnotations(): array { return $this->parameterAnnotations; diff --git a/src/Annotations/MiddlewareAnnotations.php b/src/Annotations/MiddlewareAnnotations.php index 258fc88702..d2bb63c168 100644 --- a/src/Annotations/MiddlewareAnnotations.php +++ b/src/Annotations/MiddlewareAnnotations.php @@ -13,9 +13,7 @@ */ class MiddlewareAnnotations { - /** - * @param array $annotations - */ + /** @param array $annotations */ public function __construct(private array $annotations) { } @@ -35,7 +33,7 @@ public function getAnnotationsByType(string $className): array /** * Returns at most 1 annotation of the $className type. */ - public function getAnnotationByType(string $className): ?MiddlewareAnnotationInterface + public function getAnnotationByType(string $className): MiddlewareAnnotationInterface|null { $annotations = $this->getAnnotationsByType($className); $count = count($annotations); diff --git a/src/Annotations/ParameterAnnotations.php b/src/Annotations/ParameterAnnotations.php index ca19cd2264..67f623eb34 100644 --- a/src/Annotations/ParameterAnnotations.php +++ b/src/Annotations/ParameterAnnotations.php @@ -13,9 +13,7 @@ */ class ParameterAnnotations { - /** - * @param array $annotations - */ + /** @param array $annotations */ public function __construct(private array $annotations) { } @@ -45,7 +43,7 @@ public function getAnnotationsByType(string $className): array * * @template T of ParameterAnnotationInterface */ - public function getAnnotationByType(string $className): ?ParameterAnnotationInterface + public function getAnnotationByType(string $className): ParameterAnnotationInterface|null { $annotations = $this->getAnnotationsByType($className); $count = count($annotations); @@ -60,9 +58,7 @@ public function getAnnotationByType(string $className): ?ParameterAnnotationInte return array_pop($annotations); } - /** - * @return array - */ + /** @return array */ public function getAllAnnotations(): array { return $this->annotations; diff --git a/src/Annotations/Security.php b/src/Annotations/Security.php index 229a446299..22381f3312 100644 --- a/src/Annotations/Security.php +++ b/src/Annotations/Security.php @@ -43,7 +43,7 @@ class Security implements MiddlewareAnnotationInterface * * @throws BadMethodCallException */ - public function __construct(array|string $data = [], ?string $expression = null, mixed $failWith = '__fail__with__magic__key__', ?string $message = null, ?int $statusCode = null) + public function __construct(array|string $data = [], string|null $expression = null, mixed $failWith = '__fail__with__magic__key__', string|null $message = null, int|null $statusCode = null) { if (is_string($data)) { $data = ['expression' => $data]; diff --git a/src/Annotations/SourceField.php b/src/Annotations/SourceField.php index 0b76b4da76..f09363f1c9 100644 --- a/src/Annotations/SourceField.php +++ b/src/Annotations/SourceField.php @@ -27,23 +27,21 @@ class SourceField implements SourceFieldInterface { private string $name; - private ?string $outputType = null; + private string|null $outputType = null; - private ?string $phpType = null; + private string|null $phpType = null; - private ?string $description = null; + private string|null $description = null; - private ?string $sourceName; + private string|null $sourceName; private MiddlewareAnnotations $middlewareAnnotations; /** @var array */ private array $parameterAnnotations; - /** - * @param mixed[] $attributes - */ - public function __construct(array $attributes = [], ?string $name = null, ?string $outputType = null, ?string $phpType = null, ?string $description = null, ?string $sourceName = null) + /** @param mixed[] $attributes */ + public function __construct(array $attributes = [], string|null $name = null, string|null $outputType = null, string|null $phpType = null, string|null $description = null, string|null $sourceName = null) { $name = $name ?? $attributes['name'] ?? null; if ($name === null) { @@ -92,12 +90,12 @@ public function getName(): string * Returns the GraphQL return type of the request (as a string). * The string is the GraphQL output type name. */ - public function getOutputType(): ?string + public function getOutputType(): string|null { return $this->outputType; } - public function getPhpType(): ?string + public function getPhpType(): string|null { return $this->phpType; } @@ -105,7 +103,7 @@ public function getPhpType(): ?string /** * Returns the description of the GraphQL query/mutation/field. */ - public function getDescription(): ?string + public function getDescription(): string|null { return $this->description; } @@ -113,7 +111,7 @@ public function getDescription(): ?string /** * Returns the property name in the source class */ - public function getSourceName(): ?string + public function getSourceName(): string|null { return $this->sourceName; } @@ -123,9 +121,7 @@ public function getMiddlewareAnnotations(): MiddlewareAnnotations return $this->middlewareAnnotations; } - /** - * @return array Key: the name of the attribute - */ + /** @return array Key: the name of the attribute */ public function getParameterAnnotations(): array { return $this->parameterAnnotations; diff --git a/src/Annotations/SourceFieldInterface.php b/src/Annotations/SourceFieldInterface.php index 016e40628f..6e4937b170 100644 --- a/src/Annotations/SourceFieldInterface.php +++ b/src/Annotations/SourceFieldInterface.php @@ -18,29 +18,27 @@ public function getName(): string; * Returns the GraphQL return type of the field (as a string). * The string is the GraphQL output type name. */ - public function getOutputType(): ?string; + public function getOutputType(): string|null; /** * Returns the PHP return type of the field (as a string). * The string is the PHPDoc for the PHP type. */ - public function getPhpType(): ?string; + public function getPhpType(): string|null; /** * Returns the description of the GraphQL query/mutation/field. */ - public function getDescription(): ?string; + public function getDescription(): string|null; /** * Returns the property name in the source class */ - public function getSourceName(): ?string; + public function getSourceName(): string|null; public function getMiddlewareAnnotations(): MiddlewareAnnotations; - /** - * @return array Key: the name of the attribute - */ + /** @return array Key: the name of the attribute */ public function getParameterAnnotations(): array; /** diff --git a/src/Annotations/Type.php b/src/Annotations/Type.php index 6ce8bdc6f0..0505eec76f 100644 --- a/src/Annotations/Type.php +++ b/src/Annotations/Type.php @@ -54,11 +54,11 @@ class Type implements TypeInterface */ public function __construct( array $attributes = [], - ?string $class = null, - ?string $name = null, - ?bool $default = null, - ?bool $external = null, - ?bool $useEnumValues = null + string|null $class = null, + string|null $name = null, + bool|null $default = null, + bool|null $external = null, + bool|null $useEnumValues = null, ) { $external = $external ?? $attributes['external'] ?? null; $class = $class ?? $attributes['class'] ?? null; @@ -121,7 +121,7 @@ public function isSelfType(): bool /** * Returns the GraphQL output name for this type. */ - public function getName(): ?string + public function getName(): string|null { return $this->name; } diff --git a/src/Annotations/TypeInterface.php b/src/Annotations/TypeInterface.php index 726419706f..9352ad345d 100644 --- a/src/Annotations/TypeInterface.php +++ b/src/Annotations/TypeInterface.php @@ -16,12 +16,10 @@ public function isSelfType(): bool; public function setClass(string $className): void; - /** - * @return class-string - */ + /** @return class-string */ public function getClass(): string; public function isDefault(): bool; - public function getName(): ?string; + public function getName(): string|null; } diff --git a/src/Containers/BasicAutoWiringContainer.php b/src/Containers/BasicAutoWiringContainer.php index c4fcc5b484..06fe38c56a 100644 --- a/src/Containers/BasicAutoWiringContainer.php +++ b/src/Containers/BasicAutoWiringContainer.php @@ -20,9 +20,7 @@ class BasicAutoWiringContainer implements ContainerInterface /** @var array */ private array $values = []; - /** - * @param ContainerInterface $container The proxied container. - */ + /** @param ContainerInterface $container The proxied container. */ public function __construct(private ContainerInterface $container) { } diff --git a/src/Exceptions/GraphQLAggregateException.php b/src/Exceptions/GraphQLAggregateException.php index 66670b70fc..693a6df733 100644 --- a/src/Exceptions/GraphQLAggregateException.php +++ b/src/Exceptions/GraphQLAggregateException.php @@ -19,9 +19,7 @@ class GraphQLAggregateException extends Exception implements GraphQLAggregateExc /** @var (ClientAware&Throwable)[] */ private array $exceptions = []; - /** - * @param (ClientAware&Throwable)[] $exceptions - */ + /** @param (ClientAware&Throwable)[] $exceptions */ public function __construct(iterable $exceptions = []) { parent::__construct('Many exceptions have be thrown:'); @@ -30,9 +28,7 @@ public function __construct(iterable $exceptions = []) } } - /** - * @param ClientAware&Throwable $exception - */ + /** @param ClientAware&Throwable $exception */ public function add(ClientAware $exception): void { $this->exceptions[] = $exception; @@ -40,9 +36,7 @@ public function add(ClientAware $exception): void $this->updateCode(); } - /** - * @return (ClientAware&Throwable)[] - */ + /** @return (ClientAware&Throwable)[] */ public function getExceptions(): array { return $this->exceptions; diff --git a/src/Exceptions/GraphQLAggregateExceptionInterface.php b/src/Exceptions/GraphQLAggregateExceptionInterface.php index 434530f8ba..f252d09924 100644 --- a/src/Exceptions/GraphQLAggregateExceptionInterface.php +++ b/src/Exceptions/GraphQLAggregateExceptionInterface.php @@ -13,8 +13,6 @@ */ interface GraphQLAggregateExceptionInterface extends Throwable { - /** - * @return (ClientAware&Throwable)[] - */ + /** @return (ClientAware&Throwable)[] */ public function getExceptions(): array; } diff --git a/src/Exceptions/GraphQLException.php b/src/Exceptions/GraphQLException.php index 40f0a467f6..ca706d1021 100644 --- a/src/Exceptions/GraphQLException.php +++ b/src/Exceptions/GraphQLException.php @@ -9,10 +9,8 @@ class GraphQLException extends Exception implements GraphQLExceptionInterface { - /** - * @param array $extensions - */ - public function __construct(string $message, int $code = 0, ?Throwable $previous = null, private string $category = 'Exception', private array $extensions = []) + /** @param array $extensions */ + public function __construct(string $message, int $code = 0, Throwable|null $previous = null, private string $category = 'Exception', private array $extensions = []) { parent::__construct($message, $code, $previous); } diff --git a/src/Exceptions/WebonyxErrorHandler.php b/src/Exceptions/WebonyxErrorHandler.php index e146e7432e..03c0c755f8 100644 --- a/src/Exceptions/WebonyxErrorHandler.php +++ b/src/Exceptions/WebonyxErrorHandler.php @@ -16,9 +16,7 @@ */ final class WebonyxErrorHandler { - /** - * @return mixed[] - */ + /** @return mixed[] */ public static function errorFormatter(Error $error): array { $formattedError = FormattedError::createFromException($error); diff --git a/src/FactoryContext.php b/src/FactoryContext.php index fa69c2f2bd..4985a2040a 100644 --- a/src/FactoryContext.php +++ b/src/FactoryContext.php @@ -28,9 +28,9 @@ public function __construct( private RecursiveTypeMapperInterface $recursiveTypeMapper, private ContainerInterface $container, private CacheInterface $cache, - private ?InputTypeValidatorInterface $inputTypeValidator, - private ?int $globTTL, - private ?int $mapTTL = null + private InputTypeValidatorInterface|null $inputTypeValidator, + private int|null $globTTL, + private int|null $mapTTL = null, ) { } @@ -84,17 +84,17 @@ public function getCache(): CacheInterface return $this->cache; } - public function getInputTypeValidator(): ?InputTypeValidatorInterface + public function getInputTypeValidator(): InputTypeValidatorInterface|null { return $this->inputTypeValidator; } - public function getGlobTTL(): ?int + public function getGlobTTL(): int|null { return $this->globTTL; } - public function getMapTTL(): ?int + public function getMapTTL(): int|null { return $this->mapTTL; } diff --git a/src/FieldNotFoundException.php b/src/FieldNotFoundException.php index c6d0001f2c..3b5dd62a5a 100644 --- a/src/FieldNotFoundException.php +++ b/src/FieldNotFoundException.php @@ -21,7 +21,7 @@ public static function missingField(string $className, string $fieldName): self $className, ucfirst($fieldName), $className, - ucfirst($fieldName) + ucfirst($fieldName), )); } @@ -30,7 +30,7 @@ public static function wrapWithCallerInfo(self $e, string $className): self throw new self(sprintf( 'There is an issue with a @SourceField annotation in class "%s": %s', $className, - $e->getMessage() + $e->getMessage(), ), 0, $e); } } diff --git a/src/FieldsBuilder.php b/src/FieldsBuilder.php index cfacd34ef2..c9671bd94a 100644 --- a/src/FieldsBuilder.php +++ b/src/FieldsBuilder.php @@ -83,7 +83,7 @@ public function __construct( private RootTypeMapperInterface $rootTypeMapper, private ParameterMiddlewareInterface $parameterMapper, private FieldMiddlewareInterface $fieldMiddleware, - private InputFieldMiddlewareInterface $inputFieldMiddleware + private InputFieldMiddlewareInterface $inputFieldMiddleware, ) { $this->typeMapper = new TypeHandler($this->argumentResolver, $this->rootTypeMapper, $this->typeResolver); @@ -109,10 +109,8 @@ public function getMutations(object $controller): array return $this->getFieldsByAnnotations($controller, Mutation::class, false); } - /** - * @return array QueryField indexed by name. - */ - public function getFields(object $controller, ?string $typeName = null): array + /** @return array QueryField indexed by name. */ + public function getFields(object $controller, string|null $typeName = null): array { $fieldAnnotations = $this->getFieldsByAnnotations($controller, Annotations\Field::class, true, $typeName); @@ -205,7 +203,7 @@ public function getInputFields(string $className, string $inputName, bool $isUpd * * @return array QueryField indexed by name. */ - public function getSelfFields(string $className, ?string $typeName = null): array + public function getSelfFields(string $className, string|null $typeName = null): array { $fieldAnnotations = $this->getFieldsByAnnotations($className, Annotations\Field::class, false, $typeName); @@ -271,7 +269,7 @@ public function getParametersForDecorator(ReflectionMethod $refMethod): array * * @throws ReflectionException */ - private function getFieldsByAnnotations($controller, string $annotationName, bool $injectSource, ?string $typeName = null): array + private function getFieldsByAnnotations($controller, string $annotationName, bool $injectSource, string|null $typeName = null): array { $refClass = new ReflectionClass($controller); /** @var array $queryList */ @@ -333,7 +331,7 @@ private function getFieldsByAnnotations($controller, string $annotationName, boo * * @throws AnnotationException */ - private function getFieldsByMethodAnnotations(string|object $controller, ReflectionClass $refClass, ReflectionMethod $refMethod, string $annotationName, bool $injectSource, ?string $typeName = null): array + private function getFieldsByMethodAnnotations(string|object $controller, ReflectionClass $refClass, ReflectionMethod $refMethod, string $annotationName, bool $injectSource, string|null $typeName = null): array { $fields = []; @@ -416,7 +414,7 @@ private function getFieldsByMethodAnnotations(string|object $controller, Reflect $fieldDescriptor->setMiddlewareAnnotations($this->annotationReader->getMiddlewareAnnotations($refMethod)); $field = $this->fieldMiddleware->process($fieldDescriptor, new class implements FieldHandlerInterface { - public function handle(QueryFieldDescriptor $fieldDescriptor): ?FieldDefinition + public function handle(QueryFieldDescriptor $fieldDescriptor): FieldDefinition|null { return QueryField::fromFieldDescriptor($fieldDescriptor); } @@ -444,7 +442,7 @@ public function handle(QueryFieldDescriptor $fieldDescriptor): ?FieldDefinition * * @throws AnnotationException */ - private function getFieldsByPropertyAnnotations(string|object $controller, ReflectionClass $refClass, ReflectionProperty $refProperty, string $annotationName, ?string $typeName = null): array + private function getFieldsByPropertyAnnotations(string|object $controller, ReflectionClass $refClass, ReflectionProperty $refProperty, string $annotationName, string|null $typeName = null): array { $fields = []; $annotations = $this->annotationReader->getPropertyAnnotations($refProperty, $annotationName); @@ -509,7 +507,7 @@ private function getFieldsByPropertyAnnotations(string|object $controller, Refle $fieldDescriptor->setMiddlewareAnnotations($this->annotationReader->getMiddlewareAnnotations($refProperty)); $field = $this->fieldMiddleware->process($fieldDescriptor, new class implements FieldHandlerInterface { - public function handle(QueryFieldDescriptor $fieldDescriptor): ?FieldDefinition + public function handle(QueryFieldDescriptor $fieldDescriptor): FieldDefinition|null { return QueryField::fromFieldDescriptor($fieldDescriptor); } @@ -632,7 +630,7 @@ private function getQueryFieldsFromSourceFields(array $sourceFields, ReflectionC $fieldDescriptor->setMiddlewareAnnotations($sourceField->getMiddlewareAnnotations()); $field = $this->fieldMiddleware->process($fieldDescriptor, new class implements FieldHandlerInterface { - public function handle(QueryFieldDescriptor $fieldDescriptor): ?FieldDefinition + public function handle(QueryFieldDescriptor $fieldDescriptor): FieldDefinition|null { return QueryField::fromFieldDescriptor($fieldDescriptor); } @@ -732,12 +730,12 @@ private function getMethodFromPropertyName(ReflectionClass $reflectionClass, str * * @return array */ - private function mapParameters(array $refParameters, DocBlock $docBlock, ?SourceFieldInterface $sourceField = null): array + private function mapParameters(array $refParameters, DocBlock $docBlock, SourceFieldInterface|null $sourceField = null): array { if (empty($refParameters)) { return []; } - $additionalParameterAnnotations = $sourceField !== null ? $sourceField->getParameterAnnotations() : []; + $additionalParameterAnnotations = $sourceField?->getParameterAnnotations() ?? []; $docBlockTypes = []; /** @var DocBlock\Tags\Param[] $paramTags */ @@ -779,7 +777,7 @@ private function mapParameters(array $refParameters, DocBlock $docBlock, ?Source /** * Extracts deprecation reason from doc block. */ - private function getDeprecationReason(DocBlock $docBlockObj): ?string + private function getDeprecationReason(DocBlock $docBlockObj): string|null { $deprecated = $docBlockObj->getTagsByName('deprecated'); if (count($deprecated) >= 1) { @@ -832,7 +830,7 @@ private function getPrefetchMethodInfo(ReflectionClass $refClass, ReflectionMeth * * @throws AnnotationException */ - private function getInputFieldsByMethodAnnotations(string|object $controller, ReflectionClass $refClass, ReflectionMethod $refMethod, string $annotationName, bool $injectSource, array $defaultProperties, ?string $typeName = null, bool $isUpdate = false): array + private function getInputFieldsByMethodAnnotations(string|object $controller, ReflectionClass $refClass, ReflectionMethod $refMethod, string $annotationName, bool $injectSource, array $defaultProperties, string|null $typeName = null, bool $isUpdate = false): array { $fields = []; @@ -904,7 +902,7 @@ private function getInputFieldsByMethodAnnotations(string|object $controller, Re $inputFieldDescriptor->setMiddlewareAnnotations($this->annotationReader->getMiddlewareAnnotations($refMethod)); $field = $this->inputFieldMiddleware->process($inputFieldDescriptor, new class implements InputFieldHandlerInterface { - public function handle(InputFieldDescriptor $inputFieldDescriptor): ?InputField + public function handle(InputFieldDescriptor $inputFieldDescriptor): InputField|null { return InputField::fromFieldDescriptor($inputFieldDescriptor); } @@ -930,7 +928,7 @@ public function handle(InputFieldDescriptor $inputFieldDescriptor): ?InputField * * @throws AnnotationException */ - private function getInputFieldsByPropertyAnnotations(string|object $controller, ReflectionClass $refClass, ReflectionProperty $refProperty, string $annotationName, array $defaultProperties, ?string $typeName = null, bool $isUpdate = false): array + private function getInputFieldsByPropertyAnnotations(string|object $controller, ReflectionClass $refClass, ReflectionProperty $refProperty, string $annotationName, array $defaultProperties, string|null $typeName = null, bool $isUpdate = false): array { $fields = []; @@ -973,7 +971,7 @@ private function getInputFieldsByPropertyAnnotations(string|object $controller, trim($description), $isUpdate, $inputProperty->hasDefaultValue(), - $inputProperty->getDefaultValue() + $inputProperty->getDefaultValue(), ); } else { // setters and properties @@ -999,7 +997,7 @@ private function getInputFieldsByPropertyAnnotations(string|object $controller, $inputFieldDescriptor->setMiddlewareAnnotations($this->annotationReader->getMiddlewareAnnotations($refProperty)); $field = $this->inputFieldMiddleware->process($inputFieldDescriptor, new class implements InputFieldHandlerInterface { - public function handle(InputFieldDescriptor $inputFieldDescriptor): ?InputField + public function handle(InputFieldDescriptor $inputFieldDescriptor): InputField|null { return InputField::fromFieldDescriptor($inputFieldDescriptor); } @@ -1016,9 +1014,7 @@ public function handle(InputFieldDescriptor $inputFieldDescriptor): ?InputField return $fields; } - /** - * @return string[] - */ + /** @return string[] */ private function getClassConstructParameterNames(ReflectionClass $refClass): array { $constructor = $refClass->getConstructor(); diff --git a/src/GlobControllerQueryProvider.php b/src/GlobControllerQueryProvider.php index e2866fbe8b..998044984f 100644 --- a/src/GlobControllerQueryProvider.php +++ b/src/GlobControllerQueryProvider.php @@ -31,9 +31,9 @@ final class GlobControllerQueryProvider implements QueryProviderInterface { /** @var array|null */ - private ?array $instancesList = null; + private array|null $instancesList = null; private ClassNameMapper $classNameMapper; - private ?AggregateControllerQueryProvider $aggregateControllerQueryProvider = null; + private AggregateControllerQueryProvider|null $aggregateControllerQueryProvider = null; private CacheContractInterface $cacheContract; /** @@ -47,9 +47,9 @@ public function __construct( private ContainerInterface $container, private AnnotationReader $annotationReader, private CacheInterface $cache, - ?ClassNameMapper $classNameMapper = null, - private ?int $cacheTtl = null, - private bool $recursive = true + ClassNameMapper|null $classNameMapper = null, + private int|null $cacheTtl = null, + private bool $recursive = true, ) { $this->classNameMapper = $classNameMapper ?? ClassNameMapper::createFromComposerFile(null, null, true); @@ -84,9 +84,7 @@ private function getInstancesList(): array return $this->instancesList; } - /** - * @return array - */ + /** @return array */ private function buildInstancesList(): array { $explorer = new GlobClassExplorer($this->namespace, $this->cache, $this->cacheTtl, $this->classNameMapper, $this->recursive); @@ -113,9 +111,7 @@ private function buildInstancesList(): array return $instances; } - /** - * @param ReflectionClass $reflectionClass - */ + /** @param ReflectionClass $reflectionClass */ private function hasQueriesOrMutations(ReflectionClass $reflectionClass): bool { foreach ($reflectionClass->getMethods(ReflectionMethod::IS_PUBLIC) as $refMethod) { @@ -131,17 +127,13 @@ private function hasQueriesOrMutations(ReflectionClass $reflectionClass): bool return false; } - /** - * @return array - */ + /** @return array */ public function getQueries(): array { return $this->getAggregateControllerQueryProvider()->getQueries(); } - /** - * @return array - */ + /** @return array */ public function getMutations(): array { return $this->getAggregateControllerQueryProvider()->getMutations(); diff --git a/src/Http/Psr15GraphQLMiddlewareBuilder.php b/src/Http/Psr15GraphQLMiddlewareBuilder.php index 89aeb22a68..5db5ae15c2 100644 --- a/src/Http/Psr15GraphQLMiddlewareBuilder.php +++ b/src/Http/Psr15GraphQLMiddlewareBuilder.php @@ -26,9 +26,9 @@ class Psr15GraphQLMiddlewareBuilder private string $url = '/graphql'; private ServerConfig $config; - private ?ResponseFactoryInterface $responseFactory = null; + private ResponseFactoryInterface|null $responseFactory = null; - private ?StreamFactoryInterface $streamFactory = null; + private StreamFactoryInterface|null $streamFactory = null; private HttpCodeDeciderInterface $httpCodeDecider; diff --git a/src/Http/WebonyxGraphqlMiddleware.php b/src/Http/WebonyxGraphqlMiddleware.php index 2762eb2c1d..acc02a2fa8 100644 --- a/src/Http/WebonyxGraphqlMiddleware.php +++ b/src/Http/WebonyxGraphqlMiddleware.php @@ -47,7 +47,7 @@ public function __construct( private StreamFactoryInterface $streamFactory, private HttpCodeDeciderInterface $httpCodeDecider, private string $graphqlUri = '/graphql', - ?StandardServer $handler = null + StandardServer|null $handler = null, ) { $this->standardServer = $handler ?? new StandardServer($config); @@ -105,9 +105,7 @@ private function processResult(ExecutionResult|array|Promise $result): array throw new RuntimeException('Unexpected response from StandardServer::executePsrRequest'); // @codeCoverageIgnore } - /** - * @param ExecutionResult|array|Promise $result - */ + /** @param ExecutionResult|array|Promise $result */ private function decideHttpCode(ExecutionResult|array|Promise $result): int { if ($result instanceof ExecutionResult) { @@ -166,9 +164,7 @@ private function hasGraphQLHeader(ServerRequestInterface $request): bool return false; } - /** - * @param mixed[] $array - */ + /** @param mixed[] $array */ private function getJsonResponse(array $array, int $statusCode): ResponseInterface { $response = $this->responseFactory->createResponse(); diff --git a/src/InputField.php b/src/InputField.php index b4e84f5e55..86da58f221 100644 --- a/src/InputField.php +++ b/src/InputField.php @@ -40,7 +40,7 @@ class InputField extends InputObjectField * @param mixed|null $defaultValue the default value set for this field * @param array $additionalConfig */ - public function __construct(string $name, $type, array $arguments, ?ResolverInterface $originalResolver, ?callable $resolver, ?string $comment, bool $isUpdate, bool $hasDefaultValue, mixed $defaultValue, array $additionalConfig = []) + public function __construct(string $name, $type, array $arguments, ResolverInterface|null $originalResolver, callable|null $resolver, string|null $comment, bool $isUpdate, bool $hasDefaultValue, mixed $defaultValue, array $additionalConfig = []) { $config = [ 'name' => $name, @@ -164,7 +164,7 @@ public static function fromFieldDescriptor(InputFieldDescriptor $fieldDescriptor * * @return array */ - private function paramsToArguments(array $parameters, ?object $source, array $args, mixed $context, ResolveInfo $info, callable $resolve): array + private function paramsToArguments(array $parameters, object|null $source, array $args, mixed $context, ResolveInfo $info, callable $resolve): array { $toPassArgs = []; $exceptions = []; diff --git a/src/InputFieldDescriptor.php b/src/InputFieldDescriptor.php index fca0227ca6..5de2d6cf55 100644 --- a/src/InputFieldDescriptor.php +++ b/src/InputFieldDescriptor.php @@ -32,8 +32,8 @@ class InputFieldDescriptor private array $parameters = []; /** @var callable|null */ private $callable; - private ?string $targetMethodOnSource; - private ?string $targetPropertyOnSource; + private string|null $targetMethodOnSource; + private string|null $targetPropertyOnSource; /** * Implement in future PR @@ -44,11 +44,11 @@ class InputFieldDescriptor * Whether we should inject the source as the first parameter or not. */ private bool $injectSource = false; - private ?string $comment = null; + private string|null $comment = null; private MiddlewareAnnotations $middlewareAnnotations; private ReflectionMethod $refMethod; private ReflectionProperty $refProperty; - private ?ResolverInterface $originalResolver = null; + private ResolverInterface|null $originalResolver = null; /** @var callable */ private $resolver; private bool $isUpdate = false; @@ -95,33 +95,25 @@ public function setName(string $name): void $this->name = $name; } - /** - * @return InputType|(NullableType&Type) - */ + /** @return InputType|(NullableType&Type) */ public function getType() { return $this->type; } - /** - * @param InputType|(NullableType&Type) $type - */ + /** @param InputType|(NullableType&Type) $type */ public function setType($type): void { $this->type = $type; } - /** - * @return array - */ + /** @return array */ public function getParameters(): array { return $this->parameters; } - /** - * @param array $parameters - */ + /** @param array $parameters */ public function setParameters(array $parameters): void { $this->parameters = $parameters; @@ -160,7 +152,7 @@ public function setTargetMethodOnSource(string $targetMethodOnSource): void // $this->magicProperty = null; } - public function setTargetPropertyOnSource(?string $targetPropertyOnSource): void + public function setTargetPropertyOnSource(string|null $targetPropertyOnSource): void { if ($this->originalResolver !== null) { throw new GraphQLRuntimeException('You cannot modify the target method via setTargetMethodOnSource because it was already used. You can still wrap the callable using getResolver/setResolver'); @@ -184,12 +176,12 @@ public function setInjectSource(bool $injectSource): void $this->injectSource = $injectSource; } - public function getComment(): ?string + public function getComment(): string|null { return $this->comment; } - public function setComment(?string $comment): void + public function setComment(string|null $comment): void { $this->comment = $comment; } diff --git a/src/InputTypeGenerator.php b/src/InputTypeGenerator.php index dd3e565bd0..2dbb070dab 100644 --- a/src/InputTypeGenerator.php +++ b/src/InputTypeGenerator.php @@ -30,7 +30,7 @@ class InputTypeGenerator public function __construct( private InputTypeUtils $inputTypeUtils, private FieldsBuilder $fieldsBuilder, - private ?InputTypeValidatorInterface $inputTypeValidator = null + private InputTypeValidatorInterface|null $inputTypeValidator = null, ) { } @@ -54,10 +54,8 @@ public function mapFactoryMethod(string $factory, string $methodName, ContainerI return $this->factoryCache[$inputName]; } - /** - * @param class-string $className - */ - public function mapInput(string $className, string $inputName, ?string $description, bool $isUpdate): InputType + /** @param class-string $className */ + public function mapInput(string $className, string $inputName, string|null $description, bool $isUpdate): InputType { if (! isset($this->inputCache[$inputName])) { $this->inputCache[$inputName] = new InputType( @@ -66,7 +64,7 @@ public function mapInput(string $className, string $inputName, ?string $descript $description, $isUpdate, $this->fieldsBuilder, - $this->inputTypeValidator + $this->inputTypeValidator, ); } @@ -96,9 +94,7 @@ public static function canBeInstantiatedWithoutParameter(ReflectionFunctionAbstr return true; } - /** - * @param ResolvableMutableInputInterface&InputObjectType $inputType - */ + /** @param ResolvableMutableInputInterface&InputObjectType $inputType */ public function decorateInputType(string $className, string $methodName, ResolvableMutableInputInterface $inputType, ContainerInterface $container): void { $method = new ReflectionMethod($className, $methodName); diff --git a/src/InputTypeUtils.php b/src/InputTypeUtils.php index 7bc4b48358..56b6fe7718 100644 --- a/src/InputTypeUtils.php +++ b/src/InputTypeUtils.php @@ -26,7 +26,7 @@ class InputTypeUtils { public function __construct( private AnnotationReader $annotationReader, - private NamingStrategyInterface $namingStrategy + private NamingStrategyInterface $namingStrategy, ) { } @@ -38,9 +38,7 @@ public function __construct( */ public function getInputTypeNameAndClassName(ReflectionMethod $method): array { - /** - * @var class-string - */ + /** @var class-string */ $fqsen = ltrim((string) $this->validateReturnType($method), '\\'); $factory = $this->annotationReader->getFactoryAnnotation($method); if ($factory === null) { diff --git a/src/Mappers/AbstractTypeMapper.php b/src/Mappers/AbstractTypeMapper.php index 08cf95f434..60828ee63f 100644 --- a/src/Mappers/AbstractTypeMapper.php +++ b/src/Mappers/AbstractTypeMapper.php @@ -49,8 +49,8 @@ abstract class AbstractTypeMapper implements TypeMapperInterface private ClassBoundCacheContractInterface $mapClassToExtendAnnotationsCache; private CacheContractInterface $cacheContract; - private ?GlobTypeMapperCache $globTypeMapperCache = null; - private ?GlobExtendTypeMapperCache $globExtendTypeMapperCache = null; + private GlobTypeMapperCache|null $globTypeMapperCache = null; + private GlobExtendTypeMapperCache|null $globExtendTypeMapperCache = null; /** @var array> */ private array $registeredInputs; @@ -64,8 +64,8 @@ public function __construct( private NamingStrategyInterface $namingStrategy, private RecursiveTypeMapperInterface $recursiveTypeMapper, private CacheInterface $cache, - protected ?int $globTTL = 2, - private ?int $mapTTL = null + protected int|null $globTTL = 2, + private int|null $mapTTL = null, ) { $this->cacheContract = new Psr16Adapter($this->cache, $cachePrefix, $this->globTTL ?? 0); @@ -249,7 +249,7 @@ public function canMapClassToType(string $className): bool * * @throws CannotMapTypeExceptionInterface */ - public function mapClassToType(string $className, ?OutputType $subType): MutableInterface + public function mapClassToType(string $className, OutputType|null $subType): MutableInterface { /** @var class-string|null $inputTypeClassName */ $inputTypeClassName = $this->getMaps()->getInputByObjectClass($className) diff --git a/src/Mappers/CannotMapTypeException.php b/src/Mappers/CannotMapTypeException.php index eb8132b833..7ea34ea8cf 100644 --- a/src/Mappers/CannotMapTypeException.php +++ b/src/Mappers/CannotMapTypeException.php @@ -29,17 +29,13 @@ class CannotMapTypeException extends Exception implements CannotMapTypeException { use CannotMapTypeTrait; - /** - * @param class-string $className - */ + /** @param class-string $className */ public static function createForType(string $className): self { return new self('cannot map class "' . $className . '" to a known GraphQL type. Check your TypeMapper configuration.'); } - /** - * @param class-string $className - */ + /** @param class-string $className */ public static function createForInputType(string $className): self { return new self('cannot map class "' . $className . '" to a known GraphQL input type. Are you missing a @Factory annotation? If you have a @Factory annotation, is it in a namespace analyzed by GraphQLite?'); @@ -55,15 +51,13 @@ public static function createForParseError(Error $error): self return new self($error->getMessage(), $error->getCode(), $error); } - /** - * @param class-string $className - */ + /** @param class-string $className */ public static function createForMissingIteratorValue(string $className, self $e): self { $message = sprintf( '"%s" is iterable. Please provide a more specific type. For instance: %s|User[].', $className, - $className + $className, ); return new self($message, 0, $e); @@ -124,18 +118,14 @@ public static function createForDecorateName(string $name, InputObjectType $type return new self('cannot decorate GraphQL input type "' . $type->name . '" with type "' . $name . '". Check your TypeMapper configuration.'); } - /** - * @param class-string $className - */ + /** @param class-string $className */ public static function extendTypeWithBadTargetedClass(string $className, ExtendType $extendType): self { return new self('For ' . self::extendTypeToString($extendType) . ' annotation declared in class "' . $className . '", the pointed at GraphQL type cannot be extended. You can only target types extending the MutableObjectType (like types created with the @Type annotation).'); } - /** - * @param Array_|Iterable_|Object_|Mixed_ $type - */ - public static function createForMissingPhpDoc(PhpDocumentorType $type, ReflectionMethod|ReflectionProperty $reflector, ?string $argumentName = null): self + /** @param Array_|Iterable_|Object_|Mixed_ $type */ + public static function createForMissingPhpDoc(PhpDocumentorType $type, ReflectionMethod|ReflectionProperty $reflector, string|null $argumentName = null): self { $typeStr = ''; if ($type instanceof Array_) { diff --git a/src/Mappers/CannotMapTypeExceptionInterface.php b/src/Mappers/CannotMapTypeExceptionInterface.php index 7d0781b2c7..e3a947e12c 100644 --- a/src/Mappers/CannotMapTypeExceptionInterface.php +++ b/src/Mappers/CannotMapTypeExceptionInterface.php @@ -11,22 +11,16 @@ use TheCodingMachine\GraphQLite\Annotations\SourceFieldInterface; use Throwable; -/** - * @unstable See https://graphqlite.thecodingmachine.io/docs/semver.html - */ +/** @unstable See https://graphqlite.thecodingmachine.io/docs/semver.html */ interface CannotMapTypeExceptionInterface extends Throwable { public function addParamInfo(ReflectionParameter $parameter): void; public function addReturnInfo(ReflectionMethod $method): void; - /** - * @param ReflectionClass $class - */ + /** @param ReflectionClass $class */ public function addSourceFieldInfo(ReflectionClass $class, SourceFieldInterface $sourceField): void; - /** - * @param ReflectionClass $class - */ + /** @param ReflectionClass $class */ public function addExtendTypeInfo(ReflectionClass $class, ExtendType $extendType): void; } diff --git a/src/Mappers/CannotMapTypeTrait.php b/src/Mappers/CannotMapTypeTrait.php index c872bc284c..b200316840 100644 --- a/src/Mappers/CannotMapTypeTrait.php +++ b/src/Mappers/CannotMapTypeTrait.php @@ -34,7 +34,7 @@ public function addParamInfo(ReflectionParameter $parameter): void $parameter->getName(), $declaringClass->getName(), $parameter->getDeclaringFunction()->getName(), - $this->message + $this->message, ); } @@ -49,13 +49,11 @@ public function addReturnInfo(ReflectionMethod $method): void 'For return type of %s::%s, %s', $method->getDeclaringClass()->getName(), $method->getName(), - $this->message + $this->message, ); } - /** - * @param ReflectionClass $class - */ + /** @param ReflectionClass $class */ public function addSourceFieldInfo(ReflectionClass $class, SourceFieldInterface $sourceField): void { if ($this->locationInfoAdded !== false) { @@ -67,13 +65,11 @@ public function addSourceFieldInfo(ReflectionClass $class, SourceFieldInterface 'For @SourceField "%s" declared in "%s", %s', $sourceField->getName(), $class->getName(), - $this->message + $this->message, ); } - /** - * @param ReflectionClass $class - */ + /** @param ReflectionClass $class */ public function addExtendTypeInfo(ReflectionClass $class, ExtendType $extendType): void { if ($this->locationInfoAdded !== false) { diff --git a/src/Mappers/CompositeTypeMapper.php b/src/Mappers/CompositeTypeMapper.php index 2f0e693ce2..44302d6ca2 100644 --- a/src/Mappers/CompositeTypeMapper.php +++ b/src/Mappers/CompositeTypeMapper.php @@ -27,7 +27,7 @@ class CompositeTypeMapper implements TypeMapperInterface * * @var array */ - private ?array $supportedClasses = null; + private array|null $supportedClasses = null; public function addTypeMapper(TypeMapperInterface $typeMapper): void { @@ -58,7 +58,7 @@ public function canMapClassToType(string $className): bool * * @throws CannotMapTypeExceptionInterface */ - public function mapClassToType(string $className, ?OutputType $subType): MutableInterface + public function mapClassToType(string $className, OutputType|null $subType): MutableInterface { foreach ($this->typeMappers as $typeMapper) { if ($typeMapper->canMapClassToType($className)) { diff --git a/src/Mappers/DuplicateMappingException.php b/src/Mappers/DuplicateMappingException.php index 1e8d149a62..d37d15a95c 100644 --- a/src/Mappers/DuplicateMappingException.php +++ b/src/Mappers/DuplicateMappingException.php @@ -32,9 +32,7 @@ public static function createForTypeName(string $type, string $sourceClass1, str throw new self(sprintf("The type '%s' is created by 2 different classes: '%s' and '%s'", $type, $sourceClass1, $sourceClass2)); } - /** - * @return static - */ + /** @return static */ public static function createForQuery(string $sourceClass, string $queryName, ReflectionMethod|ReflectionProperty $firstReflector, ReflectionMethod|ReflectionProperty $secondReflector): self { $firstName = sprintf('%s::%s', $firstReflector->getDeclaringClass()->getName(), $firstReflector->getName()); @@ -65,9 +63,7 @@ public static function createForQueryInOneProperty(string $queryName, Reflection throw new self(sprintf("The query/mutation/field '%s' is declared twice in '%s::%s'", $queryName, $property->getDeclaringClass()->getName(), $property->getName())); } - /** - * @return static - */ + /** @return static */ public static function createForDefaultInput(string $sourceClass): self { throw new self(sprintf("The class '%s' should be mapped to only one GraphQL Input type as default. Two default inputs are declared as default via @Input annotation.", $sourceClass)); diff --git a/src/Mappers/GlobAnnotationsCache.php b/src/Mappers/GlobAnnotationsCache.php index 551b668e33..207fc08401 100644 --- a/src/Mappers/GlobAnnotationsCache.php +++ b/src/Mappers/GlobAnnotationsCache.php @@ -14,9 +14,9 @@ final class GlobAnnotationsCache { /** @var class-string|null */ - private ?string $typeClassName = null; + private string|null $typeClassName = null; - private ?string $typeName = null; + private string|null $typeName = null; private bool $default; @@ -29,9 +29,7 @@ final class GlobAnnotationsCache /** @var array, 1: bool, 2: string|null, 3: bool}> An array mapping an input type name to an input name / declaring class */ private array $inputs = []; - /** - * @param class-string $className - */ + /** @param class-string $className */ public function setType(string $className, string $typeName, bool $isDefault): void { $this->typeClassName = $className; @@ -39,15 +37,13 @@ public function setType(string $className, string $typeName, bool $isDefault): v $this->default = $isDefault; } - /** - * @return class-string|null - */ - public function getTypeClassName(): ?string + /** @return class-string|null */ + public function getTypeClassName(): string|null { return $this->typeClassName; } - public function getTypeName(): ?string + public function getTypeName(): string|null { return $this->typeName; } @@ -61,30 +57,24 @@ public function isDefault(): bool * @param class-string|null $className * @param class-string $declaringClass */ - public function registerFactory(string $methodName, string $inputName, ?string $className, bool $isDefault, string $declaringClass): void + public function registerFactory(string $methodName, string $inputName, string|null $className, bool $isDefault, string $declaringClass): void { $this->factories[$methodName] = [$inputName, $className, $isDefault, $declaringClass]; } - /** - * @param class-string $declaringClass - */ + /** @param class-string $declaringClass */ public function registerDecorator(string $methodName, string $inputName, string $declaringClass): void { $this->decorators[$methodName] = [$inputName, $declaringClass]; } - /** - * @return array|null, 2:bool, 3:class-string}> - */ + /** @return array|null, 2:bool, 3:class-string}> */ public function getFactories(): array { return $this->factories; } - /** - * @return array}> - */ + /** @return array}> */ public function getDecorators(): array { return $this->decorators; diff --git a/src/Mappers/GlobExtendAnnotationsCache.php b/src/Mappers/GlobExtendAnnotationsCache.php index 4bf6c25021..d99bf1e47b 100644 --- a/src/Mappers/GlobExtendAnnotationsCache.php +++ b/src/Mappers/GlobExtendAnnotationsCache.php @@ -11,17 +11,17 @@ */ class GlobExtendAnnotationsCache { - private ?string $extendTypeClassName = null; + private string|null $extendTypeClassName = null; private string $extendTypeName; - public function setExtendType(?string $className, string $typeName): void + public function setExtendType(string|null $className, string $typeName): void { $this->extendTypeClassName = $className; $this->extendTypeName = $typeName; } - public function getExtendTypeClassName(): ?string + public function getExtendTypeClassName(): string|null { return $this->extendTypeClassName; } diff --git a/src/Mappers/GlobExtendTypeMapperCache.php b/src/Mappers/GlobExtendTypeMapperCache.php index a6e4e2ca81..590fe49220 100644 --- a/src/Mappers/GlobExtendTypeMapperCache.php +++ b/src/Mappers/GlobExtendTypeMapperCache.php @@ -34,18 +34,14 @@ public function registerAnnotations(ReflectionClass $refClass, GlobExtendAnnotat $this->mapNameToExtendType[$typeName][$className] = $className; } - /** - * @return array|null An array of classes with the @ExtendType annotation (key and value = FQCN) - */ - public function getExtendTypesByObjectClass(string $className): ?array + /** @return array|null An array of classes with the @ExtendType annotation (key and value = FQCN) */ + public function getExtendTypesByObjectClass(string $className): array|null { return $this->mapClassToExtendTypeArray[$className] ?? null; } - /** - * @return array|null An array of classes with the @ExtendType annotation (key and value = FQCN) - */ - public function getExtendTypesByGraphQLTypeName(string $graphqlTypeName): ?array + /** @return array|null An array of classes with the @ExtendType annotation (key and value = FQCN) */ + public function getExtendTypesByGraphQLTypeName(string $graphqlTypeName): array|null { return $this->mapNameToExtendType[$graphqlTypeName] ?? null; } diff --git a/src/Mappers/GlobTypeMapper.php b/src/Mappers/GlobTypeMapper.php index 4d8d127c94..e8dc017381 100644 --- a/src/Mappers/GlobTypeMapper.php +++ b/src/Mappers/GlobTypeMapper.php @@ -26,10 +26,8 @@ */ final class GlobTypeMapper extends AbstractTypeMapper { - /** - * @param NS $namespace The namespace that contains the GraphQL types (they must have a `@Type` annotation) - */ - public function __construct(private NS $namespace, TypeGenerator $typeGenerator, InputTypeGenerator $inputTypeGenerator, InputTypeUtils $inputTypeUtils, ContainerInterface $container, AnnotationReader $annotationReader, NamingStrategyInterface $namingStrategy, RecursiveTypeMapperInterface $recursiveTypeMapper, CacheInterface $cache, ?int $globTTL = 2, ?int $mapTTL = null) + /** @param NS $namespace The namespace that contains the GraphQL types (they must have a `@Type` annotation) */ + public function __construct(private NS $namespace, TypeGenerator $typeGenerator, InputTypeGenerator $inputTypeGenerator, InputTypeUtils $inputTypeUtils, ContainerInterface $container, AnnotationReader $annotationReader, NamingStrategyInterface $namingStrategy, RecursiveTypeMapperInterface $recursiveTypeMapper, CacheInterface $cache, int|null $globTTL = 2, int|null $mapTTL = null) { $cachePrefix = str_replace(['\\', '{', '}', '(', ')', '/', '@', ':'], '_', $namespace->getNamespace()); parent::__construct($cachePrefix, $typeGenerator, $inputTypeGenerator, $inputTypeUtils, $container, $annotationReader, $namingStrategy, $recursiveTypeMapper, $cache, $globTTL, $mapTTL); diff --git a/src/Mappers/GlobTypeMapperCache.php b/src/Mappers/GlobTypeMapperCache.php index 448ed8973d..24be49646c 100644 --- a/src/Mappers/GlobTypeMapperCache.php +++ b/src/Mappers/GlobTypeMapperCache.php @@ -91,63 +91,49 @@ public function registerAnnotations(ReflectionClass $refClass, GlobAnnotationsCa * * @return class-string|null */ - public function getTypeByObjectClass(string $className): ?string + public function getTypeByObjectClass(string $className): string|null { return $this->mapClassToTypeArray[$className] ?? null; } - /** - * @return class-string[] - */ + /** @return class-string[] */ public function getSupportedClasses(): array { return array_keys($this->mapClassToTypeArray); } - /** - * @return class-string|null - */ - public function getTypeByGraphQLTypeName(string $graphqlTypeName): ?string + /** @return class-string|null */ + public function getTypeByGraphQLTypeName(string $graphqlTypeName): string|null { return $this->mapNameToType[$graphqlTypeName] ?? null; } - /** - * @return array|null Maps a GraphQL input type name to the factory method that creates the input type in the form [classname, methodname] - */ - public function getFactoryByGraphQLInputTypeName(string $graphqlTypeName): ?array + /** @return array|null Maps a GraphQL input type name to the factory method that creates the input type in the form [classname, methodname] */ + public function getFactoryByGraphQLInputTypeName(string $graphqlTypeName): array|null { return $this->mapInputNameToFactory[$graphqlTypeName] ?? null; } - /** - * @return array|null A pointer to the decorators methods [$className, $methodName] or null on cache miss - */ - public function getDecorateByGraphQLInputTypeName(string $graphqlTypeName): ?array + /** @return array|null A pointer to the decorators methods [$className, $methodName] or null on cache miss */ + public function getDecorateByGraphQLInputTypeName(string $graphqlTypeName): array|null { return $this->mapInputNameToDecorator[$graphqlTypeName] ?? null; } - /** - * @return string[]|null A pointer to the factory [$className, $methodName] or null on cache miss - */ - public function getFactoryByObjectClass(string $className): ?array + /** @return string[]|null A pointer to the factory [$className, $methodName] or null on cache miss */ + public function getFactoryByObjectClass(string $className): array|null { return $this->mapClassToFactory[$className] ?? null; } - /** - * @return array{0: class-string, 1: string|null, 2: bool}|null - */ - public function getInputByGraphQLInputTypeName(string $graphqlTypeName): ?array + /** @return array{0: class-string, 1: string|null, 2: bool}|null */ + public function getInputByGraphQLInputTypeName(string $graphqlTypeName): array|null { return $this->mapNameToInput[$graphqlTypeName] ?? null; } - /** - * @return array{0: class-string, 1: string, 2: string|null, 3: bool}|null - */ - public function getInputByObjectClass(string $className): ?array + /** @return array{0: class-string, 1: string, 2: string|null, 3: bool}|null */ + public function getInputByObjectClass(string $className): array|null { return $this->mapClassToInput[$className] ?? null; } diff --git a/src/Mappers/MappedClass.php b/src/Mappers/MappedClass.php index 41d09d42a6..96efdc1044 100644 --- a/src/Mappers/MappedClass.php +++ b/src/Mappers/MappedClass.php @@ -6,14 +6,10 @@ class MappedClass { - /** - * @var string - */ + /** @var string */ //private $className; - /** - * @var MappedClass|null - */ + /** @var MappedClass|null */ //private $parent; /** @var MappedClass[] */ @@ -24,33 +20,25 @@ class MappedClass $this->className = $className; }*/ - /** - * @return string - */ + /** @return string */ /*public function getClassName(): string { return $this->className; }*/ - /** - * @return MappedClass|null - */ + /** @return MappedClass|null */ /*public function getParent(): ?MappedClass { return $this->parent; }*/ - /** - * @param MappedClass|null $parent - */ + /** @param MappedClass|null $parent */ /*public function setParent(?MappedClass $parent): void { $this->parent = $parent; }*/ - /** - * @return MappedClass[] - */ + /** @return MappedClass[] */ public function getChildren(): array { return $this->children; diff --git a/src/Mappers/Parameters/ContainerParameterHandler.php b/src/Mappers/Parameters/ContainerParameterHandler.php index fe9f5099fb..7988189d01 100644 --- a/src/Mappers/Parameters/ContainerParameterHandler.php +++ b/src/Mappers/Parameters/ContainerParameterHandler.php @@ -29,7 +29,7 @@ public function __construct(ContainerInterface $container) $this->container = $container; } - public function mapParameter(ReflectionParameter $parameter, DocBlock $docBlock, ?Type $paramTagType, ParameterAnnotations $parameterAnnotations, ParameterHandlerInterface $next): ParameterInterface + public function mapParameter(ReflectionParameter $parameter, DocBlock $docBlock, Type|null $paramTagType, ParameterAnnotations $parameterAnnotations, ParameterHandlerInterface $next): ParameterInterface { $autowire = $parameterAnnotations->getAnnotationByType(Autowire::class); diff --git a/src/Mappers/Parameters/InjectUserParameterHandler.php b/src/Mappers/Parameters/InjectUserParameterHandler.php index 3c03081864..d794544daa 100644 --- a/src/Mappers/Parameters/InjectUserParameterHandler.php +++ b/src/Mappers/Parameters/InjectUserParameterHandler.php @@ -22,7 +22,7 @@ public function __construct(private AuthenticationServiceInterface $authenticati { } - public function mapParameter(ReflectionParameter $parameter, DocBlock $docBlock, ?Type $paramTagType, ParameterAnnotations $parameterAnnotations, ParameterHandlerInterface $next): ParameterInterface + public function mapParameter(ReflectionParameter $parameter, DocBlock $docBlock, Type|null $paramTagType, ParameterAnnotations $parameterAnnotations, ParameterHandlerInterface $next): ParameterInterface { $injectUser = $parameterAnnotations->getAnnotationByType(InjectUser::class); diff --git a/src/Mappers/Parameters/Next.php b/src/Mappers/Parameters/Next.php index 0d46234cfd..c5da322614 100644 --- a/src/Mappers/Parameters/Next.php +++ b/src/Mappers/Parameters/Next.php @@ -31,7 +31,7 @@ public function __construct(SplQueue $queue, protected ParameterHandlerInterface $this->queue = clone $queue; } - public function mapParameter(ReflectionParameter $parameter, DocBlock $docBlock, ?Type $paramTagType, ParameterAnnotations $parameterAnnotations): ParameterInterface + public function mapParameter(ReflectionParameter $parameter, DocBlock $docBlock, Type|null $paramTagType, ParameterAnnotations $parameterAnnotations): ParameterInterface { if ($this->queue->isEmpty()) { return $this->fallbackHandler->mapParameter($parameter, $docBlock, $paramTagType, $parameterAnnotations); diff --git a/src/Mappers/Parameters/ParameterHandlerInterface.php b/src/Mappers/Parameters/ParameterHandlerInterface.php index 0e4b7340b1..26d7e2e55e 100644 --- a/src/Mappers/Parameters/ParameterHandlerInterface.php +++ b/src/Mappers/Parameters/ParameterHandlerInterface.php @@ -12,5 +12,5 @@ interface ParameterHandlerInterface { - public function mapParameter(ReflectionParameter $parameter, DocBlock $docBlock, ?Type $paramTagType, ParameterAnnotations $parameterAnnotations): ParameterInterface; + public function mapParameter(ReflectionParameter $parameter, DocBlock $docBlock, Type|null $paramTagType, ParameterAnnotations $parameterAnnotations): ParameterInterface; } diff --git a/src/Mappers/Parameters/ParameterMiddlewareInterface.php b/src/Mappers/Parameters/ParameterMiddlewareInterface.php index 7ed3ec4d33..7894634868 100644 --- a/src/Mappers/Parameters/ParameterMiddlewareInterface.php +++ b/src/Mappers/Parameters/ParameterMiddlewareInterface.php @@ -15,5 +15,5 @@ */ interface ParameterMiddlewareInterface { - public function mapParameter(ReflectionParameter $parameter, DocBlock $docBlock, ?Type $paramTagType, ParameterAnnotations $parameterAnnotations, ParameterHandlerInterface $next): ParameterInterface; + public function mapParameter(ReflectionParameter $parameter, DocBlock $docBlock, Type|null $paramTagType, ParameterAnnotations $parameterAnnotations, ParameterHandlerInterface $next): ParameterInterface; } diff --git a/src/Mappers/Parameters/ParameterMiddlewarePipe.php b/src/Mappers/Parameters/ParameterMiddlewarePipe.php index 2a2e325b9f..dd5a4ad06a 100644 --- a/src/Mappers/Parameters/ParameterMiddlewarePipe.php +++ b/src/Mappers/Parameters/ParameterMiddlewarePipe.php @@ -30,7 +30,7 @@ public function __construct() * Executes the internal pipeline, passing $handler as the "final * handler" in cases when the pipeline exhausts itself. */ - public function mapParameter(ReflectionParameter $parameter, DocBlock $docBlock, ?Type $paramTagType, ParameterAnnotations $parameterAnnotations, ParameterHandlerInterface $parameterMapper): ParameterInterface + public function mapParameter(ReflectionParameter $parameter, DocBlock $docBlock, Type|null $paramTagType, ParameterAnnotations $parameterAnnotations, ParameterHandlerInterface $parameterMapper): ParameterInterface { return (new Next($this->pipeline, $parameterMapper))->mapParameter($parameter, $docBlock, $paramTagType, $parameterAnnotations); } diff --git a/src/Mappers/Parameters/ResolveInfoParameterHandler.php b/src/Mappers/Parameters/ResolveInfoParameterHandler.php index 38cbd3e840..33e688cf77 100644 --- a/src/Mappers/Parameters/ResolveInfoParameterHandler.php +++ b/src/Mappers/Parameters/ResolveInfoParameterHandler.php @@ -17,7 +17,7 @@ class ResolveInfoParameterHandler implements ParameterMiddlewareInterface { - public function mapParameter(ReflectionParameter $parameter, DocBlock $docBlock, ?Type $paramTagType, ParameterAnnotations $parameterAnnotations, ParameterHandlerInterface $parameterMapper): ParameterInterface + public function mapParameter(ReflectionParameter $parameter, DocBlock $docBlock, Type|null $paramTagType, ParameterAnnotations $parameterAnnotations, ParameterHandlerInterface $parameterMapper): ParameterInterface { $type = $parameter->getType(); assert($type === null || $type instanceof ReflectionNamedType); diff --git a/src/Mappers/Parameters/TypeHandler.php b/src/Mappers/Parameters/TypeHandler.php index 3d28fdc5ae..810e971b39 100644 --- a/src/Mappers/Parameters/TypeHandler.php +++ b/src/Mappers/Parameters/TypeHandler.php @@ -65,15 +65,13 @@ class TypeHandler implements ParameterHandlerInterface public function __construct( private ArgumentResolver $argumentResolver, private RootTypeMapperInterface $rootTypeMapper, - private TypeResolver $typeResolver + private TypeResolver $typeResolver, ) { $this->phpDocumentorTypeResolver = new PhpDocumentorTypeResolver(); } - /** - * @return GraphQLType&OutputType - */ + /** @return GraphQLType&OutputType */ public function mapReturnType(ReflectionMethod $refMethod, DocBlock $docBlockObj): GraphQLType { $returnType = $refMethod->getReturnType(); @@ -92,7 +90,7 @@ public function mapReturnType(ReflectionMethod $refMethod, DocBlock $docBlockObj $returnType && $returnType->allowsNull(), false, $refMethod, - $docBlockObj + $docBlockObj, ); assert($type instanceof GraphQLType && $type instanceof OutputType); } catch (CannotMapTypeExceptionInterface $e) { @@ -103,7 +101,7 @@ public function mapReturnType(ReflectionMethod $refMethod, DocBlock $docBlockObj return $type; } - private function getDocBlocReturnType(DocBlock $docBlock, ReflectionMethod $refMethod): ?Type + private function getDocBlocReturnType(DocBlock $docBlock, ReflectionMethod $refMethod): Type|null { /** @var array $returnTypeTags */ $returnTypeTags = $docBlock->getTagsByName('return'); @@ -121,7 +119,7 @@ private function getDocBlocReturnType(DocBlock $docBlock, ReflectionMethod $refM /** * Gets property type from its dock block. */ - private function getDocBlockPropertyType(DocBlock $docBlock, ReflectionProperty $refProperty): ?Type + private function getDocBlockPropertyType(DocBlock $docBlock, ReflectionProperty $refProperty): Type|null { /** @var Var_[] $varTags */ $varTags = $docBlock->getTagsByName('var'); @@ -137,7 +135,7 @@ private function getDocBlockPropertyType(DocBlock $docBlock, ReflectionProperty return reset($varTags)->getType(); } - public function mapParameter(ReflectionParameter $parameter, DocBlock $docBlock, ?Type $paramTagType, ParameterAnnotations $parameterAnnotations): ParameterInterface + public function mapParameter(ReflectionParameter $parameter, DocBlock $docBlock, Type|null $paramTagType, ParameterAnnotations $parameterAnnotations): ParameterInterface { $hideParameter = $parameterAnnotations->getAnnotationByType(HideParameter::class); if ($hideParameter) { @@ -182,7 +180,7 @@ public function mapParameter(ReflectionParameter $parameter, DocBlock $docBlock, true, $declaringFunction, $docBlock, - $parameter->getName() + $parameter->getName(), ); assert($type instanceof InputType); } catch (CannotMapTypeExceptionInterface $e) { @@ -215,8 +213,8 @@ public function mapPropertyType( ReflectionProperty $refProperty, DocBlock $docBlock, bool $toInput, - ?string $argumentName = null, - ?bool $isNullable = null + string|null $argumentName = null, + bool|null $isNullable = null, ): GraphQLType { $propertyType = $refProperty->getType(); @@ -239,7 +237,7 @@ public function mapPropertyType( $toInput, $refProperty, $docBlock, - $argumentName + $argumentName, ); } @@ -251,10 +249,10 @@ public function mapPropertyType( public function mapInputProperty( ReflectionProperty $refProperty, DocBlock $docBlock, - ?string $argumentName = null, - ?string $inputTypeName = null, + string|null $argumentName = null, + string|null $inputTypeName = null, mixed $defaultValue = null, - ?bool $isNullable = null + bool|null $isNullable = null, ): InputTypeProperty { $docBlockComment = $docBlock->getSummary() . PHP_EOL . $docBlock->getDescription()->render(); @@ -307,12 +305,12 @@ public function mapInputProperty( */ private function mapType( Type $type, - ?Type $docBlockType, + Type|null $docBlockType, bool $isNullable, bool $mapToInputType, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj, - ?string $argumentName = null + string|null $argumentName = null, ): GraphQLType { $graphQlType = null; @@ -359,7 +357,7 @@ private function mapType( /** * Appends types together, eventually creating a Compound type and removing duplicates if any. */ - private function appendTypes(Type $type, ?Type $docBlockType): Type + private function appendTypes(Type $type, Type|null $docBlockType): Type { if ($docBlockType === null) { return $type; @@ -397,9 +395,7 @@ private function appendTypes(Type $type, ?Type $docBlockType): Type return new Compound($types); } - /** - * @param ReflectionClass $reflectionClass - */ + /** @param ReflectionClass $reflectionClass */ private function reflectionTypeToPhpDocType(ReflectionType $type, ReflectionClass $reflectionClass): Type { assert($type instanceof ReflectionNamedType || $type instanceof ReflectionUnionType); @@ -429,8 +425,8 @@ function ($namedType) use ($reflectionClass): Type { } return $phpdocType; }, - $type->getTypes() - ) + $type->getTypes(), + ), ); } diff --git a/src/Mappers/PorpaginasTypeMapper.php b/src/Mappers/PorpaginasTypeMapper.php index 24e18545d7..759556da08 100644 --- a/src/Mappers/PorpaginasTypeMapper.php +++ b/src/Mappers/PorpaginasTypeMapper.php @@ -49,7 +49,7 @@ public function canMapClassToType(string $className): bool * * @throws CannotMapTypeExceptionInterface */ - public function mapClassToType(string $className, ?OutputType $subType): MutableInterface + public function mapClassToType(string $className, OutputType|null $subType): MutableInterface { if (! $this->canMapClassToType($className)) { throw CannotMapTypeException::createForType($className); diff --git a/src/Mappers/RecursiveTypeMapper.php b/src/Mappers/RecursiveTypeMapper.php index fda089bc7a..31208fafe7 100644 --- a/src/Mappers/RecursiveTypeMapper.php +++ b/src/Mappers/RecursiveTypeMapper.php @@ -38,14 +38,12 @@ */ class RecursiveTypeMapper implements RecursiveTypeMapperInterface { - private TypeMapperInterface $typeMapper; - /** * An array mapping a class name to the MappedClass instance (useful to know if the class has children) * * @var array,MappedClass>|null */ - private ?array $mappedClasses = null; + private array|null $mappedClasses = null; /** * An array of interfaces OR object types if no interface matching. @@ -60,38 +58,20 @@ class RecursiveTypeMapper implements RecursiveTypeMapperInterface /** @var array Key: FQCN */ private array $classToInputTypeCache = []; - private NamingStrategyInterface $namingStrategy; - - private CacheInterface $cache; - - private ?int $ttl = null; - /** @var array> An array mapping a GraphQL interface name to the PHP class name that triggered its generation. */ - private ?array $interfaceToClassNameMap = null; - - private TypeRegistry $typeRegistry; - - private AnnotationReader $annotationReader; + private array|null $interfaceToClassNameMap = null; public function __construct( - TypeMapperInterface $typeMapper, - NamingStrategyInterface $namingStrategy, - CacheInterface $cache, - TypeRegistry $typeRegistry, - AnnotationReader $annotationReader, - ?int $ttl = null + private TypeMapperInterface $typeMapper, + private NamingStrategyInterface $namingStrategy, + private CacheInterface $cache, + private TypeRegistry $typeRegistry, + private AnnotationReader $annotationReader, + private int|null $ttl = null, ) { - $this->typeMapper = $typeMapper; - $this->namingStrategy = $namingStrategy; - $this->cache = $cache; - $this->ttl = $ttl; - $this->typeRegistry = $typeRegistry; - $this->annotationReader = $annotationReader; } - /** - * @return array,MappedClass> - */ + /** @return array,MappedClass> */ private function getClassTree(): array { if ($this->mappedClasses === null) { @@ -230,7 +210,7 @@ public function getGeneratedObjectTypeFromInterfaceType(MutableInterfaceType $ty * * @return class-string|null */ - public function findClosestMatchingParent(string $className): ?string + public function findClosestMatchingParent(string $className): string|null { do { if ($this->typeMapper->canMapClassToType($className)) { @@ -238,7 +218,7 @@ public function findClosestMatchingParent(string $className): ?string } try { $className = get_parent_class($className); - } catch (TypeError $exception) { + } catch (TypeError) { return null; } } while ($className); @@ -257,9 +237,7 @@ public function findInterfaces(string $className): array { $interfaces = []; - /** - * @var array> - */ + /** @var array> */ $implements = class_implements($className); foreach ($implements as $interface) { if (! $this->typeMapper->canMapClassToType($interface)) { @@ -304,7 +282,7 @@ public function canMapClassToType(string $className): bool * * @throws CannotMapTypeExceptionInterface */ - public function mapClassToType(string $className, ?OutputType $subType): MutableObjectType + public function mapClassToType(string $className, OutputType|null $subType): MutableObjectType { $cacheKey = $className; if ($subType !== null) { @@ -367,7 +345,7 @@ public function mapClassToType(string $className, ?OutputType $subType): Mutable * * @throws CannotMapTypeExceptionInterface */ - public function mapClassToInterfaceOrType(string $className, ?OutputType $subType): OutputType + public function mapClassToInterfaceOrType(string $className, OutputType|null $subType): OutputType { $closestClassName = $this->findClosestMatchingParent($className); if ($closestClassName === null) { diff --git a/src/Mappers/RecursiveTypeMapperInterface.php b/src/Mappers/RecursiveTypeMapperInterface.php index 430a30331a..8847f80650 100644 --- a/src/Mappers/RecursiveTypeMapperInterface.php +++ b/src/Mappers/RecursiveTypeMapperInterface.php @@ -37,7 +37,7 @@ public function canMapClassToType(string $className): bool; * * @throws CannotMapTypeExceptionInterface */ - public function mapClassToType(string $className, ?OutputType $subType): MutableObjectType; + public function mapClassToType(string $className, OutputType|null $subType): MutableObjectType; /** * Maps a PHP fully qualified class name to a GraphQL interface (or returns null if no interface is found). @@ -49,7 +49,7 @@ public function mapClassToType(string $className, ?OutputType $subType): Mutable * * @throws CannotMapTypeExceptionInterface */ - public function mapClassToInterfaceOrType(string $className, ?OutputType $subType): OutputType; + public function mapClassToInterfaceOrType(string $className, OutputType|null $subType): OutputType; /** * Finds the list of interfaces returned by $className. @@ -99,7 +99,7 @@ public function mapNameToType(string $typeName): Type; /** * Returns the closest parent that can be mapped, or null if nothing can be matched. */ - public function findClosestMatchingParent(string $className): ?string; + public function findClosestMatchingParent(string $className): string|null; /** * Generates an object type from an interface type (in case no object type maps this interface) diff --git a/src/Mappers/Root/BaseTypeMapper.php b/src/Mappers/Root/BaseTypeMapper.php index d8e24fd32b..19e8b03d3d 100644 --- a/src/Mappers/Root/BaseTypeMapper.php +++ b/src/Mappers/Root/BaseTypeMapper.php @@ -49,10 +49,8 @@ public function __construct(private RootTypeMapperInterface $next, private Recur { } - /** - * @throws CannotMapTypeExceptionInterface - */ - public function toGraphQLOutputType(Type $type, ?OutputType $subType, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): OutputType + /** @throws CannotMapTypeExceptionInterface */ + public function toGraphQLOutputType(Type $type, OutputType|null $subType, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): OutputType { $mappedType = $this->mapBaseType($type); if ($mappedType !== null) { @@ -80,7 +78,7 @@ public function toGraphQLOutputType(Type $type, ?OutputType $subType, Reflection * @throws CannotMapTypeException * @throws CannotMapTypeExceptionInterface */ - public function toGraphQLInputType(Type $type, null|InputType|GraphQLType $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType|GraphQLType + public function toGraphQLInputType(Type $type, InputType|GraphQLType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType|GraphQLType { $mappedType = $this->mapBaseType($type); if ($mappedType !== null) { @@ -151,7 +149,7 @@ private function mapBaseType(Type $type): BooleanType|FloatType|IDType|IntType|S return null; } - private static ?UploadType $uploadType = null; + private static UploadType|null $uploadType = null; private static function getUploadType(): UploadType { @@ -162,7 +160,7 @@ private static function getUploadType(): UploadType return self::$uploadType; } - private static ?DateTimeType $dateTimeType = null; + private static DateTimeType|null $dateTimeType = null; private static function getDateTimeType(): DateTimeType { diff --git a/src/Mappers/Root/CompoundTypeMapper.php b/src/Mappers/Root/CompoundTypeMapper.php index fc5e7c8706..2780769356 100644 --- a/src/Mappers/Root/CompoundTypeMapper.php +++ b/src/Mappers/Root/CompoundTypeMapper.php @@ -42,7 +42,7 @@ public function __construct(private RootTypeMapperInterface $next, private RootT { } - public function toGraphQLOutputType(Type $type, ?OutputType $subType, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): OutputType + public function toGraphQLOutputType(Type $type, OutputType|null $subType, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): OutputType { if (! $type instanceof Compound) { return $this->next->toGraphQLOutputType($type, $subType, $reflector, $docBlockObj); @@ -81,7 +81,7 @@ public function toGraphQLOutputType(Type $type, ?OutputType $subType, Reflection return $return; } - public function toGraphQLInputType(Type $type, null|InputType|GraphQLType $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType|GraphQLType + public function toGraphQLInputType(Type $type, InputType|GraphQLType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType|GraphQLType { if (! $type instanceof Compound) { return $this->next->toGraphQLInputType($type, $subType, $argumentName, $reflector, $docBlockObj); diff --git a/src/Mappers/Root/EnumTypeMapper.php b/src/Mappers/Root/EnumTypeMapper.php index fe53558768..434f901430 100644 --- a/src/Mappers/Root/EnumTypeMapper.php +++ b/src/Mappers/Root/EnumTypeMapper.php @@ -34,16 +34,14 @@ class EnumTypeMapper implements RootTypeMapperInterface /** @var array */ private array $cacheByName = []; /** @var array> */ - private ?array $nameToClassMapping = null; + private array|null $nameToClassMapping = null; - /** - * @param NS[] $namespaces List of namespaces containing enums. Used when searching an enum by name. - */ + /** @param NS[] $namespaces List of namespaces containing enums. Used when searching an enum by name. */ public function __construct( private RootTypeMapperInterface $next, private AnnotationReader $annotationReader, private CacheInterface $cacheService, - private array $namespaces + private array $namespaces, ) { } @@ -54,9 +52,9 @@ public function __construct( */ public function toGraphQLOutputType( Type $type, - ?OutputType $subType, + OutputType|null $subType, ReflectionMethod|ReflectionProperty $reflector, - DocBlock $docBlockObj + DocBlock $docBlockObj, ): OutputType { $result = $this->map($type); return $result ?? $this->next->toGraphQLOutputType($type, $subType, $reflector, $docBlockObj); @@ -67,10 +65,10 @@ public function toGraphQLOutputType( */ public function toGraphQLInputType( Type $type, - null|InputType|GraphQLType $subType, + InputType|GraphQLType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, - DocBlock $docBlockObj + DocBlock $docBlockObj, ): InputType|GraphQLType { $result = $this->map($type); @@ -81,7 +79,7 @@ public function toGraphQLInputType( return $result; } - private function map(Type $type): ?EnumType + private function map(Type $type): EnumType|null { if (! $type instanceof Object_) { return null; @@ -97,10 +95,8 @@ private function map(Type $type): ?EnumType return $this->mapByClassName($enumClass); } - /** - * @param class-string $enumClass - */ - private function mapByClassName(string $enumClass): ?EnumType + /** @param class-string $enumClass */ + private function mapByClassName(string $enumClass): EnumType|null { if (isset($this->cache[$enumClass])) { return $this->cache[$enumClass]; @@ -117,7 +113,7 @@ private function mapByClassName(string $enumClass): ?EnumType $reflectionEnum = new ReflectionEnum($enumClass); $typeAnnotation = $this->annotationReader->getTypeAnnotation($reflectionEnum); - $typeName = ($typeAnnotation !== null ? $typeAnnotation->getName() : null) ?? $reflectionEnum->getShortName(); + $typeName = $typeAnnotation?->getName() ?? $reflectionEnum->getShortName(); // Expose values instead of names if specifically configured to and if enum is string-backed $useValues = $typeAnnotation !== null && @@ -134,7 +130,7 @@ private function getTypeName(ReflectionClass $reflectionClass): string { $typeAnnotation = $this->annotationReader->getTypeAnnotation($reflectionClass); - return ($typeAnnotation !== null ? $typeAnnotation->getName() : null) ?? $reflectionClass->getShortName(); + return $typeAnnotation?->getName() ?? $reflectionClass->getShortName(); } /** diff --git a/src/Mappers/Root/FinalRootTypeMapper.php b/src/Mappers/Root/FinalRootTypeMapper.php index fabfc6ac44..a9cceb5c99 100644 --- a/src/Mappers/Root/FinalRootTypeMapper.php +++ b/src/Mappers/Root/FinalRootTypeMapper.php @@ -34,15 +34,13 @@ public function __construct(private RecursiveTypeMapperInterface $recursiveTypeM * * @throws CannotMapTypeException */ - public function toGraphQLOutputType(Type $type, ?OutputType $subType, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): OutputType + public function toGraphQLOutputType(Type $type, OutputType|null $subType, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): OutputType { throw CannotMapTypeException::createForPhpDocType($type); } - /** - * @throws CannotMapTypeException - */ - public function toGraphQLInputType(Type $type, null|InputType|GraphQLType $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType|GraphQLType + /** @throws CannotMapTypeException */ + public function toGraphQLInputType(Type $type, InputType|GraphQLType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType|GraphQLType { throw CannotMapTypeException::createForPhpDocType($type); } diff --git a/src/Mappers/Root/IteratorTypeMapper.php b/src/Mappers/Root/IteratorTypeMapper.php index c274b70a4c..fe6978e867 100644 --- a/src/Mappers/Root/IteratorTypeMapper.php +++ b/src/Mappers/Root/IteratorTypeMapper.php @@ -38,16 +38,14 @@ public function __construct(private RootTypeMapperInterface $next, private RootT { } - public function toGraphQLOutputType(Type $type, ?OutputType $subType, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): OutputType + public function toGraphQLOutputType(Type $type, OutputType|null $subType, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): OutputType { if (! $type instanceof Compound) { try { return $this->next->toGraphQLOutputType($type, $subType, $reflector, $docBlockObj); } catch (CannotMapTypeException $e) { if ($type instanceof Object_) { - /** - * @var class-string - */ + /** @var class-string $fqcn */ $fqcn = (string) $type->getFqsen(); $refClass = new ReflectionClass($fqcn); // Note : $refClass->isIterable() is only accessible in PHP 7.2 @@ -59,7 +57,7 @@ public function toGraphQLOutputType(Type $type, ?OutputType $subType, Reflection } } - $result = $this->toGraphQLType($type, function (Type $type, ?OutputType $subType) use ($reflector, $docBlockObj) { + $result = $this->toGraphQLType($type, function (Type $type, OutputType|null $subType) use ($reflector, $docBlockObj) { return $this->topRootTypeMapper->toGraphQLOutputType($type, $subType, $reflector, $docBlockObj); }, true); @@ -72,7 +70,7 @@ public function toGraphQLOutputType(Type $type, ?OutputType $subType, Reflection return $result; } - public function toGraphQLInputType(Type $type, null|InputType|GraphQLType $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType|GraphQLType + public function toGraphQLInputType(Type $type, InputType|GraphQLType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType|GraphQLType { if (! $type instanceof Compound) { //try { @@ -83,7 +81,7 @@ public function toGraphQLInputType(Type $type, null|InputType|GraphQLType $subTy }*/ } - $result = $this->toGraphQLType($type, function (Type $type, ?InputType $subType) use ($reflector, $docBlockObj, $argumentName) { + $result = $this->toGraphQLType($type, function (Type $type, InputType|null $subType) use ($reflector, $docBlockObj, $argumentName) { $topType = $this->topRootTypeMapper->toGraphQLInputType($type, $subType, $argumentName, $reflector, $docBlockObj); if ($topType instanceof NonNull) { $topType = $topType->getWrappedType(); @@ -113,7 +111,7 @@ public function mapNameToType(string $typeName): NamedType /** * Resolves a list type. */ - private function getTypeInArray(Type $typeHint): ?Type + private function getTypeInArray(Type $typeHint): Type|null { if (! $typeHint instanceof Array_) { return null; @@ -173,7 +171,7 @@ private function toGraphQLType(Compound $type, Closure $topToGraphQLType, bool $ // We have an issue, let's try without the subType try { $result = $topToGraphQLType($iteratorType, null); - } catch (CannotMapTypeExceptionInterface $otherException) { + } catch (CannotMapTypeExceptionInterface) { // Still an issue? Let's rethrow the previous exception. throw $lastException; } @@ -206,7 +204,7 @@ private function toGraphQLType(Compound $type, Closure $topToGraphQLType, bool $ * * @param Type[] $types */ - private function splitIteratorFromOtherTypes(array &$types): ?Type + private function splitIteratorFromOtherTypes(array &$types): Type|null { $iteratorType = null; $key = null; @@ -215,9 +213,7 @@ private function splitIteratorFromOtherTypes(array &$types): ?Type continue; } - /** - * @var class-string - */ + /** @var class-string */ $fqcn = (string) $singleDocBlockType->getFqsen(); $refClass = new ReflectionClass($fqcn); // Note : $refClass->isIterable() is only accessible in PHP 7.2 diff --git a/src/Mappers/Root/MyCLabsEnumTypeMapper.php b/src/Mappers/Root/MyCLabsEnumTypeMapper.php index cad8b5ebe6..5d9630c278 100644 --- a/src/Mappers/Root/MyCLabsEnumTypeMapper.php +++ b/src/Mappers/Root/MyCLabsEnumTypeMapper.php @@ -35,26 +35,24 @@ class MyCLabsEnumTypeMapper implements RootTypeMapperInterface /** @var array */ private array $cacheByName = []; - /** - * @param NS[] $namespaces List of namespaces containing enums. Used when searching an enum by name. - */ + /** @param NS[] $namespaces List of namespaces containing enums. Used when searching an enum by name. */ public function __construct(private RootTypeMapperInterface $next, private AnnotationReader $annotationReader, private CacheInterface $cacheService, private array $namespaces) { } - public function toGraphQLOutputType(Type $type, ?OutputType $subType, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): OutputType + public function toGraphQLOutputType(Type $type, OutputType|null $subType, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): OutputType { $result = $this->map($type); return $result ?? $this->next->toGraphQLOutputType($type, $subType, $reflector, $docBlockObj); } - public function toGraphQLInputType(Type $type, null|InputType|GraphQLType $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType|GraphQLType + public function toGraphQLInputType(Type $type, InputType|GraphQLType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType|GraphQLType { $result = $this->map($type); return $result ?? $this->next->toGraphQLInputType($type, $subType, $argumentName, $reflector, $docBlockObj); } - private function map(Type $type): ?EnumType + private function map(Type $type): EnumType|null { if (! $type instanceof Object_) { return null; @@ -63,25 +61,19 @@ private function map(Type $type): ?EnumType if ($fqsen === null) { return null; } - /** - * @var class-string $enumClass - */ + /** @var class-string $enumClass */ $enumClass = (string) $fqsen; return $this->mapByClassName($enumClass); } - /** - * @param class-string $enumClass - */ - private function mapByClassName(string $enumClass): ?EnumType + /** @param class-string $enumClass */ + private function mapByClassName(string $enumClass): EnumType|null { if (! is_a($enumClass, Enum::class, true)) { return null; } - /** - * @var class-string - */ + /** @var class-string $enumClass */ $enumClass = ltrim($enumClass, '\\'); if (isset($this->cache[$enumClass])) { return $this->cache[$enumClass]; diff --git a/src/Mappers/Root/NullableTypeMapperAdapter.php b/src/Mappers/Root/NullableTypeMapperAdapter.php index 144694d8d2..06f11beef0 100644 --- a/src/Mappers/Root/NullableTypeMapperAdapter.php +++ b/src/Mappers/Root/NullableTypeMapperAdapter.php @@ -120,7 +120,7 @@ private function isNullable(Type $docBlockTypeHint): bool return false; } - private function getNonNullable(Type $type): ?Type + private function getNonNullable(Type $type): Type|null { if ($type instanceof Null_) { return null; diff --git a/src/Mappers/Root/RootTypeMapperFactoryContext.php b/src/Mappers/Root/RootTypeMapperFactoryContext.php index dcf3ce4f37..5a6f27d28f 100644 --- a/src/Mappers/Root/RootTypeMapperFactoryContext.php +++ b/src/Mappers/Root/RootTypeMapperFactoryContext.php @@ -26,8 +26,8 @@ public function __construct( private RecursiveTypeMapperInterface $recursiveTypeMapper, private ContainerInterface $container, private CacheInterface $cache, - private ?int $globTTL, - private ?int $mapTTL = null + private int|null $globTTL, + private int|null $mapTTL = null, ) { } @@ -66,12 +66,12 @@ public function getCache(): CacheInterface return $this->cache; } - public function getGlobTTL(): ?int + public function getGlobTTL(): int|null { return $this->globTTL; } - public function getMapTTL(): ?int + public function getMapTTL(): int|null { return $this->mapTTL; } diff --git a/src/Mappers/Root/RootTypeMapperInterface.php b/src/Mappers/Root/RootTypeMapperInterface.php index 6bcccdc27f..1a9faa16cc 100644 --- a/src/Mappers/Root/RootTypeMapperInterface.php +++ b/src/Mappers/Root/RootTypeMapperInterface.php @@ -30,14 +30,14 @@ interface RootTypeMapperInterface * * @return OutputType&GraphQLType */ - public function toGraphQLOutputType(Type $type, ?OutputType $subType, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): OutputType; + public function toGraphQLOutputType(Type $type, OutputType|null $subType, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): OutputType; /** * @param (InputType&GraphQLType)|null $subType * * @return InputType&GraphQLType */ - public function toGraphQLInputType(Type $type, null|InputType|GraphQLType $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType|GraphQLType; + public function toGraphQLInputType(Type $type, InputType|GraphQLType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType|GraphQLType; /** * Returns a GraphQL type by name. diff --git a/src/Mappers/StaticClassListTypeMapper.php b/src/Mappers/StaticClassListTypeMapper.php index 07b11d1ad6..8eeec45a9c 100644 --- a/src/Mappers/StaticClassListTypeMapper.php +++ b/src/Mappers/StaticClassListTypeMapper.php @@ -30,12 +30,10 @@ final class StaticClassListTypeMapper extends AbstractTypeMapper * * @var array> */ - private ?array $classes = null; + private array|null $classes = null; - /** - * @param array $classList The list of classes to analyze. - */ - public function __construct(private array $classList, TypeGenerator $typeGenerator, InputTypeGenerator $inputTypeGenerator, InputTypeUtils $inputTypeUtils, ContainerInterface $container, AnnotationReader $annotationReader, NamingStrategyInterface $namingStrategy, RecursiveTypeMapperInterface $recursiveTypeMapper, CacheInterface $cache, ?int $globTTL = 2, ?int $mapTTL = null) + /** @param array $classList The list of classes to analyze. */ + public function __construct(private array $classList, TypeGenerator $typeGenerator, InputTypeGenerator $inputTypeGenerator, InputTypeUtils $inputTypeUtils, ContainerInterface $container, AnnotationReader $annotationReader, NamingStrategyInterface $namingStrategy, RecursiveTypeMapperInterface $recursiveTypeMapper, CacheInterface $cache, int|null $globTTL = 2, int|null $mapTTL = null) { $cachePrefix = str_replace(['\\', '{', '}', '(', ')', '/', '@', ':'], '_', implode('_', $classList)); parent::__construct($cachePrefix, $typeGenerator, $inputTypeGenerator, $inputTypeUtils, $container, $annotationReader, $namingStrategy, $recursiveTypeMapper, $cache, $globTTL, $mapTTL); diff --git a/src/Mappers/StaticClassListTypeMapperFactory.php b/src/Mappers/StaticClassListTypeMapperFactory.php index 1a9a8fc6cf..ff8becbc6f 100644 --- a/src/Mappers/StaticClassListTypeMapperFactory.php +++ b/src/Mappers/StaticClassListTypeMapperFactory.php @@ -18,7 +18,7 @@ final class StaticClassListTypeMapperFactory implements TypeMapperFactoryInterfa * @param array $classList The list of classes to be scanned. */ public function __construct( - private array $classList + private array $classList, ) { } @@ -37,7 +37,7 @@ public function create(FactoryContext $context): TypeMapperInterface $context->getRecursiveTypeMapper(), $context->getCache(), $context->getGlobTTL(), - $context->getMapTTL() + $context->getMapTTL(), ); } } diff --git a/src/Mappers/StaticTypeMapper.php b/src/Mappers/StaticTypeMapper.php index 6d54502ce2..916fc66ead 100644 --- a/src/Mappers/StaticTypeMapper.php +++ b/src/Mappers/StaticTypeMapper.php @@ -104,7 +104,7 @@ public function canMapClassToType(string $className): bool * * @throws CannotMapTypeException */ - public function mapClassToType(string $className, ?OutputType $subType): MutableInterface + public function mapClassToType(string $className, OutputType|null $subType): MutableInterface { // TODO: add support for $subType if ($subType !== null) { diff --git a/src/Mappers/TypeMapperInterface.php b/src/Mappers/TypeMapperInterface.php index 471ceec108..c402e230de 100644 --- a/src/Mappers/TypeMapperInterface.php +++ b/src/Mappers/TypeMapperInterface.php @@ -37,7 +37,7 @@ public function canMapClassToType(string $className): bool; * * @throws CannotMapTypeExceptionInterface */ - public function mapClassToType(string $className, ?OutputType $subType): MutableInterface; + public function mapClassToType(string $className, OutputType|null $subType): MutableInterface; /** * Returns true if this type mapper can map the $typeName GraphQL name to a GraphQL type. diff --git a/src/Middlewares/AuthorizationFieldMiddleware.php b/src/Middlewares/AuthorizationFieldMiddleware.php index af5ec08271..13a212658a 100644 --- a/src/Middlewares/AuthorizationFieldMiddleware.php +++ b/src/Middlewares/AuthorizationFieldMiddleware.php @@ -26,11 +26,11 @@ class AuthorizationFieldMiddleware implements FieldMiddlewareInterface { public function __construct( private AuthenticationServiceInterface $authenticationService, - private AuthorizationServiceInterface $authorizationService + private AuthorizationServiceInterface $authorizationService, ) { } - public function process(QueryFieldDescriptor $queryFieldDescriptor, FieldHandlerInterface $fieldHandler): ?FieldDefinition + public function process(QueryFieldDescriptor $queryFieldDescriptor, FieldHandlerInterface $fieldHandler): FieldDefinition|null { $annotations = $queryFieldDescriptor->getMiddlewareAnnotations(); @@ -77,7 +77,7 @@ public function process(QueryFieldDescriptor $queryFieldDescriptor, FieldHandler /** * Checks the @Logged and @Right annotations. */ - private function isAuthorized(?Logged $loggedAnnotation, ?Right $rightAnnotation): bool + private function isAuthorized(Logged|null $loggedAnnotation, Right|null $rightAnnotation): bool { if ($loggedAnnotation !== null && ! $this->authenticationService->isLogged()) { return false; diff --git a/src/Middlewares/AuthorizationInputFieldMiddleware.php b/src/Middlewares/AuthorizationInputFieldMiddleware.php index 841827b78b..5d1676db03 100644 --- a/src/Middlewares/AuthorizationInputFieldMiddleware.php +++ b/src/Middlewares/AuthorizationInputFieldMiddleware.php @@ -21,15 +21,13 @@ class AuthorizationInputFieldMiddleware implements InputFieldMiddlewareInterface { public function __construct( private AuthenticationServiceInterface $authenticationService, - private AuthorizationServiceInterface $authorizationService + private AuthorizationServiceInterface $authorizationService, ) { } - /** - * @throws MissingAuthorizationException - */ - public function process(InputFieldDescriptor $inputFieldDescriptor, InputFieldHandlerInterface $inputFieldHandler): ?InputField + /** @throws MissingAuthorizationException */ + public function process(InputFieldDescriptor $inputFieldDescriptor, InputFieldHandlerInterface $inputFieldHandler): InputField|null { $annotations = $inputFieldDescriptor->getMiddlewareAnnotations(); @@ -54,7 +52,7 @@ public function process(InputFieldDescriptor $inputFieldDescriptor, InputFieldHa /** * Checks the @Logged and @Right annotations. */ - private function isAuthorized(?Logged $loggedAnnotation, ?Right $rightAnnotation): bool + private function isAuthorized(Logged|null $loggedAnnotation, Right|null $rightAnnotation): bool { if ($loggedAnnotation !== null && ! $this->authenticationService->isLogged()) { return false; diff --git a/src/Middlewares/FieldHandlerInterface.php b/src/Middlewares/FieldHandlerInterface.php index e3697a2432..e5980466e3 100644 --- a/src/Middlewares/FieldHandlerInterface.php +++ b/src/Middlewares/FieldHandlerInterface.php @@ -7,9 +7,7 @@ use GraphQL\Type\Definition\FieldDefinition; use TheCodingMachine\GraphQLite\QueryFieldDescriptor; -/** - * @unstable See https://graphqlite.thecodingmachine.io/docs/semver.html - */ +/** @unstable See https://graphqlite.thecodingmachine.io/docs/semver.html */ interface FieldHandlerInterface { /** @@ -17,5 +15,5 @@ interface FieldHandlerInterface * * May call other collaborating code to generate the field. */ - public function handle(QueryFieldDescriptor $fieldDescriptor): ?FieldDefinition; + public function handle(QueryFieldDescriptor $fieldDescriptor): FieldDefinition|null; } diff --git a/src/Middlewares/FieldMiddlewareInterface.php b/src/Middlewares/FieldMiddlewareInterface.php index 5bae069f57..7fcd3a4c26 100644 --- a/src/Middlewares/FieldMiddlewareInterface.php +++ b/src/Middlewares/FieldMiddlewareInterface.php @@ -14,5 +14,5 @@ */ interface FieldMiddlewareInterface { - public function process(QueryFieldDescriptor $queryFieldDescriptor, FieldHandlerInterface $fieldHandler): ?FieldDefinition; + public function process(QueryFieldDescriptor $queryFieldDescriptor, FieldHandlerInterface $fieldHandler): FieldDefinition|null; } diff --git a/src/Middlewares/FieldMiddlewarePipe.php b/src/Middlewares/FieldMiddlewarePipe.php index 128bbd8b2f..1e8f56d51c 100644 --- a/src/Middlewares/FieldMiddlewarePipe.php +++ b/src/Middlewares/FieldMiddlewarePipe.php @@ -26,7 +26,7 @@ public function __construct() * Executes the internal pipeline, passing $handler as the "final * handler" in cases when the pipeline exhausts itself. */ - public function process(QueryFieldDescriptor $queryFieldDescriptor, FieldHandlerInterface $fieldHandler): ?FieldDefinition + public function process(QueryFieldDescriptor $queryFieldDescriptor, FieldHandlerInterface $fieldHandler): FieldDefinition|null { return (new Next($this->pipeline, $fieldHandler))->handle($queryFieldDescriptor); } diff --git a/src/Middlewares/InputFieldHandlerInterface.php b/src/Middlewares/InputFieldHandlerInterface.php index 8ffc8caf60..89a68793a9 100644 --- a/src/Middlewares/InputFieldHandlerInterface.php +++ b/src/Middlewares/InputFieldHandlerInterface.php @@ -14,5 +14,5 @@ interface InputFieldHandlerInterface * * May call other collaborating code to generate the field. */ - public function handle(InputFieldDescriptor $inputFieldDescriptor): ?InputField; + public function handle(InputFieldDescriptor $inputFieldDescriptor): InputField|null; } diff --git a/src/Middlewares/InputFieldMiddlewareInterface.php b/src/Middlewares/InputFieldMiddlewareInterface.php index 07e934d9ef..e28309743e 100644 --- a/src/Middlewares/InputFieldMiddlewareInterface.php +++ b/src/Middlewares/InputFieldMiddlewareInterface.php @@ -12,5 +12,5 @@ */ interface InputFieldMiddlewareInterface { - public function process(InputFieldDescriptor $inputFieldDescriptor, InputFieldHandlerInterface $inputFieldHandler): ?InputField; + public function process(InputFieldDescriptor $inputFieldDescriptor, InputFieldHandlerInterface $inputFieldHandler): InputField|null; } diff --git a/src/Middlewares/InputFieldMiddlewarePipe.php b/src/Middlewares/InputFieldMiddlewarePipe.php index 1e6d6d71dc..b67f0d5276 100644 --- a/src/Middlewares/InputFieldMiddlewarePipe.php +++ b/src/Middlewares/InputFieldMiddlewarePipe.php @@ -26,7 +26,7 @@ public function __construct() * Executes the internal pipeline, passing $handler as the "final * handler" in cases when the pipeline exhausts itself. */ - public function process(InputFieldDescriptor $inputFieldDescriptor, InputFieldHandlerInterface $inputFieldHandler): ?InputField + public function process(InputFieldDescriptor $inputFieldDescriptor, InputFieldHandlerInterface $inputFieldHandler): InputField|null { return (new InputNext($this->pipeline, $inputFieldHandler))->handle($inputFieldDescriptor); } diff --git a/src/Middlewares/InputNext.php b/src/Middlewares/InputNext.php index 8c171b6852..80f8b4f82e 100644 --- a/src/Middlewares/InputNext.php +++ b/src/Middlewares/InputNext.php @@ -28,7 +28,7 @@ public function __construct(SplQueue $queue, private InputFieldHandlerInterface $this->queue = clone $queue; } - public function handle(InputFieldDescriptor $inputFieldDescriptor): ?InputField + public function handle(InputFieldDescriptor $inputFieldDescriptor): InputField|null { if ($this->queue->isEmpty()) { return $this->fallbackHandler->handle($inputFieldDescriptor); diff --git a/src/Middlewares/MissingMagicGetException.php b/src/Middlewares/MissingMagicGetException.php index 2aa4a78b1b..9a12531294 100644 --- a/src/Middlewares/MissingMagicGetException.php +++ b/src/Middlewares/MissingMagicGetException.php @@ -8,9 +8,7 @@ class MissingMagicGetException extends RuntimeException { - /** - * @param class-string $className - */ + /** @param class-string $className */ public static function cannotFindMagicGet(string $className): self { return new self('You cannot use a @MagicField annotation on an object that does not implement the __get() magic method. The class ' . $className . ' must implement a __get() method.'); diff --git a/src/Middlewares/Next.php b/src/Middlewares/Next.php index 6a3d6ee668..fb9a1ddc7c 100644 --- a/src/Middlewares/Next.php +++ b/src/Middlewares/Next.php @@ -26,7 +26,7 @@ public function __construct(SplQueue $queue, private FieldHandlerInterface $fall $this->queue = clone $queue; } - public function handle(QueryFieldDescriptor $fieldDescriptor): ?FieldDefinition + public function handle(QueryFieldDescriptor $fieldDescriptor): FieldDefinition|null { if ($this->queue->isEmpty()) { return $this->fallbackHandler->handle($fieldDescriptor); diff --git a/src/Middlewares/SecurityFieldMiddleware.php b/src/Middlewares/SecurityFieldMiddleware.php index 9ad4e5c2d8..6dbb07c8ae 100644 --- a/src/Middlewares/SecurityFieldMiddleware.php +++ b/src/Middlewares/SecurityFieldMiddleware.php @@ -31,7 +31,7 @@ public function __construct(private ExpressionLanguage $language, private Authen /*$this->logger = $logger;*/ } - public function process(QueryFieldDescriptor $queryFieldDescriptor, FieldHandlerInterface $fieldHandler): ?FieldDefinition + public function process(QueryFieldDescriptor $queryFieldDescriptor, FieldHandlerInterface $fieldHandler): FieldDefinition|null { $annotations = $queryFieldDescriptor->getMiddlewareAnnotations(); /** @var Security[] $securityAnnotations */ diff --git a/src/Middlewares/SecurityInputFieldMiddleware.php b/src/Middlewares/SecurityInputFieldMiddleware.php index eb1134ffc2..89a93bb5cb 100644 --- a/src/Middlewares/SecurityInputFieldMiddleware.php +++ b/src/Middlewares/SecurityInputFieldMiddleware.php @@ -27,11 +27,11 @@ class SecurityInputFieldMiddleware implements InputFieldMiddlewareInterface public function __construct( private ExpressionLanguage $language, private AuthenticationServiceInterface $authenticationService, - private AuthorizationServiceInterface $authorizationService + private AuthorizationServiceInterface $authorizationService, ) { } - public function process(InputFieldDescriptor $inputFieldDescriptor, InputFieldHandlerInterface $inputFieldHandler): ?InputField + public function process(InputFieldDescriptor $inputFieldDescriptor, InputFieldHandlerInterface $inputFieldHandler): InputField|null { $annotations = $inputFieldDescriptor->getMiddlewareAnnotations(); /** @var Security[] $securityAnnotations */ diff --git a/src/Middlewares/ServiceResolver.php b/src/Middlewares/ServiceResolver.php index 71f729b828..f1135fae8d 100644 --- a/src/Middlewares/ServiceResolver.php +++ b/src/Middlewares/ServiceResolver.php @@ -17,9 +17,7 @@ class ServiceResolver implements ResolverInterface /** @var callable&array{0:object, 1:string} */ private $callable; - /** - * @param callable&array{0:object, 1:string} $callable - */ + /** @param callable&array{0:object, 1:string} $callable */ public function __construct(callable $callable) { $this->callable = $callable; diff --git a/src/Middlewares/SourceInputPropertyResolver.php b/src/Middlewares/SourceInputPropertyResolver.php index 14e034ee35..ad5607c9c9 100644 --- a/src/Middlewares/SourceInputPropertyResolver.php +++ b/src/Middlewares/SourceInputPropertyResolver.php @@ -17,7 +17,7 @@ */ class SourceInputPropertyResolver implements SourceResolverInterface { - private ?object $object = null; + private object|null $object = null; public function __construct(private string $propertyName) { diff --git a/src/Middlewares/SourcePropertyResolver.php b/src/Middlewares/SourcePropertyResolver.php index 730f271730..5444070400 100644 --- a/src/Middlewares/SourcePropertyResolver.php +++ b/src/Middlewares/SourcePropertyResolver.php @@ -17,7 +17,7 @@ */ class SourcePropertyResolver implements SourceResolverInterface { - private ?object $object = null; + private object|null $object = null; public function __construct(private string $propertyName) { diff --git a/src/Middlewares/SourceResolver.php b/src/Middlewares/SourceResolver.php index fc98a290b0..51618d721a 100644 --- a/src/Middlewares/SourceResolver.php +++ b/src/Middlewares/SourceResolver.php @@ -17,7 +17,7 @@ */ class SourceResolver implements SourceResolverInterface { - private ?object $object = null; + private object|null $object = null; public function __construct(private string $methodName) { diff --git a/src/NamingStrategyInterface.php b/src/NamingStrategyInterface.php index 69f2dc7c3a..aee6f61eb9 100644 --- a/src/NamingStrategyInterface.php +++ b/src/NamingStrategyInterface.php @@ -8,9 +8,7 @@ use TheCodingMachine\GraphQLite\Annotations\Input; use TheCodingMachine\GraphQLite\Annotations\TypeInterface; -/** - * @unstable See https://graphqlite.thecodingmachine.io/docs/semver.html - */ +/** @unstable See https://graphqlite.thecodingmachine.io/docs/semver.html */ interface NamingStrategyInterface { /** diff --git a/src/Parameters/ContainerParameter.php b/src/Parameters/ContainerParameter.php index ac7088abbb..4937d23619 100644 --- a/src/Parameters/ContainerParameter.php +++ b/src/Parameters/ContainerParameter.php @@ -16,10 +16,8 @@ public function __construct(private ContainerInterface $container, private strin { } - /** - * @param array $args - */ - public function resolve(?object $source, array $args, mixed $context, ResolveInfo $info): mixed + /** @param array $args */ + public function resolve(object|null $source, array $args, mixed $context, ResolveInfo $info): mixed { return $this->container->get($this->identifier); } diff --git a/src/Parameters/DefaultValueParameter.php b/src/Parameters/DefaultValueParameter.php index 6fe17b07e0..39866b1f34 100644 --- a/src/Parameters/DefaultValueParameter.php +++ b/src/Parameters/DefaultValueParameter.php @@ -15,10 +15,8 @@ public function __construct(private mixed $defaultValue) { } - /** - * @param array $args - */ - public function resolve(?object $source, array $args, mixed $context, ResolveInfo $info): mixed + /** @param array $args */ + public function resolve(object|null $source, array $args, mixed $context, ResolveInfo $info): mixed { return $this->defaultValue; } diff --git a/src/Parameters/InjectUserParameter.php b/src/Parameters/InjectUserParameter.php index da1d859040..d6fad0a51a 100644 --- a/src/Parameters/InjectUserParameter.php +++ b/src/Parameters/InjectUserParameter.php @@ -16,10 +16,8 @@ public function __construct(private AuthenticationServiceInterface $authenticati { } - /** - * @param array $args - */ - public function resolve(?object $source, array $args, mixed $context, ResolveInfo $info): ?object + /** @param array $args */ + public function resolve(object|null $source, array $args, mixed $context, ResolveInfo $info): object|null { return $this->authenticationService->getUser(); } diff --git a/src/Parameters/InputTypeParameter.php b/src/Parameters/InputTypeParameter.php index 92db721241..4deebb4952 100644 --- a/src/Parameters/InputTypeParameter.php +++ b/src/Parameters/InputTypeParameter.php @@ -13,20 +13,16 @@ class InputTypeParameter implements InputTypeParameterInterface { private bool $doesHaveDefaultValue; - private ?string $description = null; + private string|null $description = null; - /** - * @param InputType&Type $type - */ + /** @param InputType&Type $type */ public function __construct(private string $name, private InputType $type, bool $hasDefaultValue, private mixed $defaultValue, private ArgumentResolver $argumentResolver) { $this->doesHaveDefaultValue = $hasDefaultValue; } - /** - * @param array $args - */ - public function resolve(?object $source, array $args, mixed $context, ResolveInfo $info): mixed + /** @param array $args */ + public function resolve(object|null $source, array $args, mixed $context, ResolveInfo $info): mixed { if (isset($args[$this->name])) { return $this->argumentResolver->resolve($source, $args[$this->name], $context, $info, $this->type); diff --git a/src/Parameters/InputTypeParameterInterface.php b/src/Parameters/InputTypeParameterInterface.php index 0825e45bbe..713e7560aa 100644 --- a/src/Parameters/InputTypeParameterInterface.php +++ b/src/Parameters/InputTypeParameterInterface.php @@ -7,15 +7,11 @@ use GraphQL\Type\Definition\InputType; use GraphQL\Type\Definition\ResolveInfo; -/** - * @unstable See https://graphqlite.thecodingmachine.io/docs/semver.html - */ +/** @unstable See https://graphqlite.thecodingmachine.io/docs/semver.html */ interface InputTypeParameterInterface extends ParameterInterface { - /** - * @param array $args - */ - public function resolve(?object $source, array $args, mixed $context, ResolveInfo $info): mixed; + /** @param array $args */ + public function resolve(object|null $source, array $args, mixed $context, ResolveInfo $info): mixed; public function getType(): InputType; diff --git a/src/Parameters/InputTypeProperty.php b/src/Parameters/InputTypeProperty.php index 4edfcbfe61..88170be42c 100644 --- a/src/Parameters/InputTypeProperty.php +++ b/src/Parameters/InputTypeProperty.php @@ -10,9 +10,7 @@ class InputTypeProperty extends InputTypeParameter { - /** - * @param InputType&Type $type - */ + /** @param InputType&Type $type */ public function __construct(private string $propertyName, string $fieldName, InputType $type, bool $hasDefaultValue, mixed $defaultValue, ArgumentResolver $argumentResolver) { parent::__construct($fieldName, $type, $hasDefaultValue, $defaultValue, $argumentResolver); diff --git a/src/Parameters/MissingArgumentException.php b/src/Parameters/MissingArgumentException.php index 1a43e3d893..be48cd5564 100644 --- a/src/Parameters/MissingArgumentException.php +++ b/src/Parameters/MissingArgumentException.php @@ -26,7 +26,7 @@ public static function wrapWithFactoryContext(self $previous, string $inputType, '%s in GraphQL input type \'%s\' used in factory \'%s\'', $previous->getMessage(), $inputType, - self::toLocation($callable) + self::toLocation($callable), ); return new self($message, 0, $previous); @@ -38,7 +38,7 @@ public static function wrapWithDecoratorContext(self $previous, string $inputTyp '%s in GraphQL input type \'%s\' used in decorator \'%s\'', $previous->getMessage(), $inputType, - self::toLocation($callable) + self::toLocation($callable), ); return new self($message, 0, $previous); @@ -50,7 +50,7 @@ public static function wrapWithFieldContext(self $previous, string $name, callab '%s in GraphQL query/mutation/field \'%s\' used in method \'%s\'', $previous->getMessage(), $name, - self::toLocation($callable) + self::toLocation($callable), ); return new self($message, 0, $previous); diff --git a/src/Parameters/ParameterInterface.php b/src/Parameters/ParameterInterface.php index 5737f299e6..790ccf04a9 100644 --- a/src/Parameters/ParameterInterface.php +++ b/src/Parameters/ParameterInterface.php @@ -13,8 +13,6 @@ */ interface ParameterInterface { - /** - * @param array $args - */ - public function resolve(?object $source, array $args, mixed $context, ResolveInfo $info): mixed; + /** @param array $args */ + public function resolve(object|null $source, array $args, mixed $context, ResolveInfo $info): mixed; } diff --git a/src/Parameters/PrefetchDataParameter.php b/src/Parameters/PrefetchDataParameter.php index 6a684f82e1..aa4acdf2db 100644 --- a/src/Parameters/PrefetchDataParameter.php +++ b/src/Parameters/PrefetchDataParameter.php @@ -13,10 +13,8 @@ class PrefetchDataParameter implements ParameterInterface { private mixed $prefetchedData; - /** - * @param array $args - */ - public function resolve(?object $source, array $args, mixed $context, ResolveInfo $info): mixed + /** @param array $args */ + public function resolve(object|null $source, array $args, mixed $context, ResolveInfo $info): mixed { // Note: data cannot be known at build time. return $this->prefetchedData; diff --git a/src/Parameters/ResolveInfoParameter.php b/src/Parameters/ResolveInfoParameter.php index f5151c93d1..bf7f0fb88f 100644 --- a/src/Parameters/ResolveInfoParameter.php +++ b/src/Parameters/ResolveInfoParameter.php @@ -11,10 +11,8 @@ */ class ResolveInfoParameter implements ParameterInterface { - /** - * @param array $args - */ - public function resolve(?object $source, array $args, mixed $context, ResolveInfo $info): ResolveInfo + /** @param array $args */ + public function resolve(object|null $source, array $args, mixed $context, ResolveInfo $info): ResolveInfo { return $info; } diff --git a/src/Parameters/SourceParameter.php b/src/Parameters/SourceParameter.php index cd9edb26c8..af0b5e31a6 100644 --- a/src/Parameters/SourceParameter.php +++ b/src/Parameters/SourceParameter.php @@ -11,10 +11,8 @@ */ class SourceParameter implements ParameterInterface { - /** - * @param array $args - */ - public function resolve(?object $source, array $args, mixed $context, ResolveInfo $info): ?object + /** @param array $args */ + public function resolve(object|null $source, array $args, mixed $context, ResolveInfo $info): object|null { return $source; } diff --git a/src/PrefetchBuffer.php b/src/PrefetchBuffer.php index e30a4c13ae..5105d02249 100644 --- a/src/PrefetchBuffer.php +++ b/src/PrefetchBuffer.php @@ -19,17 +19,13 @@ class PrefetchBuffer /** @var array An array of prefetch method results, indexed by hash of arguments. */ private array $results = []; - /** - * @param array $arguments The input arguments passed from GraphQL to the field. - */ + /** @param array $arguments The input arguments passed from GraphQL to the field. */ public function register(object $object, array $arguments): void { $this->objects[$this->computeHash($arguments)][] = $object; } - /** - * @param array $arguments The input arguments passed from GraphQL to the field. - */ + /** @param array $arguments The input arguments passed from GraphQL to the field. */ private function computeHash(array $arguments): string { return md5(serialize($arguments)); @@ -45,33 +41,25 @@ public function getObjectsByArguments(array $arguments): array return $this->objects[$this->computeHash($arguments)] ?? []; } - /** - * @param array $arguments The input arguments passed from GraphQL to the field. - */ + /** @param array $arguments The input arguments passed from GraphQL to the field. */ public function purge(array $arguments): void { unset($this->objects[$this->computeHash($arguments)]); } - /** - * @param array $arguments The input arguments passed from GraphQL to the field. - */ + /** @param array $arguments The input arguments passed from GraphQL to the field. */ public function storeResult(mixed $result, array $arguments): void { $this->results[$this->computeHash($arguments)] = $result; } - /** - * @param array $arguments The input arguments passed from GraphQL to the field. - */ + /** @param array $arguments The input arguments passed from GraphQL to the field. */ public function hasResult(array $arguments): bool { return array_key_exists($this->computeHash($arguments), $this->results); } - /** - * @param array $arguments The input arguments passed from GraphQL to the field. - */ + /** @param array $arguments The input arguments passed from GraphQL to the field. */ public function getResult(array $arguments): mixed { return $this->results[$this->computeHash($arguments)]; diff --git a/src/QueryField.php b/src/QueryField.php index 725a231696..eb010c1f92 100644 --- a/src/QueryField.php +++ b/src/QueryField.php @@ -42,7 +42,7 @@ class QueryField extends FieldDefinition * @param array $prefetchArgs Indexed by argument name. * @param array $additionalConfig */ - public function __construct(string $name, OutputType $type, array $arguments, ResolverInterface $originalResolver, callable $resolver, ?string $comment, ?string $deprecationReason, ?string $prefetchMethodName, array $prefetchArgs, array $additionalConfig = []) + public function __construct(string $name, OutputType $type, array $arguments, ResolverInterface $originalResolver, callable $resolver, string|null $comment, string|null $deprecationReason, string|null $prefetchMethodName, array $prefetchArgs, array $additionalConfig = []) { $config = [ 'name' => $name, @@ -213,7 +213,7 @@ private static function fromDescriptor(QueryFieldDescriptor $fieldDescriptor): s $fieldDescriptor->getComment(), $fieldDescriptor->getDeprecationReason(), $fieldDescriptor->getPrefetchMethodName(), - $fieldDescriptor->getPrefetchParameters() + $fieldDescriptor->getPrefetchParameters(), ); } @@ -239,7 +239,7 @@ public static function fromFieldDescriptor(QueryFieldDescriptor $fieldDescriptor * * @return array */ - private function paramsToArguments(array $parameters, ?object $source, array $args, mixed $context, ResolveInfo $info, callable $resolve): array + private function paramsToArguments(array $parameters, object|null $source, array $args, mixed $context, ResolveInfo $info, callable $resolve): array { $toPassArgs = []; $exceptions = []; diff --git a/src/QueryFieldDescriptor.php b/src/QueryFieldDescriptor.php index 362a9667e6..12c3514f7a 100644 --- a/src/QueryFieldDescriptor.php +++ b/src/QueryFieldDescriptor.php @@ -27,27 +27,27 @@ class QueryFieldDescriptor { private string $name; /** @var (OutputType&Type)|null */ - private ?Type $type = null; + private Type|null $type = null; /** @var array */ private array $parameters = []; /** @var array */ private array $prefetchParameters = []; - private ?string $prefetchMethodName = null; + private string|null $prefetchMethodName = null; /** @var callable|null */ private $callable; - private ?string $targetMethodOnSource = null; - private ?string $targetPropertyOnSource = null; - private ?string $magicProperty = null; + private string|null $targetMethodOnSource = null; + private string|null $targetPropertyOnSource = null; + private string|null $magicProperty = null; /** * Whether we should inject the source as the first parameter or not. */ private bool $injectSource; - private ?string $comment = null; - private ?string $deprecationReason = null; + private string|null $comment = null; + private string|null $deprecationReason = null; private MiddlewareAnnotations $middlewareAnnotations; private ReflectionMethod $refMethod; private ReflectionProperty $refProperty; - private ?ResolverInterface $originalResolver = null; + private ResolverInterface|null $originalResolver = null; /** @var callable */ private $resolver; @@ -61,60 +61,48 @@ public function setName(string $name): void $this->name = $name; } - /** - * @return (OutputType&Type)|null - */ - public function getType(): ?Type + /** @return (OutputType&Type)|null */ + public function getType(): Type|null { return $this->type; } - /** - * @param OutputType&Type $type - */ + /** @param OutputType&Type $type */ public function setType(Type $type): void { $this->type = $type; } - /** - * @return array - */ + /** @return array */ public function getParameters(): array { return $this->parameters; } - /** - * @param array $parameters - */ + /** @param array $parameters */ public function setParameters(array $parameters): void { $this->parameters = $parameters; } - /** - * @return array - */ + /** @return array */ public function getPrefetchParameters(): array { return $this->prefetchParameters; } - /** - * @param array $prefetchParameters - */ + /** @param array $prefetchParameters */ public function setPrefetchParameters(array $prefetchParameters): void { $this->prefetchParameters = $prefetchParameters; } - public function getPrefetchMethodName(): ?string + public function getPrefetchMethodName(): string|null { return $this->prefetchMethodName; } - public function setPrefetchMethodName(?string $prefetchMethodName): void + public function setPrefetchMethodName(string|null $prefetchMethodName): void { $this->prefetchMethodName = $prefetchMethodName; } @@ -146,7 +134,7 @@ public function setTargetMethodOnSource(string $targetMethodOnSource): void $this->magicProperty = null; } - public function setTargetPropertyOnSource(?string $targetPropertyOnSource): void + public function setTargetPropertyOnSource(string|null $targetPropertyOnSource): void { if ($this->originalResolver !== null) { throw new GraphQLRuntimeException('You cannot modify the target method via setTargetMethodOnSource because it was already used. You can still wrap the callable using getResolver/setResolver'); @@ -178,22 +166,22 @@ public function setInjectSource(bool $injectSource): void $this->injectSource = $injectSource; } - public function getComment(): ?string + public function getComment(): string|null { return $this->comment; } - public function setComment(?string $comment): void + public function setComment(string|null $comment): void { $this->comment = $comment; } - public function getDeprecationReason(): ?string + public function getDeprecationReason(): string|null { return $this->deprecationReason; } - public function setDeprecationReason(?string $deprecationReason): void + public function setDeprecationReason(string|null $deprecationReason): void { $this->deprecationReason = $deprecationReason; } diff --git a/src/QueryProviderInterface.php b/src/QueryProviderInterface.php index bf0b5e281f..f427ec1a67 100644 --- a/src/QueryProviderInterface.php +++ b/src/QueryProviderInterface.php @@ -9,13 +9,9 @@ */ interface QueryProviderInterface { - /** - * @return QueryField[] - */ + /** @return QueryField[] */ public function getQueries(): array; - /** - * @return QueryField[] - */ + /** @return QueryField[] */ public function getMutations(): array; } diff --git a/src/Reflection/CachedDocBlockFactory.php b/src/Reflection/CachedDocBlockFactory.php index bc53b12a52..31be932ce0 100644 --- a/src/Reflection/CachedDocBlockFactory.php +++ b/src/Reflection/CachedDocBlockFactory.php @@ -31,10 +31,8 @@ class CachedDocBlockFactory private array $contextArrayCache = []; private ContextFactory $contextFactory; - /** - * @param CacheInterface $cache The cache we fetch data from. Note this is a SAFE cache. It does not need to be purged. - */ - public function __construct(private CacheInterface $cache, ?DocBlockFactory $docBlockFactory = null) + /** @param CacheInterface $cache The cache we fetch data from. Note this is a SAFE cache. It does not need to be purged. */ + public function __construct(private CacheInterface $cache, DocBlockFactory|null $docBlockFactory = null) { $this->docBlockFactory = $docBlockFactory ?: DocBlockFactory::createInstance(); $this->contextFactory = new ContextFactory(); @@ -94,9 +92,7 @@ private function doGetDocBlock(ReflectionMethod|ReflectionProperty $reflector): return $this->docBlockFactory->create($docComment, $this->contextArrayCache[$refClassName]); } - /** - * @param ReflectionClass $reflectionClass - */ + /** @param ReflectionClass $reflectionClass */ public function getContextFromClass(ReflectionClass $reflectionClass): Context { $className = $reflectionClass->getName(); diff --git a/src/Schema.php b/src/Schema.php index d50a386f75..ac7beeffd3 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -18,7 +18,7 @@ */ class Schema extends \GraphQL\Type\Schema { - public function __construct(QueryProviderInterface $queryProvider, RecursiveTypeMapperInterface $recursiveTypeMapper, TypeResolver $typeResolver, RootTypeMapperInterface $rootTypeMapper, ?SchemaConfig $config = null) + public function __construct(QueryProviderInterface $queryProvider, RecursiveTypeMapperInterface $recursiveTypeMapper, TypeResolver $typeResolver, RootTypeMapperInterface $rootTypeMapper, SchemaConfig|null $config = null) { if ($config === null) { $config = SchemaConfig::create(); diff --git a/src/SchemaFactory.php b/src/SchemaFactory.php index dc42fd3c1a..abaac63745 100644 --- a/src/SchemaFactory.php +++ b/src/SchemaFactory.php @@ -98,25 +98,21 @@ class SchemaFactory /** @var ParameterMiddlewareInterface[] */ private array $parameterMiddlewares = []; - private ?Reader $doctrineAnnotationReader = null; + private Reader|null $doctrineAnnotationReader = null; - private ?AuthenticationServiceInterface $authenticationService = null; + private AuthenticationServiceInterface|null $authenticationService = null; - private ?AuthorizationServiceInterface $authorizationService = null; + private AuthorizationServiceInterface|null $authorizationService = null; - private ?InputTypeValidatorInterface $inputTypeValidator = null; + private InputTypeValidatorInterface|null $inputTypeValidator = null; - private CacheInterface $cache; + private NamingStrategyInterface|null $namingStrategy = null; - private ?NamingStrategyInterface $namingStrategy = null; + private ClassNameMapper|null $classNameMapper = null; - private ContainerInterface $container; + private SchemaConfig|null $schemaConfig = null; - private ?ClassNameMapper $classNameMapper = null; - - private ?SchemaConfig $schemaConfig = null; - - private ?int $globTTL = self::GLOB_CACHE_SECONDS; + private int|null $globTTL = self::GLOB_CACHE_SECONDS; /** @var array */ private array $fieldMiddlewares = []; @@ -124,15 +120,13 @@ class SchemaFactory /** @var array */ private array $inputFieldMiddlewares = []; - private ?ExpressionLanguage $expressionLanguage = null; + private ExpressionLanguage|null $expressionLanguage = null; private string $cacheNamespace; - public function __construct(CacheInterface $cache, ContainerInterface $container) + public function __construct(private CacheInterface $cache, private ContainerInterface $container) { $this->cacheNamespace = substr(md5(Versions::getVersion('thecodingmachine/graphqlite')), 0, 8); - $this->cache = $cache; - $this->container = $container; } /** @@ -251,7 +245,7 @@ public function setAuthorizationService(AuthorizationServiceInterface $authoriza return $this; } - public function setInputTypeValidator(?InputTypeValidatorInterface $inputTypeValidator): self + public function setInputTypeValidator(InputTypeValidatorInterface|null $inputTypeValidator): self { $this->inputTypeValidator = $inputTypeValidator; @@ -284,7 +278,7 @@ public function setClassNameMapper(ClassNameMapper $classNameMapper): self * By default this is set to 2 seconds which is ok for development environments. * Set this to "null" (i.e. infinity) for production environments. */ - public function setGlobTTL(?int $globTTL): self + public function setGlobTTL(int|null $globTTL): self { $this->globTTL = $globTTL; @@ -357,7 +351,7 @@ public function createSchema(): Schema $namespaceFactory = new NamespaceFactory($namespacedCache, $this->classNameMapper, $this->globTTL); $nsList = array_map( static fn (string $namespace) => $namespaceFactory->createNamespace($namespace), - $this->typeNamespaces + $this->typeNamespaces, ); $expressionLanguage = $this->expressionLanguage ?: new ExpressionLanguage($symfonyCache); @@ -404,7 +398,7 @@ public function createSchema(): Schema $recursiveTypeMapper, $this->container, $namespacedCache, - $this->globTTL + $this->globTTL, ); $reversedRootTypeMapperFactories = array_reverse($this->rootTypeMapperFactories); @@ -456,7 +450,7 @@ public function createSchema(): Schema $namingStrategy, $recursiveTypeMapper, $namespacedCache, - $this->globTTL + $this->globTTL, )); } @@ -473,7 +467,7 @@ public function createSchema(): Schema $this->container, $namespacedCache, $this->inputTypeValidator, - $this->globTTL + $this->globTTL, ); } @@ -500,7 +494,7 @@ public function createSchema(): Schema $annotationReader, $namespacedCache, $this->classNameMapper, - $this->globTTL + $this->globTTL, ); } diff --git a/src/Security/AuthenticationServiceInterface.php b/src/Security/AuthenticationServiceInterface.php index 33a5293699..5a3c40b93c 100644 --- a/src/Security/AuthenticationServiceInterface.php +++ b/src/Security/AuthenticationServiceInterface.php @@ -4,9 +4,7 @@ namespace TheCodingMachine\GraphQLite\Security; -/** - * @unstable See https://graphqlite.thecodingmachine.io/docs/semver.html - */ +/** @unstable See https://graphqlite.thecodingmachine.io/docs/semver.html */ interface AuthenticationServiceInterface { /** @@ -18,5 +16,5 @@ public function isLogged(): bool; * Returns an object representing the current logged user. * Can return null if the user is not logged. */ - public function getUser(): ?object; + public function getUser(): object|null; } diff --git a/src/Security/AuthorizationServiceInterface.php b/src/Security/AuthorizationServiceInterface.php index 0346a23c47..f7f00564cb 100644 --- a/src/Security/AuthorizationServiceInterface.php +++ b/src/Security/AuthorizationServiceInterface.php @@ -4,9 +4,7 @@ namespace TheCodingMachine\GraphQLite\Security; -/** - * @unstable See https://graphqlite.thecodingmachine.io/docs/semver.html - */ +/** @unstable See https://graphqlite.thecodingmachine.io/docs/semver.html */ interface AuthorizationServiceInterface { /** diff --git a/src/Security/FailAuthenticationService.php b/src/Security/FailAuthenticationService.php index 4b5c6286c6..49eb3cf80d 100644 --- a/src/Security/FailAuthenticationService.php +++ b/src/Security/FailAuthenticationService.php @@ -21,7 +21,7 @@ public function isLogged(): bool * Returns an object representing the current logged user. * Can return null if the user is not logged. */ - public function getUser(): ?object + public function getUser(): object|null { throw SecurityNotImplementedException::createNoAuthenticationException(); } diff --git a/src/Security/SecurityExpressionLanguageProvider.php b/src/Security/SecurityExpressionLanguageProvider.php index f50d122998..cd1b1c5531 100644 --- a/src/Security/SecurityExpressionLanguageProvider.php +++ b/src/Security/SecurityExpressionLanguageProvider.php @@ -14,9 +14,7 @@ */ class SecurityExpressionLanguageProvider implements ExpressionFunctionProviderInterface { - /** - * @return ExpressionFunction[] An array of Function instances - */ + /** @return ExpressionFunction[] An array of Function instances */ public function getFunctions(): array { return [ diff --git a/src/Security/VoidAuthenticationService.php b/src/Security/VoidAuthenticationService.php index c6f4c8aa5d..d808660922 100644 --- a/src/Security/VoidAuthenticationService.php +++ b/src/Security/VoidAuthenticationService.php @@ -21,7 +21,7 @@ public function isLogged(): bool * Returns an object representing the current logged user. * Can return null if the user is not logged. */ - public function getUser(): ?object + public function getUser(): object|null { return null; } diff --git a/src/TypeGenerator.php b/src/TypeGenerator.php index 99a66bc82b..d77b119d26 100644 --- a/src/TypeGenerator.php +++ b/src/TypeGenerator.php @@ -28,7 +28,7 @@ public function __construct( private TypeRegistry $typeRegistry, private ContainerInterface $container, private RecursiveTypeMapperInterface $recursiveTypeMapper, - private FieldsBuilder $fieldsBuilder + private FieldsBuilder $fieldsBuilder, ) { } diff --git a/src/TypeRegistry.php b/src/TypeRegistry.php index da42083a68..1e538a7d39 100644 --- a/src/TypeRegistry.php +++ b/src/TypeRegistry.php @@ -63,9 +63,7 @@ public function hasType(string $typeName): bool return isset($this->types[$typeName]); } - /** - * @return NamedType&Type&(ObjectType|InterfaceType|UnionType|(InputObjectType&ResolvableMutableInputInterface)) - */ + /** @return NamedType&Type&(ObjectType|InterfaceType|UnionType|(InputObjectType&ResolvableMutableInputInterface)) */ public function getType(string $typeName): NamedType { if (! isset($this->types[$typeName])) { @@ -85,9 +83,7 @@ public function getMutableObjectType(string $typeName): MutableObjectType return $type; } - /** - * @return MutableInterface&(MutableObjectType|MutableInterfaceType) - */ + /** @return MutableInterface&(MutableObjectType|MutableInterfaceType) */ public function getMutableInterface(string $typeName): MutableInterface { $type = $this->getType($typeName); diff --git a/src/Types/ArgumentResolver.php b/src/Types/ArgumentResolver.php index dea55c3fc4..0025e5076a 100644 --- a/src/Types/ArgumentResolver.php +++ b/src/Types/ArgumentResolver.php @@ -32,7 +32,7 @@ class ArgumentResolver * * @throws Error */ - public function resolve(?object $source, mixed $val, mixed $context, ResolveInfo $resolveInfo, InputType $type): mixed + public function resolve(object|null $source, mixed $val, mixed $context, ResolveInfo $resolveInfo, InputType $type): mixed { $type = $this->stripNonNullType($type); if ($type instanceof ListOfType) { diff --git a/src/Types/DateTimeType.php b/src/Types/DateTimeType.php index cdce7e6497..6693ac7083 100644 --- a/src/Types/DateTimeType.php +++ b/src/Types/DateTimeType.php @@ -29,7 +29,7 @@ public function serialize(mixed $value): string return $value->format(DateTime::ATOM); } - public function parseValue(mixed $value): ?DateTimeImmutable + public function parseValue(mixed $value): DateTimeImmutable|null { if ($value === null) { return null; @@ -52,7 +52,7 @@ public function parseValue(mixed $value): ?DateTimeImmutable * * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint */ - public function parseLiteral($valueNode, ?array $variables = null): mixed + public function parseLiteral($valueNode, array|null $variables = null): mixed { if ($valueNode instanceof StringValueNode) { return $valueNode->value; diff --git a/src/Types/EnumType.php b/src/Types/EnumType.php index d0bb7ca46c..4962f3162b 100644 --- a/src/Types/EnumType.php +++ b/src/Types/EnumType.php @@ -17,9 +17,7 @@ */ class EnumType extends BaseEnumType { - /** - * @param class-string $enumName - */ + /** @param class-string $enumName */ public function __construct(string $enumName, string $typeName, private bool $useValues = false) { $values = []; @@ -36,9 +34,7 @@ public function __construct(string $enumName, string $typeName, private bool $us // phpcs:disable SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint - /** - * @param mixed $value - */ + /** @param mixed $value */ public function serialize($value): string { if (! $value instanceof UnitEnum) { diff --git a/src/Types/InputType.php b/src/Types/InputType.php index 9668da3338..d026255b17 100644 --- a/src/Types/InputType.php +++ b/src/Types/InputType.php @@ -22,16 +22,14 @@ class InputType extends MutableInputObjectType implements ResolvableMutableInput /** @var InputField[] */ private array $inputFields = []; - /** - * @param class-string $className - */ + /** @param class-string $className */ public function __construct( private string $className, string $inputName, - ?string $description, + string|null $description, bool $isUpdate, FieldsBuilder $fieldsBuilder, - private ?InputTypeValidatorInterface $inputTypeValidator = null + private InputTypeValidatorInterface|null $inputTypeValidator = null, ) { $reflection = new ReflectionClass($className); if (! $reflection->isInstantiable()) { @@ -65,10 +63,8 @@ public function __construct( parent::__construct($config); } - /** - * @param array $args - */ - public function resolve(?object $source, array $args, mixed $context, ResolveInfo $resolveInfo): object + /** @param array $args */ + public function resolve(object|null $source, array $args, mixed $context, ResolveInfo $resolveInfo): object { $constructorArgs = []; foreach ($this->constructorInputFields as $constructorInputField) { diff --git a/src/Types/InterfaceFromObjectType.php b/src/Types/InterfaceFromObjectType.php index 3b30737166..17cb44d350 100644 --- a/src/Types/InterfaceFromObjectType.php +++ b/src/Types/InterfaceFromObjectType.php @@ -20,7 +20,7 @@ class InterfaceFromObjectType extends InterfaceType * @param string $name The name of the interface * @param (OutputType&Type)|null $subType */ - public function __construct(string $name, ObjectType $type, ?OutputType $subType, RecursiveTypeMapperInterface $typeMapper) + public function __construct(string $name, ObjectType $type, OutputType|null $subType, RecursiveTypeMapperInterface $typeMapper) { parent::__construct([ 'name' => $name, diff --git a/src/Types/MutableInputObjectType.php b/src/Types/MutableInputObjectType.php index f97d0beca8..1c92079875 100644 --- a/src/Types/MutableInputObjectType.php +++ b/src/Types/MutableInputObjectType.php @@ -29,11 +29,9 @@ class MutableInputObjectType extends InputObjectType implements MutableInputInte protected array $fieldsCallables = []; /** @var array|null */ - protected ?array $finalFields = null; + protected array|null $finalFields = null; - /** - * @param mixed[] $config - */ + /** @param mixed[] $config */ public function __construct(array $config) { $this->status = self::STATUS_PENDING; diff --git a/src/Types/MutableInterfaceType.php b/src/Types/MutableInterfaceType.php index 4c69496e23..607557a95b 100644 --- a/src/Types/MutableInterfaceType.php +++ b/src/Types/MutableInterfaceType.php @@ -17,7 +17,7 @@ class MutableInterfaceType extends InterfaceType implements MutableInterface * @param mixed[] $config * @param class-string|null $className */ - public function __construct(array $config, ?string $className = null) + public function __construct(array $config, string|null $className = null) { $this->status = self::STATUS_PENDING; diff --git a/src/Types/MutableObjectType.php b/src/Types/MutableObjectType.php index 0a49b1e44e..f99ce0a46a 100644 --- a/src/Types/MutableObjectType.php +++ b/src/Types/MutableObjectType.php @@ -17,7 +17,7 @@ class MutableObjectType extends ObjectType implements MutableInterface * @param mixed[] $config * @param class-string|null $className */ - public function __construct(array $config, ?string $className = null) + public function __construct(array $config, string|null $className = null) { $this->status = self::STATUS_PENDING; diff --git a/src/Types/MutableTrait.php b/src/Types/MutableTrait.php index da123a347b..804c47ae3e 100644 --- a/src/Types/MutableTrait.php +++ b/src/Types/MutableTrait.php @@ -16,15 +16,15 @@ trait MutableTrait { - private ?string $status = null; + private string|null $status = null; /** @var array */ private array $fieldsCallables = []; /** @var array|null */ - private ?array $fields = null; + private array|null $fields = null; /** @var class-string|null */ - private ?string $className = null; + private string|null $className = null; public function freeze(): void { @@ -59,7 +59,7 @@ public function getField(string $name): FieldDefinition return $this->fields[$name] ?? parent::getField($name); } - public function findField(string $name): ?FieldDefinition + public function findField(string $name): FieldDefinition|null { $this->initializeFields(); @@ -85,9 +85,7 @@ public function getFields(): array return array_merge(parent::getFields(), $this->fields); } - /** - * @return array - */ + /** @return array */ public function getFieldNames(): array { $this->initializeFields(); @@ -101,7 +99,7 @@ public function getFieldNames(): array * * @return class-string|null */ - public function getMappedClassName(): ?string + public function getMappedClassName(): string|null { return $this->className; } @@ -110,7 +108,7 @@ private function initializeFields(): void { if ($this->status === MutableInterface::STATUS_PENDING) { throw new RuntimeException( - 'You must freeze() the MutableObjectType, ' . $this->className . ', before fetching its fields.' + 'You must freeze() the MutableObjectType, ' . $this->className . ', before fetching its fields.', ); } diff --git a/src/Types/ObjectFromInterfaceType.php b/src/Types/ObjectFromInterfaceType.php index adf8a6dc2c..c732d39519 100644 --- a/src/Types/ObjectFromInterfaceType.php +++ b/src/Types/ObjectFromInterfaceType.php @@ -8,9 +8,7 @@ class ObjectFromInterfaceType extends MutableObjectType { - /** - * @param string $name The name of the object type to create - */ + /** @param string $name The name of the object type to create */ public function __construct(string $name, InterfaceType $type) { parent::__construct([ diff --git a/src/Types/ResolvableMutableInputInterface.php b/src/Types/ResolvableMutableInputInterface.php index a09b3aec94..29f116b7eb 100644 --- a/src/Types/ResolvableMutableInputInterface.php +++ b/src/Types/ResolvableMutableInputInterface.php @@ -19,7 +19,7 @@ interface ResolvableMutableInputInterface extends MutableInputInterface * * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint */ - public function resolve(?object $source, array $args, mixed $context, ResolveInfo $resolveInfo): object; + public function resolve(object|null $source, array $args, mixed $context, ResolveInfo $resolveInfo): object; /** * Decorates the call to the resolver with the $decorator. diff --git a/src/Types/ResolvableMutableInputObjectType.php b/src/Types/ResolvableMutableInputObjectType.php index aeeb06a819..f8bc8a6f50 100644 --- a/src/Types/ResolvableMutableInputObjectType.php +++ b/src/Types/ResolvableMutableInputObjectType.php @@ -28,7 +28,7 @@ class ResolvableMutableInputObjectType extends MutableInputObjectType implements /** @var callable&array{object|string, string} */ private $resolve; /** @var ParameterInterface[]|null */ - private ?array $parameters = null; + private array|null $parameters = null; /** * The list of decorator callables to be applied. * @@ -43,10 +43,8 @@ class ResolvableMutableInputObjectType extends MutableInputObjectType implements */ private array $decoratorsParameters = []; - /** - * @param array $additionalConfig - */ - public function __construct(string $name, private FieldsBuilder $fieldsBuilder, object|string $factory, string $methodName, ?string $comment, private bool $canBeInstantiatedWithoutParameters, array $additionalConfig = []) + /** @param array $additionalConfig */ + public function __construct(string $name, private FieldsBuilder $fieldsBuilder, object|string $factory, string $methodName, string|null $comment, private bool $canBeInstantiatedWithoutParameters, array $additionalConfig = []) { $resolve = [$factory, $methodName]; assert(is_callable($resolve)); @@ -83,9 +81,7 @@ private function getParameters(): array return $this->parameters; } - /** - * @return ParameterInterface[] - */ + /** @return ParameterInterface[] */ private function getParametersForDecorator(int $key): array { if (! isset($this->decoratorsParameters[$key])) { @@ -96,10 +92,8 @@ private function getParametersForDecorator(int $key): array return $this->decoratorsParameters[$key]; } - /** - * @param array $args - */ - public function resolve(?object $source, array $args, mixed $context, ResolveInfo $resolveInfo): object + /** @param array $args */ + public function resolve(object|null $source, array $args, mixed $context, ResolveInfo $resolveInfo): object { $parameters = $this->getParameters(); @@ -142,9 +136,7 @@ public function resolve(?object $source, array $args, mixed $context, ResolveInf return $object; } - /** - * @param callable&array $decorator - */ + /** @param callable&array $decorator */ public function decorate(callable $decorator): void { $this->decorators[] = $decorator; diff --git a/src/Types/TypeAnnotatedObjectType.php b/src/Types/TypeAnnotatedObjectType.php index e1dc286a89..172b23cca8 100644 --- a/src/Types/TypeAnnotatedObjectType.php +++ b/src/Types/TypeAnnotatedObjectType.php @@ -24,10 +24,8 @@ public function __construct(string $className, array $config) parent::__construct($config, $className); } - /** - * @param class-string $className - */ - public static function createFromAnnotatedClass(string $typeName, string $className, ?object $annotatedObject, FieldsBuilder $fieldsBuilder, RecursiveTypeMapperInterface $recursiveTypeMapper, bool $doNotMapInterfaces): self + /** @param class-string $className */ + public static function createFromAnnotatedClass(string $typeName, string $className, object|null $annotatedObject, FieldsBuilder $fieldsBuilder, RecursiveTypeMapperInterface $recursiveTypeMapper, bool $doNotMapInterfaces): self { return new self($className, [ 'name' => $typeName, @@ -60,9 +58,7 @@ 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> - */ + /** @var array> */ $interfaces = class_implements($className); foreach ($interfaces as $interface) { if (! $recursiveTypeMapper->canMapClassToType($interface)) { diff --git a/src/Types/TypeResolver.php b/src/Types/TypeResolver.php index 553c03b92b..208a948b07 100644 --- a/src/Types/TypeResolver.php +++ b/src/Types/TypeResolver.php @@ -26,16 +26,14 @@ */ class TypeResolver { - private ?Schema $schema = null; + private Schema|null $schema = null; public function registerSchema(Schema $schema): void { $this->schema = $schema; } - /** - * @throws CannotMapTypeExceptionInterface - */ + /** @throws CannotMapTypeExceptionInterface */ public function mapNameToType(string $typeName): Type { if ($this->schema === null) { @@ -43,9 +41,7 @@ public function mapNameToType(string $typeName): Type } try { - /** - * @var ListTypeNode|NamedTypeNode|NonNullTypeNode - */ + /** @var ListTypeNode|NamedTypeNode|NonNullTypeNode */ $parsedOutputType = Parser::parseType($typeName); $type = AST::typeFromAST($this->schema, $parsedOutputType); } catch (Error $e) { @@ -59,9 +55,7 @@ public function mapNameToType(string $typeName): Type return $type; } - /** - * @return OutputType&Type - */ + /** @return OutputType&Type */ public function mapNameToOutputType(string $typeName): OutputType { $type = $this->mapNameToType($typeName); @@ -72,9 +66,7 @@ public function mapNameToOutputType(string $typeName): OutputType return $type; } - /** - * @return InputType&Type - */ + /** @return InputType&Type */ public function mapNameToInputType(string $typeName): InputType { $type = $this->mapNameToType($typeName); diff --git a/src/Types/UnionType.php b/src/Types/UnionType.php index b7491f9cfd..b923ea2211 100644 --- a/src/Types/UnionType.php +++ b/src/Types/UnionType.php @@ -13,9 +13,7 @@ class UnionType extends \GraphQL\Type\Definition\UnionType { - /** - * @param array $types - */ + /** @param array $types */ public function __construct(array $types, RecursiveTypeMapperInterface $typeMapper) { $name = 'Union'; diff --git a/src/Utils/Namespaces/NS.php b/src/Utils/Namespaces/NS.php index bf3a017145..65c1b59c7f 100644 --- a/src/Utils/Namespaces/NS.php +++ b/src/Utils/Namespaces/NS.php @@ -27,12 +27,10 @@ final class NS * * @var array> */ - private ?array $classes = null; + private array|null $classes = null; - /** - * @param string $namespace The namespace that contains the GraphQL types (they must have a `@Type` annotation) - */ - public function __construct(private string $namespace, private CacheInterface $cache, private ClassNameMapper $classNameMapper, private ?int $globTTL, private bool $recursive) + /** @param string $namespace The namespace that contains the GraphQL types (they must have a `@Type` annotation) */ + public function __construct(private string $namespace, private CacheInterface $cache, private ClassNameMapper $classNameMapper, private int|null $globTTL, private bool $recursive) { } diff --git a/src/Utils/Namespaces/NamespaceFactory.php b/src/Utils/Namespaces/NamespaceFactory.php index 3e71b36fe6..b10b087a52 100644 --- a/src/Utils/Namespaces/NamespaceFactory.php +++ b/src/Utils/Namespaces/NamespaceFactory.php @@ -16,14 +16,12 @@ final class NamespaceFactory { private ClassNameMapper $classNameMapper; - public function __construct(private CacheInterface $cache, ?ClassNameMapper $classNameMapper = null, private ?int $globTTL = 2) + public function __construct(private CacheInterface $cache, ClassNameMapper|null $classNameMapper = null, private int|null $globTTL = 2) { $this->classNameMapper = $classNameMapper ?? ClassNameMapper::createFromComposerFile(null, null, true); } - /** - * @param string $namespace A PHP namespace - */ + /** @param string $namespace A PHP namespace */ public function createNamespace(string $namespace, bool $recursive = true): NS { return new NS($namespace, $this->cache, $this->classNameMapper, $this->globTTL, $recursive); diff --git a/src/Utils/PropertyAccessor.php b/src/Utils/PropertyAccessor.php index bc436ac6f6..2ff46fc4a7 100644 --- a/src/Utils/PropertyAccessor.php +++ b/src/Utils/PropertyAccessor.php @@ -20,7 +20,7 @@ class PropertyAccessor /** * Finds a getter for a property. */ - public static function findGetter(string $class, string $propertyName): ?string + public static function findGetter(string $class, string $propertyName): string|null { $name = ucfirst($propertyName); @@ -41,7 +41,7 @@ public static function findGetter(string $class, string $propertyName): ?string /** * Finds a setter for a property. */ - public static function findSetter(string $class, string $propertyName): ?string + public static function findSetter(string $class, string $propertyName): string|null { $name = ucfirst($propertyName); @@ -105,9 +105,7 @@ private static function isPublicMethod(string $class, string $methodName): bool return (new ReflectionMethod($class, $methodName))->isPublic(); } - /** - * @throws ReflectionException - */ + /** @throws ReflectionException */ private static function isValidGetter(string $class, string $methodName): bool { $reflection = new ReflectionMethod($class, $methodName); From 95822e43cfbea86a6b55d0d9dc020c6f6b264c17 Mon Sep 17 00:00:00 2001 From: bladl Date: Fri, 21 Oct 2022 17:44:26 +0300 Subject: [PATCH 06/11] Fix some cs-fixer errors manually --- src/InputTypeUtils.php | 2 +- src/Mappers/RecursiveTypeMapper.php | 2 +- src/Mappers/Root/IteratorTypeMapper.php | 2 +- src/Types/TypeAnnotatedObjectType.php | 2 +- src/Types/TypeResolver.php | 5 +---- 5 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/InputTypeUtils.php b/src/InputTypeUtils.php index 56b6fe7718..85a2fba6d0 100644 --- a/src/InputTypeUtils.php +++ b/src/InputTypeUtils.php @@ -38,7 +38,7 @@ public function __construct( */ public function getInputTypeNameAndClassName(ReflectionMethod $method): array { - /** @var class-string */ + /** @var class-string $fqsen */ $fqsen = ltrim((string) $this->validateReturnType($method), '\\'); $factory = $this->annotationReader->getFactoryAnnotation($method); if ($factory === null) { diff --git a/src/Mappers/RecursiveTypeMapper.php b/src/Mappers/RecursiveTypeMapper.php index 31208fafe7..9394f4ff18 100644 --- a/src/Mappers/RecursiveTypeMapper.php +++ b/src/Mappers/RecursiveTypeMapper.php @@ -237,7 +237,7 @@ public function findInterfaces(string $className): array { $interfaces = []; - /** @var array> */ + /** @var array> $implements */ $implements = class_implements($className); foreach ($implements as $interface) { if (! $this->typeMapper->canMapClassToType($interface)) { diff --git a/src/Mappers/Root/IteratorTypeMapper.php b/src/Mappers/Root/IteratorTypeMapper.php index fe6978e867..c77ecba902 100644 --- a/src/Mappers/Root/IteratorTypeMapper.php +++ b/src/Mappers/Root/IteratorTypeMapper.php @@ -213,7 +213,7 @@ private function splitIteratorFromOtherTypes(array &$types): Type|null continue; } - /** @var class-string */ + /** @var class-string $fqcn */ $fqcn = (string) $singleDocBlockType->getFqsen(); $refClass = new ReflectionClass($fqcn); // Note : $refClass->isIterable() is only accessible in PHP 7.2 diff --git a/src/Types/TypeAnnotatedObjectType.php b/src/Types/TypeAnnotatedObjectType.php index 172b23cca8..7179e8bdcb 100644 --- a/src/Types/TypeAnnotatedObjectType.php +++ b/src/Types/TypeAnnotatedObjectType.php @@ -58,7 +58,7 @@ 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> */ + /** @var array> $interfaces */ $interfaces = class_implements($className); foreach ($interfaces as $interface) { if (! $recursiveTypeMapper->canMapClassToType($interface)) { diff --git a/src/Types/TypeResolver.php b/src/Types/TypeResolver.php index 208a948b07..438daeaac1 100644 --- a/src/Types/TypeResolver.php +++ b/src/Types/TypeResolver.php @@ -5,9 +5,6 @@ namespace TheCodingMachine\GraphQLite\Types; use GraphQL\Error\Error; -use GraphQL\Language\AST\ListTypeNode; -use GraphQL\Language\AST\NamedTypeNode; -use GraphQL\Language\AST\NonNullTypeNode; use GraphQL\Language\Parser; use GraphQL\Type\Definition\InputType; use GraphQL\Type\Definition\OutputType; @@ -41,8 +38,8 @@ public function mapNameToType(string $typeName): Type } try { - /** @var ListTypeNode|NamedTypeNode|NonNullTypeNode */ $parsedOutputType = Parser::parseType($typeName); + $type = AST::typeFromAST($this->schema, $parsedOutputType); } catch (Error $e) { throw CannotMapTypeException::createForParseError($e); From 1bd69febc9098b561d5bd0e0c13feba9e12906ae Mon Sep 17 00:00:00 2001 From: bladl Date: Fri, 21 Oct 2022 18:23:12 +0300 Subject: [PATCH 07/11] fix return type --- src/Containers/LazyContainer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Containers/LazyContainer.php b/src/Containers/LazyContainer.php index 01218097f7..06ab3b086c 100644 --- a/src/Containers/LazyContainer.php +++ b/src/Containers/LazyContainer.php @@ -32,7 +32,7 @@ public function __construct(private array $entries, ContainerInterface|null $del $this->delegateLookupContainer = $delegateLookupContainer ?: $this; } - public function get(string $id): mixed + public function get(string $id) { if (isset($this->objects[$id])) { return $this->objects[$id]; From 9a50bd3318e158568bd060d9e29921e503607551 Mon Sep 17 00:00:00 2001 From: bladl Date: Fri, 21 Oct 2022 18:25:04 +0300 Subject: [PATCH 08/11] abandon psr/container ^1 --- composer.json | 2 +- src/Containers/LazyContainer.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index aeeb57ed84..18f9b43f22 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "composer/package-versions-deprecated": "^1.8", "phpdocumentor/reflection-docblock": "^4.3 || ^5.0", "phpdocumentor/type-resolver": "^1.4", - "psr/container": "^1 || ^2", + "psr/container": "^2", "psr/http-factory": "^1", "psr/http-message": "^1.0.1", "psr/http-server-handler": "^1", diff --git a/src/Containers/LazyContainer.php b/src/Containers/LazyContainer.php index 06ab3b086c..1f3bb4786d 100644 --- a/src/Containers/LazyContainer.php +++ b/src/Containers/LazyContainer.php @@ -32,7 +32,7 @@ public function __construct(private array $entries, ContainerInterface|null $del $this->delegateLookupContainer = $delegateLookupContainer ?: $this; } - public function get(string $id) + public function get(string $id):mixed { if (isset($this->objects[$id])) { return $this->objects[$id]; From 307777f44719de1756a9ecda88ad1912251ed29b Mon Sep 17 00:00:00 2001 From: bladl Date: Mon, 24 Oct 2022 10:56:44 +0300 Subject: [PATCH 09/11] Test for LazyContainer --- src/Containers/LazyContainer.php | 4 +-- tests/Containers/LazyContainerTest.php | 46 ++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 tests/Containers/LazyContainerTest.php diff --git a/src/Containers/LazyContainer.php b/src/Containers/LazyContainer.php index 1f3bb4786d..1148167473 100644 --- a/src/Containers/LazyContainer.php +++ b/src/Containers/LazyContainer.php @@ -32,13 +32,13 @@ public function __construct(private array $entries, ContainerInterface|null $del $this->delegateLookupContainer = $delegateLookupContainer ?: $this; } - public function get(string $id):mixed + public function get(string $id): mixed { if (isset($this->objects[$id])) { return $this->objects[$id]; } if (! isset($this->entries[$id])) { - throw throw NotFoundException::notFoundInContainer($id); + throw NotFoundException::notFoundInContainer($id); } return $this->objects[$id] = $this->entries[$id]($this->delegateLookupContainer); diff --git a/tests/Containers/LazyContainerTest.php b/tests/Containers/LazyContainerTest.php new file mode 100644 index 0000000000..34637d4091 --- /dev/null +++ b/tests/Containers/LazyContainerTest.php @@ -0,0 +1,46 @@ + static fn () => 'bar', + ]); + } + + public function testFromContainer(): void + { + $container = $this->buildAutoWiringContainer($this->getContainer()); + + $this->assertTrue($container->has('foo')); + $this->assertFalse($container->has('bar')); + + $this->assertSame('bar', $container->get('foo')); + } + + public function testInstantiate(): void + { + $container = $this->buildAutoWiringContainer($this->getContainer()); + + $this->assertTrue($container->has(TestType::class)); + $type = $container->get(TestType::class); + $this->assertInstanceOf(TestType::class, $type); + $this->assertSame($type, $container->get(TestType::class)); + $this->assertTrue($container->has(TestType::class)); + } + + public function testNotFound(): void + { + $container = $this->buildAutoWiringContainer($this->getContainer()); + $this->expectException(NotFoundException::class); + $container->get('notfound'); + } +} From af0a1f3d80a2ee64561f842f9c6c88eab231a4c3 Mon Sep 17 00:00:00 2001 From: bladl Date: Sat, 29 Oct 2022 00:27:40 +0300 Subject: [PATCH 10/11] Normalize RootTypeMapperInterface --- src/Mappers/Root/BaseTypeMapper.php | 2 +- src/Mappers/Root/CompoundTypeMapper.php | 2 +- src/Mappers/Root/EnumTypeMapper.php | 4 ++-- src/Mappers/Root/FinalRootTypeMapper.php | 2 +- src/Mappers/Root/IteratorTypeMapper.php | 2 +- src/Mappers/Root/MyCLabsEnumTypeMapper.php | 3 +-- src/Mappers/Root/NullableTypeMapperAdapter.php | 2 +- src/Mappers/Root/RootTypeMapperInterface.php | 2 +- tests/Mappers/Root/NullableTypeMapperAdapterTest.php | 2 +- tests/Mappers/Root/VoidRootTypeMapper.php | 12 ++++-------- 10 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/Mappers/Root/BaseTypeMapper.php b/src/Mappers/Root/BaseTypeMapper.php index 19e8b03d3d..22ec7a8ff6 100644 --- a/src/Mappers/Root/BaseTypeMapper.php +++ b/src/Mappers/Root/BaseTypeMapper.php @@ -78,7 +78,7 @@ public function toGraphQLOutputType(Type $type, OutputType|null $subType, Reflec * @throws CannotMapTypeException * @throws CannotMapTypeExceptionInterface */ - public function toGraphQLInputType(Type $type, InputType|GraphQLType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType|GraphQLType + public function toGraphQLInputType(Type $type, InputType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType { $mappedType = $this->mapBaseType($type); if ($mappedType !== null) { diff --git a/src/Mappers/Root/CompoundTypeMapper.php b/src/Mappers/Root/CompoundTypeMapper.php index 2780769356..ed9f995873 100644 --- a/src/Mappers/Root/CompoundTypeMapper.php +++ b/src/Mappers/Root/CompoundTypeMapper.php @@ -81,7 +81,7 @@ public function toGraphQLOutputType(Type $type, OutputType|null $subType, Reflec return $return; } - public function toGraphQLInputType(Type $type, InputType|GraphQLType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType|GraphQLType + public function toGraphQLInputType(Type $type, InputType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType { if (! $type instanceof Compound) { return $this->next->toGraphQLInputType($type, $subType, $argumentName, $reflector, $docBlockObj); diff --git a/src/Mappers/Root/EnumTypeMapper.php b/src/Mappers/Root/EnumTypeMapper.php index 434f901430..fbe6e6802f 100644 --- a/src/Mappers/Root/EnumTypeMapper.php +++ b/src/Mappers/Root/EnumTypeMapper.php @@ -65,11 +65,11 @@ public function toGraphQLOutputType( */ public function toGraphQLInputType( Type $type, - InputType|GraphQLType|null $subType, + InputType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj, - ): InputType|GraphQLType + ): InputType { $result = $this->map($type); if ($result === null) { diff --git a/src/Mappers/Root/FinalRootTypeMapper.php b/src/Mappers/Root/FinalRootTypeMapper.php index a9cceb5c99..e7881c5843 100644 --- a/src/Mappers/Root/FinalRootTypeMapper.php +++ b/src/Mappers/Root/FinalRootTypeMapper.php @@ -40,7 +40,7 @@ public function toGraphQLOutputType(Type $type, OutputType|null $subType, Reflec } /** @throws CannotMapTypeException */ - public function toGraphQLInputType(Type $type, InputType|GraphQLType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType|GraphQLType + public function toGraphQLInputType(Type $type, InputType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType { throw CannotMapTypeException::createForPhpDocType($type); } diff --git a/src/Mappers/Root/IteratorTypeMapper.php b/src/Mappers/Root/IteratorTypeMapper.php index c77ecba902..f0eaca1ab7 100644 --- a/src/Mappers/Root/IteratorTypeMapper.php +++ b/src/Mappers/Root/IteratorTypeMapper.php @@ -70,7 +70,7 @@ public function toGraphQLOutputType(Type $type, OutputType|null $subType, Reflec return $result; } - public function toGraphQLInputType(Type $type, InputType|GraphQLType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType|GraphQLType + public function toGraphQLInputType(Type $type, InputType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType { if (! $type instanceof Compound) { //try { diff --git a/src/Mappers/Root/MyCLabsEnumTypeMapper.php b/src/Mappers/Root/MyCLabsEnumTypeMapper.php index 5d9630c278..1797e27720 100644 --- a/src/Mappers/Root/MyCLabsEnumTypeMapper.php +++ b/src/Mappers/Root/MyCLabsEnumTypeMapper.php @@ -8,7 +8,6 @@ use GraphQL\Type\Definition\InputType; use GraphQL\Type\Definition\NamedType; use GraphQL\Type\Definition\OutputType; -use GraphQL\Type\Definition\Type as GraphQLType; use MyCLabs\Enum\Enum; use phpDocumentor\Reflection\DocBlock; use phpDocumentor\Reflection\Type; @@ -46,7 +45,7 @@ public function toGraphQLOutputType(Type $type, OutputType|null $subType, Reflec return $result ?? $this->next->toGraphQLOutputType($type, $subType, $reflector, $docBlockObj); } - public function toGraphQLInputType(Type $type, InputType|GraphQLType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType|GraphQLType + public function toGraphQLInputType(Type $type, InputType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType { $result = $this->map($type); return $result ?? $this->next->toGraphQLInputType($type, $subType, $argumentName, $reflector, $docBlockObj); diff --git a/src/Mappers/Root/NullableTypeMapperAdapter.php b/src/Mappers/Root/NullableTypeMapperAdapter.php index 06f11beef0..09260e0d16 100644 --- a/src/Mappers/Root/NullableTypeMapperAdapter.php +++ b/src/Mappers/Root/NullableTypeMapperAdapter.php @@ -65,7 +65,7 @@ public function toGraphQLOutputType(Type $type, OutputType|GraphQLType|null $sub return $graphQlType; } - public function toGraphQLInputType(Type $type, InputType|GraphQLType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType|GraphQLType + public function toGraphQLInputType(Type $type, InputType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType { // Let's check a "null" value in the docblock $isNullable = $this->isNullable($type); diff --git a/src/Mappers/Root/RootTypeMapperInterface.php b/src/Mappers/Root/RootTypeMapperInterface.php index 1a9faa16cc..03fc11aa11 100644 --- a/src/Mappers/Root/RootTypeMapperInterface.php +++ b/src/Mappers/Root/RootTypeMapperInterface.php @@ -37,7 +37,7 @@ public function toGraphQLOutputType(Type $type, OutputType|null $subType, Reflec * * @return InputType&GraphQLType */ - public function toGraphQLInputType(Type $type, InputType|GraphQLType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType|GraphQLType; + public function toGraphQLInputType(Type $type, InputType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType; /** * Returns a GraphQL type by name. diff --git a/tests/Mappers/Root/NullableTypeMapperAdapterTest.php b/tests/Mappers/Root/NullableTypeMapperAdapterTest.php index c8a52f1ee4..447d12f503 100644 --- a/tests/Mappers/Root/NullableTypeMapperAdapterTest.php +++ b/tests/Mappers/Root/NullableTypeMapperAdapterTest.php @@ -55,7 +55,7 @@ public function toGraphQLOutputType(Type $type, ?OutputType $subType, $reflector return new NonNull(new StringType()); } - public function toGraphQLInputType(Type $type, null|InputType|GraphQLType $subType, string $argumentName, $reflector, DocBlock $docBlockObj): InputType + public function toGraphQLInputType(Type $type, null|InputType $subType, string $argumentName, $reflector, DocBlock $docBlockObj): InputType { throw new \RuntimeException('Not implemented'); } diff --git a/tests/Mappers/Root/VoidRootTypeMapper.php b/tests/Mappers/Root/VoidRootTypeMapper.php index 168140724f..42b0c17906 100644 --- a/tests/Mappers/Root/VoidRootTypeMapper.php +++ b/tests/Mappers/Root/VoidRootTypeMapper.php @@ -1,9 +1,9 @@ next->toGraphQLOutputType($type, $subType, $reflector, $docBlockObj); } /** * @param (InputType&GraphQLType)|null $subType - * @param ReflectionMethod|ReflectionProperty $reflector * * @return InputType&GraphQLType */ - public function toGraphQLInputType(Type $type, null|InputType|GraphQLType $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType|GraphQLType + public function toGraphQLInputType(Type $type, InputType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType { return $this->next->toGraphQLInputType($type, $subType, $argumentName, $reflector, $docBlockObj); } From e7e49e1e2b42b88956f662a8c71e9a733436b82b Mon Sep 17 00:00:00 2001 From: bladl Date: Sat, 17 Dec 2022 12:16:57 +0200 Subject: [PATCH 11/11] end-to-end test with enums in mutation and as single-returned field --- .../Controllers/ButtonController.php | 19 +- .../Integration/Models/Position.php | 4 +- tests/Fixtures81/Integration/Models/Size.php | 4 +- tests/Integration/EndToEndTest.php | 788 ++++++++---------- 4 files changed, 367 insertions(+), 448 deletions(-) diff --git a/tests/Fixtures81/Integration/Controllers/ButtonController.php b/tests/Fixtures81/Integration/Controllers/ButtonController.php index d2b9e31971..2d9b66d6f4 100644 --- a/tests/Fixtures81/Integration/Controllers/ButtonController.php +++ b/tests/Fixtures81/Integration/Controllers/ButtonController.php @@ -4,19 +4,30 @@ namespace TheCodingMachine\GraphQLite\Fixtures81\Integration\Controllers; +use TheCodingMachine\GraphQLite\Annotations\Mutation; use TheCodingMachine\GraphQLite\Annotations\Query; use TheCodingMachine\GraphQLite\Fixtures81\Integration\Models\Button; use TheCodingMachine\GraphQLite\Fixtures81\Integration\Models\Color; use TheCodingMachine\GraphQLite\Fixtures81\Integration\Models\Position; use TheCodingMachine\GraphQLite\Fixtures81\Integration\Models\Size; -class ButtonController +final class ButtonController { - /** - * @Query() - */ + #[Query] public function getButton(Color $color, Size $size, Position $state): Button { return new Button($color, $size, $state); } + + #[Mutation] + public function updateButton(Color $color, Size $size, Position $state): Button + { + return new Button($color, $size, $state); + } + + #[Mutation] + public function singleEnum(Size $size): Size + { + return $size; + } } diff --git a/tests/Fixtures81/Integration/Models/Position.php b/tests/Fixtures81/Integration/Models/Position.php index 07e9638929..efd8cdf0db 100644 --- a/tests/Fixtures81/Integration/Models/Position.php +++ b/tests/Fixtures81/Integration/Models/Position.php @@ -6,9 +6,7 @@ use TheCodingMachine\GraphQLite\Annotations\Type; -/** - * @Type - */ +#[Type] enum Position: int { case Off = 0; diff --git a/tests/Fixtures81/Integration/Models/Size.php b/tests/Fixtures81/Integration/Models/Size.php index 677e8d5eb2..0ed23d2c81 100644 --- a/tests/Fixtures81/Integration/Models/Size.php +++ b/tests/Fixtures81/Integration/Models/Size.php @@ -6,9 +6,7 @@ use TheCodingMachine\GraphQLite\Annotations\Type; -/** - * @Type - */ +#[Type] enum Size { case S; diff --git a/tests/Integration/EndToEndTest.php b/tests/Integration/EndToEndTest.php index b1f75ee64f..1a0e4c346f 100644 --- a/tests/Integration/EndToEndTest.php +++ b/tests/Integration/EndToEndTest.php @@ -1,5 +1,7 @@ mainContainer = $this->createContainer(); } - /** - * @param array $overloadedServices - */ + /** @param array $overloadedServices */ public function createContainer(array $overloadedServices = []): ContainerInterface { $services = [ - Schema::class => function(ContainerInterface $container) { + Schema::class => static function (ContainerInterface $container) { return new Schema($container->get(QueryProviderInterface::class), $container->get(RecursiveTypeMapperInterface::class), $container->get(TypeResolver::class), $container->get(RootTypeMapperInterface::class)); }, - QueryProviderInterface::class => function(ContainerInterface $container) { + QueryProviderInterface::class => static function (ContainerInterface $container) { $queryProvider = new GlobControllerQueryProvider( 'TheCodingMachine\\GraphQLite\\Fixtures\\Integration\\Controllers', $container->get(FieldsBuilder::class), $container->get(BasicAutoWiringContainer::class), $container->get(AnnotationReader::class), - new Psr16Cache(new ArrayAdapter()) + new Psr16Cache(new ArrayAdapter()), ); if (interface_exists(UnitEnum::class)) { @@ -114,13 +123,13 @@ public function createContainer(array $overloadedServices = []): ContainerInterf $container->get(FieldsBuilder::class), $container->get(BasicAutoWiringContainer::class), $container->get(AnnotationReader::class), - new Psr16Cache(new ArrayAdapter()) - ) + new Psr16Cache(new ArrayAdapter()), + ), ]); } return $queryProvider; }, - FieldsBuilder::class => function(ContainerInterface $container) { + FieldsBuilder::class => static function (ContainerInterface $container) { return new FieldsBuilder( $container->get(AnnotationReader::class), $container->get(RecursiveTypeMapperInterface::class), @@ -131,63 +140,63 @@ public function createContainer(array $overloadedServices = []): ContainerInterf $container->get(RootTypeMapperInterface::class), $container->get(ParameterMiddlewareInterface::class), $container->get(FieldMiddlewareInterface::class), - $container->get(InputFieldMiddlewareInterface::class) + $container->get(InputFieldMiddlewareInterface::class), ); }, - FieldMiddlewareInterface::class => function(ContainerInterface $container) { + FieldMiddlewareInterface::class => static function (ContainerInterface $container) { $pipe = new FieldMiddlewarePipe(); $pipe->pipe($container->get(AuthorizationFieldMiddleware::class)); $pipe->pipe($container->get(SecurityFieldMiddleware::class)); return $pipe; }, - InputFieldMiddlewareInterface::class => function(ContainerInterface $container) { + InputFieldMiddlewareInterface::class => static function (ContainerInterface $container) { $pipe = new InputFieldMiddlewarePipe(); $pipe->pipe($container->get(AuthorizationInputFieldMiddleware::class)); $pipe->pipe($container->get(SecurityInputFieldMiddleware::class)); return $pipe; }, - AuthorizationInputFieldMiddleware::class => function(ContainerInterface $container) { + AuthorizationInputFieldMiddleware::class => static function (ContainerInterface $container) { return new AuthorizationInputFieldMiddleware( $container->get(AuthenticationServiceInterface::class), - $container->get(AuthorizationServiceInterface::class) + $container->get(AuthorizationServiceInterface::class), ); }, - SecurityInputFieldMiddleware::class => function(ContainerInterface $container) { + SecurityInputFieldMiddleware::class => static function (ContainerInterface $container) { return new SecurityInputFieldMiddleware( new ExpressionLanguage(new Psr16Adapter(new Psr16Cache(new ArrayAdapter())), [new SecurityExpressionLanguageProvider()]), $container->get(AuthenticationServiceInterface::class), - $container->get(AuthorizationServiceInterface::class) + $container->get(AuthorizationServiceInterface::class), ); }, - AuthorizationFieldMiddleware::class => function(ContainerInterface $container) { + AuthorizationFieldMiddleware::class => static function (ContainerInterface $container) { return new AuthorizationFieldMiddleware( $container->get(AuthenticationServiceInterface::class), - $container->get(AuthorizationServiceInterface::class) + $container->get(AuthorizationServiceInterface::class), ); }, - SecurityFieldMiddleware::class => function(ContainerInterface $container) { + SecurityFieldMiddleware::class => static function (ContainerInterface $container) { return new SecurityFieldMiddleware( new ExpressionLanguage(new Psr16Adapter(new Psr16Cache(new ArrayAdapter())), [new SecurityExpressionLanguageProvider()]), $container->get(AuthenticationServiceInterface::class), - $container->get(AuthorizationServiceInterface::class) + $container->get(AuthorizationServiceInterface::class), ); }, - ArgumentResolver::class => function(ContainerInterface $container) { + ArgumentResolver::class => static function (ContainerInterface $container) { return new ArgumentResolver(); }, - TypeResolver::class => function(ContainerInterface $container) { + TypeResolver::class => static function (ContainerInterface $container) { return new TypeResolver(); }, - BasicAutoWiringContainer::class => function(ContainerInterface $container) { + BasicAutoWiringContainer::class => static function (ContainerInterface $container) { return new BasicAutoWiringContainer(new EmptyContainer()); }, - AuthorizationServiceInterface::class => function(ContainerInterface $container) { + AuthorizationServiceInterface::class => static function (ContainerInterface $container) { return new VoidAuthorizationService(); }, - AuthenticationServiceInterface::class => function(ContainerInterface $container) { + AuthenticationServiceInterface::class => static function (ContainerInterface $container) { return new VoidAuthenticationService(); }, - RecursiveTypeMapperInterface::class => function(ContainerInterface $container) { + RecursiveTypeMapperInterface::class => static function (ContainerInterface $container) { $arrayAdapter = new ArrayAdapter(); $arrayAdapter->setLogger(new ExceptionLogger()); return new RecursiveTypeMapper( @@ -195,21 +204,22 @@ public function createContainer(array $overloadedServices = []): ContainerInterf $container->get(NamingStrategyInterface::class), new Psr16Cache($arrayAdapter), $container->get(TypeRegistry::class), - $container->get(AnnotationReader::class) + $container->get(AnnotationReader::class), ); }, - TypeMapperInterface::class => function(ContainerInterface $container) { + TypeMapperInterface::class => static function (ContainerInterface $container) { return new CompositeTypeMapper(); }, - NamespaceFactory::class => function(ContainerInterface $container) { + NamespaceFactory::class => static function (ContainerInterface $container) { $arrayAdapter = new ArrayAdapter(); $arrayAdapter->setLogger(new ExceptionLogger()); return new NamespaceFactory(new Psr16Cache($arrayAdapter)); }, - GlobTypeMapper::class => function(ContainerInterface $container) { + GlobTypeMapper::class => static function (ContainerInterface $container) { $arrayAdapter = new ArrayAdapter(); $arrayAdapter->setLogger(new ExceptionLogger()); - return new GlobTypeMapper($container->get(NamespaceFactory::class)->createNamespace('TheCodingMachine\\GraphQLite\\Fixtures\\Integration\\Types'), + return new GlobTypeMapper( + $container->get(NamespaceFactory::class)->createNamespace('TheCodingMachine\\GraphQLite\\Fixtures\\Integration\\Types'), $container->get(TypeGenerator::class), $container->get(InputTypeGenerator::class), $container->get(InputTypeUtils::class), @@ -217,14 +227,15 @@ public function createContainer(array $overloadedServices = []): ContainerInterf $container->get(AnnotationReader::class), $container->get(NamingStrategyInterface::class), $container->get(RecursiveTypeMapperInterface::class), - new Psr16Cache($arrayAdapter) + new Psr16Cache($arrayAdapter), ); }, // We use a second type mapper here so we can target the Models dir - GlobTypeMapper::class.'2' => function(ContainerInterface $container) { + GlobTypeMapper::class . '2' => static function (ContainerInterface $container) { $arrayAdapter = new ArrayAdapter(); $arrayAdapter->setLogger(new ExceptionLogger()); - return new GlobTypeMapper($container->get(NamespaceFactory::class)->createNamespace('TheCodingMachine\\GraphQLite\\Fixtures\\Integration\\Models'), + return new GlobTypeMapper( + $container->get(NamespaceFactory::class)->createNamespace('TheCodingMachine\\GraphQLite\\Fixtures\\Integration\\Models'), $container->get(TypeGenerator::class), $container->get(InputTypeGenerator::class), $container->get(InputTypeUtils::class), @@ -232,63 +243,63 @@ public function createContainer(array $overloadedServices = []): ContainerInterf $container->get(AnnotationReader::class), $container->get(NamingStrategyInterface::class), $container->get(RecursiveTypeMapperInterface::class), - new Psr16Cache($arrayAdapter) + new Psr16Cache($arrayAdapter), ); }, - PorpaginasTypeMapper::class => function(ContainerInterface $container) { + PorpaginasTypeMapper::class => static function (ContainerInterface $container) { return new PorpaginasTypeMapper($container->get(RecursiveTypeMapperInterface::class)); }, - EnumTypeMapper::class => function(ContainerInterface $container) { + EnumTypeMapper::class => static function (ContainerInterface $container) { return new EnumTypeMapper( $container->get(RootTypeMapperInterface::class), $container->get(AnnotationReader::class), new ArrayAdapter(), [ $container->get(NamespaceFactory::class) - ->createNamespace('TheCodingMachine\\GraphQLite\\Fixtures81\\Integration\\Models') - ] + ->createNamespace('TheCodingMachine\\GraphQLite\\Fixtures81\\Integration\\Models'), + ], ); }, - TypeGenerator::class => function(ContainerInterface $container) { + TypeGenerator::class => static function (ContainerInterface $container) { return new TypeGenerator( $container->get(AnnotationReader::class), $container->get(NamingStrategyInterface::class), $container->get(TypeRegistry::class), $container->get(BasicAutoWiringContainer::class), $container->get(RecursiveTypeMapperInterface::class), - $container->get(FieldsBuilder::class) + $container->get(FieldsBuilder::class), ); }, - TypeRegistry::class => function() { + TypeRegistry::class => static function () { return new TypeRegistry(); }, - InputTypeGenerator::class => function(ContainerInterface $container) { + InputTypeGenerator::class => static function (ContainerInterface $container) { return new InputTypeGenerator( $container->get(InputTypeUtils::class), - $container->get(FieldsBuilder::class) + $container->get(FieldsBuilder::class), ); }, - InputTypeUtils::class => function(ContainerInterface $container) { + InputTypeUtils::class => static function (ContainerInterface $container) { return new InputTypeUtils( $container->get(AnnotationReader::class), - $container->get(NamingStrategyInterface::class) + $container->get(NamingStrategyInterface::class), ); }, - AnnotationReader::class => function(ContainerInterface $container) { + AnnotationReader::class => static function (ContainerInterface $container) { return new AnnotationReader(new DoctrineAnnotationReader()); }, - NamingStrategyInterface::class => function() { + NamingStrategyInterface::class => static function () { return new NamingStrategy(); }, - CachedDocBlockFactory::class => function() { + CachedDocBlockFactory::class => static function () { $arrayAdapter = new ArrayAdapter(); $arrayAdapter->setLogger(new ExceptionLogger()); return new CachedDocBlockFactory(new Psr16Cache($arrayAdapter)); }, - RootTypeMapperInterface::class => function(ContainerInterface $container) { + RootTypeMapperInterface::class => static function (ContainerInterface $container) { return new NullableTypeMapperAdapter(); }, - 'rootTypeMapper' => function(ContainerInterface $container) { + 'rootTypeMapper' => static function (ContainerInterface $container) { // These are in reverse order of execution $errorRootTypeMapper = new FinalRootTypeMapper($container->get(RecursiveTypeMapperInterface::class)); $rootTypeMapper = new BaseTypeMapper($errorRootTypeMapper, $container->get(RecursiveTypeMapperInterface::class), $container->get(RootTypeMapperInterface::class)); @@ -300,36 +311,37 @@ public function createContainer(array $overloadedServices = []): ContainerInterf $rootTypeMapper = new IteratorTypeMapper($rootTypeMapper, $container->get(RootTypeMapperInterface::class)); return $rootTypeMapper; }, - ContainerParameterHandler::class => function(ContainerInterface $container) { + ContainerParameterHandler::class => static function (ContainerInterface $container) { return new ContainerParameterHandler($container, true, true); }, - InjectUserParameterHandler::class => function(ContainerInterface $container) { + InjectUserParameterHandler::class => static function (ContainerInterface $container) { return new InjectUserParameterHandler($container->get(AuthenticationServiceInterface::class)); }, - 'testService' => function() { + 'testService' => static function () { return 'foo'; }, - stdClass::class => function() { + stdClass::class => static function () { // Empty test service for autowiring return new stdClass(); }, - ParameterMiddlewareInterface::class => function(ContainerInterface $container) { + ParameterMiddlewareInterface::class => static function (ContainerInterface $container) { $parameterMiddlewarePipe = new ParameterMiddlewarePipe(); $parameterMiddlewarePipe->pipe(new ResolveInfoParameterHandler()); $parameterMiddlewarePipe->pipe($container->get(ContainerParameterHandler::class)); $parameterMiddlewarePipe->pipe($container->get(InjectUserParameterHandler::class)); return $parameterMiddlewarePipe; - } + }, ]; if (interface_exists(UnitEnum::class)) { // Register another instance of GlobTypeMapper to process our PHP 8.1 enums and/or other // 8.1 supported features. - $services[GlobTypeMapper::class.'3'] = function(ContainerInterface $container) { + $services[GlobTypeMapper::class . '3'] = static function (ContainerInterface $container) { $arrayAdapter = new ArrayAdapter(); $arrayAdapter->setLogger(new ExceptionLogger()); - return new GlobTypeMapper($container->get(NamespaceFactory::class)->createNamespace('TheCodingMachine\\GraphQLite\\Fixtures81\\Integration\\Models'), + return new GlobTypeMapper( + $container->get(NamespaceFactory::class)->createNamespace('TheCodingMachine\\GraphQLite\\Fixtures81\\Integration\\Models'), $container->get(TypeGenerator::class), $container->get(InputTypeGenerator::class), $container->get(InputTypeUtils::class), @@ -337,7 +349,7 @@ public function createContainer(array $overloadedServices = []): ContainerInterf $container->get(AnnotationReader::class), $container->get(NamingStrategyInterface::class), $container->get(RecursiveTypeMapperInterface::class), - new Psr16Cache($arrayAdapter) + new Psr16Cache($arrayAdapter), ); }; } @@ -345,9 +357,9 @@ public function createContainer(array $overloadedServices = []): ContainerInterf $container = new LazyContainer($overloadedServices + $services); $container->get(TypeResolver::class)->registerSchema($container->get(Schema::class)); $container->get(TypeMapperInterface::class)->addTypeMapper($container->get(GlobTypeMapper::class)); - $container->get(TypeMapperInterface::class)->addTypeMapper($container->get(GlobTypeMapper::class.'2')); + $container->get(TypeMapperInterface::class)->addTypeMapper($container->get(GlobTypeMapper::class . '2')); if (interface_exists(UnitEnum::class)) { - $container->get(TypeMapperInterface::class)->addTypeMapper($container->get(GlobTypeMapper::class.'3')); + $container->get(TypeMapperInterface::class)->addTypeMapper($container->get(GlobTypeMapper::class . '3')); } $container->get(TypeMapperInterface::class)->addTypeMapper($container->get(PorpaginasTypeMapper::class)); @@ -361,23 +373,19 @@ public function createContainer(array $overloadedServices = []): ContainerInterf return $container; } - /** - * @return mixed - */ - private function getSuccessResult(ExecutionResult $result, int $debugFlag = DebugFlag::RETHROW_INTERNAL_EXCEPTIONS) { + private function getSuccessResult(ExecutionResult $result, int $debugFlag = DebugFlag::RETHROW_INTERNAL_EXCEPTIONS): mixed + { $array = $result->toArray($debugFlag); - if (isset($array['errors']) || !isset($array['data'])) { - $this->fail('Expected a successful answer. Got '.json_encode($array, JSON_PRETTY_PRINT)); + if (isset($array['errors']) || ! isset($array['data'])) { + $this->fail('Expected a successful answer. Got ' . json_encode($array, JSON_PRETTY_PRINT)); } return $array['data']; } public function testEndToEnd(): void { - /** - * @var Schema $schema - */ $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); $schema->assertValid(); @@ -400,7 +408,7 @@ public function testEndToEnd(): void $schema, $queryString, null, - new Context() + new Context(), ); $this->assertSame([ @@ -418,10 +426,10 @@ public function testEndToEnd(): void 'uppercaseName' => 'BILL', 'repeatName' => 'fooBillbar', 'repeatInnerName' => 'Bill', - 'email' => 'bill@example.com' - ] + 'email' => 'bill@example.com', + ], - ] + ], ], $this->getSuccessResult($result)); // Let's redo this to test cache. @@ -429,7 +437,7 @@ public function testEndToEnd(): void $schema, $queryString, null, - new Context() + new Context(), ); $this->assertSame([ @@ -447,19 +455,17 @@ public function testEndToEnd(): void 'uppercaseName' => 'BILL', 'repeatName' => 'fooBillbar', 'repeatInnerName' => 'Bill', - 'email' => 'bill@example.com' - ] + 'email' => 'bill@example.com', + ], - ] + ], ], $this->getSuccessResult($result)); } public function testDeprecatedField(): void { - /** - * @var Schema $schema - */ $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); $schema->assertValid(); @@ -478,7 +484,7 @@ public function testDeprecatedField(): void $schema, $queryString, null, - new Context() + new Context(), ); $this->assertSame([ @@ -494,9 +500,9 @@ public function testDeprecatedField(): void 'uppercaseName' => 'BILL', 'deprecatedUppercaseName' => 'BILL', 'deprecatedName' => 'Bill', - ] + ], - ] + ], ], $this->getSuccessResult($result)); // Let's introspect to see if the field is marked as deprecated @@ -517,15 +523,15 @@ public function testDeprecatedField(): void $schema, $queryString, null, - new Context() + new Context(), ); $fields = $this->getSuccessResult($result)['__type']['fields']; $deprecatedFields = [ 'deprecatedUppercaseName', - 'deprecatedName' + 'deprecatedName', ]; - $fields = array_filter($fields, function($field) use ($deprecatedFields) { + $fields = array_filter($fields, static function ($field) use ($deprecatedFields) { if (in_array($field['name'], $deprecatedFields)) { return true; } @@ -534,27 +540,25 @@ public function testDeprecatedField(): void $this->assertCount( count($deprecatedFields), $fields, - 'Missing deprecated fields on GraphQL Schema' + 'Missing deprecated fields on GraphQL Schema', ); foreach ($fields as $field) { $this->assertTrue( $field['isDeprecated'], - 'Field ' . $field['name'] . ' must be marked deprecated, but is not' + 'Field ' . $field['name'] . ' must be marked deprecated, but is not', ); $this->assertStringContainsString( 'use field ', $field['deprecationReason'], - 'Field ' . $field['name'] . ' is misssing a deprecation reason' + 'Field ' . $field['name'] . ' is misssing a deprecation reason', ); } } public function testPrefetchException(): void { - /** - * @var Schema $schema - */ $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); $schema->assertValid(); @@ -575,7 +579,7 @@ public function testPrefetchException(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->expectException(GraphQLRuntimeException::class); @@ -583,12 +587,10 @@ public function testPrefetchException(): void $result->toArray(DebugFlag::RETHROW_INTERNAL_EXCEPTIONS); } - public function testEndToEndInputTypeDate() + public function testEndToEndInputTypeDate(): void { - /** - * @var Schema $schema - */ $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); $queryString = ' mutation { saveBirthDate(birthDate: "1942-12-24T00:00:00+00:00") { @@ -600,23 +602,21 @@ public function testEndToEndInputTypeDate() $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->assertSame([ 'saveBirthDate' => [ 'name' => 'Bill', 'birthDate' => '1942-12-24T00:00:00+00:00', - ] + ], ], $this->getSuccessResult($result)); } - public function testEndToEndInputTypeDateAsParam() + public function testEndToEndInputTypeDateAsParam(): void { - /** - * @var Schema $schema - */ $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); $queryString = ' mutation($birthDate: DateTime!) { saveBirthDate(birthDate: $birthDate) { @@ -631,25 +631,21 @@ public function testEndToEndInputTypeDateAsParam() $queryString, null, null, - [ - "birthDate" => "1942-12-24T00:00:00+00:00" - ] + ['birthDate' => '1942-12-24T00:00:00+00:00'], ); $this->assertSame([ 'saveBirthDate' => [ 'name' => 'Bill', 'birthDate' => '1942-12-24T00:00:00+00:00', - ] + ], ], $this->getSuccessResult($result)); } - public function testEndToEndInputType() + public function testEndToEndInputType(): void { - /** - * @var Schema $schema - */ $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); $queryString = ' mutation { saveContact( @@ -674,7 +670,7 @@ public function testEndToEndInputType() $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->assertSame([ @@ -682,20 +678,16 @@ public function testEndToEndInputType() 'name' => 'foo', 'birthDate' => '1942-12-24T00:00:00+00:00', 'relations' => [ - [ - 'name' => 'bar', - ] - ] - ] + ['name' => 'bar'], + ], + ], ], $this->getSuccessResult($result)); } public function testEndToEndPorpaginas(): void { - /** - * @var Schema $schema - */ $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); $queryString = ' query { @@ -714,7 +706,7 @@ public function testEndToEndPorpaginas(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->assertSame([ @@ -723,17 +715,17 @@ public function testEndToEndPorpaginas(): void [ 'name' => 'Bill', 'uppercaseName' => 'BILL', - 'email' => 'bill@example.com' - ] + 'email' => 'bill@example.com', + ], ], - 'count' => 2 - ] + 'count' => 2, + ], ], $this->getSuccessResult($result)); // Let's redo this to test cache. $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->assertSame([ @@ -742,11 +734,11 @@ public function testEndToEndPorpaginas(): void [ 'name' => 'Bill', 'uppercaseName' => 'BILL', - 'email' => 'bill@example.com' - ] + 'email' => 'bill@example.com', + ], ], - 'count' => 2 - ] + 'count' => 2, + ], ], $this->getSuccessResult($result)); // Let's run a query with no limit but an offset @@ -766,12 +758,11 @@ public function testEndToEndPorpaginas(): void $result = GraphQL::executeQuery( $schema, - $invalidQueryString + $invalidQueryString, ); $this->assertSame('In the items field of a result set, you cannot add a "offset" without also adding a "limit"', $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS)['errors'][0]['message']); - // Let's run a query with no limit offset $invalidQueryString = ' query { @@ -789,31 +780,27 @@ public function testEndToEndPorpaginas(): void $result = GraphQL::executeQuery( $schema, - $invalidQueryString + $invalidQueryString, ); $this->assertSame([ 'contactsIterator' => [ 'items' => [ - [ - 'name' => 'Joe', - ], + ['name' => 'Joe'], [ 'name' => 'Bill', - 'email' => 'bill@example.com' - ] + 'email' => 'bill@example.com', + ], ], - 'count' => 2 - ] + 'count' => 2, + ], ], $this->getSuccessResult($result)); } public function testEndToEndPorpaginasOnScalarType(): void { - /** - * @var Schema $schema - */ $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); $queryString = ' query { @@ -826,14 +813,14 @@ public function testEndToEndPorpaginasOnScalarType(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->assertSame([ 'contactsNamesIterator' => [ 'items' => ['Bill'], - 'count' => 2 - ] + 'count' => 2, + ], ], $this->getSuccessResult($result)); } @@ -842,10 +829,8 @@ public function testEndToEndPorpaginasOnScalarType(): void */ public function testEndToEnd2Iterators(): void { - /** - * @var Schema $schema - */ $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); $queryString = ' query { @@ -872,7 +857,7 @@ public function testEndToEnd2Iterators(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->assertSame([ @@ -881,31 +866,28 @@ public function testEndToEnd2Iterators(): void [ 'name' => 'Bill', 'uppercaseName' => 'BILL', - 'email' => 'bill@example.com' - ] + 'email' => 'bill@example.com', + ], ], - 'count' => 2 + 'count' => 2, ], 'products' => [ 'items' => [ [ 'name' => 'Foo', 'price' => 42.0, - 'unauthorized' => null - ] + 'unauthorized' => null, + ], ], - 'count' => 1 - ] + 'count' => 1, + ], ], $this->getSuccessResult($result)); - } public function testEndToEndStaticFactories(): void { - /** - * @var Schema $schema - */ $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); $queryString = ' query { @@ -915,30 +897,28 @@ public function testEndToEndStaticFactories(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->assertSame([ - 'echoFilters' => [ "foo", "bar", "12", "42", "62" ] + 'echoFilters' => [ 'foo', 'bar', '12', '42', '62' ], ], $this->getSuccessResult($result)); // Call again to test GlobTypeMapper cache $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->assertSame([ - 'echoFilters' => [ "foo", "bar", "12", "42", "62" ] + 'echoFilters' => [ 'foo', 'bar', '12', '42', '62' ], ], $this->getSuccessResult($result)); } public function testNonNullableTypesWithOptionnalFactoryArguments(): void { - /** - * @var Schema $schema - */ $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); $queryString = ' query { @@ -948,20 +928,18 @@ public function testNonNullableTypesWithOptionnalFactoryArguments(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->assertSame([ - 'echoFilters' => [] + 'echoFilters' => [], ], $this->getSuccessResult($result)); } public function testNullableTypesWithOptionnalFactoryArguments(): void { - /** - * @var Schema $schema - */ $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); $queryString = ' query { @@ -971,20 +949,16 @@ public function testNullableTypesWithOptionnalFactoryArguments(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); - $this->assertSame([ - 'echoNullableFilters' => null - ], $this->getSuccessResult($result)); + $this->assertSame(['echoNullableFilters' => null], $this->getSuccessResult($result)); } public function testEndToEndResolveInfo(): void { - /** - * @var Schema $schema - */ $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); $queryString = ' query { @@ -994,20 +968,16 @@ public function testEndToEndResolveInfo(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); - $this->assertSame([ - 'echoResolveInfo' => 'echoResolveInfo' - ], $this->getSuccessResult($result)); + $this->assertSame(['echoResolveInfo' => 'echoResolveInfo'], $this->getSuccessResult($result)); } public function testEndToEndRightIssues(): void { - /** - * @var Schema $schema - */ $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); $queryString = ' query { @@ -1021,7 +991,7 @@ public function testEndToEndRightIssues(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->assertSame('You need to be logged to access this field', $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS)['errors'][0]['message']); @@ -1037,7 +1007,7 @@ public function testEndToEndRightIssues(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->assertSame('You need to be logged to access this field', $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS)['errors'][0]['message']); @@ -1052,7 +1022,7 @@ public function testEndToEndRightIssues(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->assertSame('You do not have sufficient rights to access this field', $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS)['errors'][0]['message']); @@ -1067,7 +1037,7 @@ public function testEndToEndRightIssues(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->assertSame('You do not have sufficient rights to access this field', $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS)['errors'][0]['message']); @@ -1083,7 +1053,7 @@ public function testEndToEndRightIssues(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->assertSame('Cannot query field "hidden" on type "ContactInterface".', $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS)['errors'][0]['message']); @@ -1091,10 +1061,8 @@ public function testEndToEndRightIssues(): void public function testAutowireService(): void { - /** - * @var Schema $schema - */ $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); $queryString = ' query { @@ -1106,28 +1074,22 @@ public function testAutowireService(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->assertSame([ 'contacts' => [ - [ - 'injectService' => 'OK', - ], - [ - 'injectService' => 'OK', - ] + ['injectService' => 'OK'], + ['injectService' => 'OK'], - ] + ], ], $this->getSuccessResult($result)); } public function testParameterAnnotationsInSourceField(): void { - /** - * @var Schema $schema - */ $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); $queryString = ' query { @@ -1139,28 +1101,22 @@ public function testParameterAnnotationsInSourceField(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->assertSame([ 'contacts' => [ - [ - 'injectServiceFromExternal' => 'OK', - ], - [ - 'injectServiceFromExternal' => 'OK', - ] + ['injectServiceFromExternal' => 'OK'], + ['injectServiceFromExternal' => 'OK'], - ] + ], ], $this->getSuccessResult($result)); } public function testEndToEndEnums(): void { - /** - * @var Schema $schema - */ $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); $queryString = ' query { @@ -1170,20 +1126,16 @@ public function testEndToEndEnums(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); - $this->assertSame([ - 'echoProductType' => 'NON_FOOD' - ], $this->getSuccessResult($result)); + $this->assertSame(['echoProductType' => 'NON_FOOD'], $this->getSuccessResult($result)); } public function testEndToEndEnums2(): void { - /** - * @var Schema $schema - */ $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); $queryString = ' query { @@ -1193,20 +1145,16 @@ public function testEndToEndEnums2(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); - $this->assertSame([ - 'echoSomeProductType' => 'FOOD' - ], $this->getSuccessResult($result)); + $this->assertSame(['echoSomeProductType' => 'FOOD'], $this->getSuccessResult($result)); } public function testEndToEndEnums3(): void { - /** - * @var Schema $schema - */ $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); $queryString = ' query echo($productType: ProductTypes!) { @@ -1214,32 +1162,24 @@ public function testEndToEndEnums3(): void } '; - $variables = [ - 'productType' => 'NON_FOOD' - ]; + $variables = ['productType' => 'NON_FOOD']; $result = GraphQL::executeQuery( $schema, $queryString, null, null, - $variables + $variables, ); - $this->assertSame([ - 'echoProductType' => 'NON_FOOD' - ], $this->getSuccessResult($result)); + $this->assertSame(['echoProductType' => 'NON_FOOD'], $this->getSuccessResult($result)); } - /** - * @requires PHP >= 8.1 - */ + /** @requires PHP >= 8.1 */ public function testEndToEndNativeEnums(): void { - /** - * @var Schema $schema - */ $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); $gql = ' query { @@ -1253,7 +1193,7 @@ public function testEndToEndNativeEnums(): void $result = GraphQL::executeQuery( $schema, - $gql + $gql, ); $this->assertSame([ @@ -1261,16 +1201,58 @@ public function testEndToEndNativeEnums(): void 'color' => 'red', 'size' => 'M', 'state' => 'Off', - ] + ], + ], $this->getSuccessResult($result)); + + $gql = ' + mutation($color:Color!,$size:Size!,$state:Position!) { + updateButton(color: $color, size: $size, state: $state) { + color + size + state + } + } + '; + + $result = GraphQL::executeQuery( + $schema, + $gql, + variableValues: [ + 'color' => Color::Red->value, + 'size' => Size::M->name, + 'state' => Position::Off->name, + ], + ); + $this->assertSame([ + 'updateButton' => [ + 'color' => 'red', + 'size' => 'M', + 'state' => 'Off', + ], + ], $this->getSuccessResult($result)); + + $gql = ' + mutation($size:Size!) { + singleEnum(size: $size) + } + '; + + $result = GraphQL::executeQuery( + $schema, + $gql, + variableValues: [ + 'size' => Size::L->name, + ], + ); + $this->assertSame([ + 'singleEnum' => 'L', ], $this->getSuccessResult($result)); } public function testEndToEndDateTime(): void { - /** - * @var Schema $schema - */ $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); $queryString = ' query { @@ -1280,20 +1262,16 @@ public function testEndToEndDateTime(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); - $this->assertSame([ - 'echoDate' => '2019-05-05T01:02:03+00:00' - ], $this->getSuccessResult($result)); + $this->assertSame(['echoDate' => '2019-05-05T01:02:03+00:00'], $this->getSuccessResult($result)); } public function testEndToEndErrorHandlingOfInconstentTypesInArrays(): void { - /** - * @var Schema $schema - */ $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); $queryString = ' query { @@ -1305,7 +1283,7 @@ public function testEndToEndErrorHandlingOfInconstentTypesInArrays(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->expectException(TypeMismatchRuntimeException::class); @@ -1315,10 +1293,8 @@ public function testEndToEndErrorHandlingOfInconstentTypesInArrays(): void public function testEndToEndNonDefaultOutputType(): void { - /** - * @var Schema $schema - */ $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); $queryString = ' query { @@ -1332,24 +1308,22 @@ public function testEndToEndNonDefaultOutputType(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->assertSame([ 'otherContact' => [ 'name' => 'Joe', 'fullName' => 'JOE', - 'phone' => '0123456789' - ] + 'phone' => '0123456789', + ], ], $this->getSuccessResult($result)); } public function testEndToEndSecurityAnnotation(): void { - /** - * @var Schema $schema - */ $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); $queryString = ' query { @@ -1359,12 +1333,10 @@ public function testEndToEndSecurityAnnotation(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); - $this->assertSame([ - 'secretPhrase' => 'you can see this secret only if passed parameter is "foo"' - ], $this->getSuccessResult($result)); + $this->assertSame(['secretPhrase' => 'you can see this secret only if passed parameter is "foo"'], $this->getSuccessResult($result)); $queryString = ' query { @@ -1374,7 +1346,7 @@ public function testEndToEndSecurityAnnotation(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->expectException(MissingAuthorizationException::class); @@ -1384,10 +1356,8 @@ public function testEndToEndSecurityAnnotation(): void public function testEndToEndSecurityFailWithAnnotation(): void { - /** - * @var Schema $schema - */ $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); // Test with failWith attribute $queryString = ' @@ -1398,12 +1368,10 @@ public function testEndToEndSecurityFailWithAnnotation(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); - $this->assertSame([ - 'nullableSecretPhrase' => null - ], $this->getSuccessResult($result)); + $this->assertSame(['nullableSecretPhrase' => null], $this->getSuccessResult($result)); // Test with @FailWith annotation $queryString = ' @@ -1414,12 +1382,10 @@ public function testEndToEndSecurityFailWithAnnotation(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); - $this->assertSame([ - 'nullableSecretPhrase2' => null - ], $this->getSuccessResult($result)); + $this->assertSame(['nullableSecretPhrase2' => null], $this->getSuccessResult($result)); // Test with @FailWith annotation on property $queryString = ' @@ -1432,7 +1398,7 @@ public function testEndToEndSecurityFailWithAnnotation(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $data = $this->getSuccessResult($result); @@ -1441,10 +1407,8 @@ public function testEndToEndSecurityFailWithAnnotation(): void public function testEndToEndSecurityWithUser(): void { - /** - * @var Schema $schema - */ $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); // Test with failWith attribute $queryString = ' @@ -1455,7 +1419,7 @@ public function testEndToEndSecurityWithUser(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->assertSame('Access denied.', $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS)['errors'][0]['message']); @@ -1464,14 +1428,14 @@ public function testEndToEndSecurityWithUser(): void public function testEndToEndSecurityWithUserConnected(): void { $container = $this->createContainer([ - AuthenticationServiceInterface::class => static function() { + AuthenticationServiceInterface::class => static function () { return new class implements AuthenticationServiceInterface { public function isLogged(): bool { return true; } - public function getUser(): ?object + public function getUser(): object|null { $user = new stdClass(); $user->bar = 42; @@ -1479,25 +1443,19 @@ public function getUser(): ?object } }; }, - AuthorizationServiceInterface::class => static function() { + AuthorizationServiceInterface::class => static function () { return new class implements AuthorizationServiceInterface { public function isAllowed(string $right, $subject = null): bool { - if ($right === 'CAN_EDIT' && $subject->bar == 42) { - return true; - } - return false; + return $right === 'CAN_EDIT' && $subject->bar === 42; } }; }, - ]); - /** - * @var Schema $schema - */ $schema = $container->get(Schema::class); + assert($schema instanceof Schema); // Test with failWith attribute $queryString = ' @@ -1508,12 +1466,11 @@ public function isAllowed(string $right, $subject = null): bool $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->assertSame('you can see this secret only if user.bar is set to 42', $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS)['data']['secretUsingUser']); - // Test with failWith attribute $queryString = ' query { @@ -1523,7 +1480,7 @@ public function isAllowed(string $right, $subject = null): bool $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->assertSame('you can see this secret only if user has right "CAN_EDIT"', $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS)['data']['secretUsingIsGranted']); @@ -1531,10 +1488,8 @@ public function isAllowed(string $right, $subject = null): bool public function testEndToEndSecurityWithThis(): void { - /** - * @var Schema $schema - */ $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); $queryString = ' query { @@ -1544,7 +1499,7 @@ public function testEndToEndSecurityWithThis(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->assertSame('Access denied.', $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS)['errors'][0]['message']); @@ -1557,7 +1512,7 @@ public function testEndToEndSecurityWithThis(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->assertSame('you can see this secret only if isAllowed() returns true', $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS)['data']['secretUsingThis']); @@ -1565,10 +1520,8 @@ public function testEndToEndSecurityWithThis(): void public function testEndToEndSecurityInField(): void { - /** - * @var Schema $schema - */ $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); $queryString = ' query { @@ -1582,7 +1535,7 @@ public function testEndToEndSecurityInField(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->assertSame('Access denied.', $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS)['errors'][0]['message']); @@ -1597,17 +1550,16 @@ public function testEndToEndSecurityInField(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->assertSame('Access denied.', $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS)['errors'][0]['message']); } - public function testEndToEndUnions(){ - /** - * @var Schema $schema - */ + public function testEndToEndUnions(): void + { $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); $queryString = ' query { @@ -1623,7 +1575,7 @@ public function testEndToEndUnions(){ $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $resultArray = $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS); @@ -1632,11 +1584,10 @@ public function testEndToEndUnions(){ $this->assertEquals('unicorn', $resultArray['data']['getProduct']['special']); } - public function testEndToEndUnionsInIterables(){ - /** - * @var Schema $schema - */ + public function testEndToEndUnionsInIterables(): void + { $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); $queryString = ' query { @@ -1652,7 +1603,7 @@ public function testEndToEndUnionsInIterables(){ $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $resultArray = $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS); @@ -1663,10 +1614,8 @@ public function testEndToEndUnionsInIterables(){ public function testEndToEndMagicFieldWithPhpType(): void { - /** - * @var Schema $schema - */ $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); $queryString = ' query { @@ -1680,49 +1629,43 @@ public function testEndToEndMagicFieldWithPhpType(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->assertSame([ 'contacts' => [ [ - 'magicContact' => [ - 'name' => 'foo' - ] + 'magicContact' => ['name' => 'foo'], ], [ - 'magicContact' => [ - 'name' => 'foo' - ] + 'magicContact' => ['name' => 'foo'], ], - ] + ], ], $this->getSuccessResult($result)); } public function testEndToEndInjectUser(): void { $container = $this->createContainer([ - AuthenticationServiceInterface::class => static function() { + AuthenticationServiceInterface::class => static function () { return new class implements AuthenticationServiceInterface { public function isLogged(): bool { return true; } - public function getUser(): ?object + public function getUser(): object|null { $user = new stdClass(); $user->bar = 42; return $user; } }; - } + }, ]); - /** - * @var Schema $schema - */ $schema = $container->get(Schema::class); + assert($schema instanceof Schema); // Test with failWith attribute $queryString = ' @@ -1733,7 +1676,7 @@ public function getUser(): ?object $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->assertSame(42, $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS)['data']['injectedUser']); @@ -1755,11 +1698,10 @@ public function testInputOutputNameConflict(): void $schema->validate(); } - public function testNullableResult(){ - /** - * @var Schema $schema - */ + public function testNullableResult(): void + { $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); $queryString = ' query { @@ -1771,21 +1713,19 @@ public function testNullableResult(){ $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $resultArray = $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS); - if (isset($resultArray['errors']) || !isset($resultArray['data'])) { - $this->fail('Expected a successful answer. Got '.json_encode($resultArray, JSON_PRETTY_PRINT)); + if (isset($resultArray['errors']) || ! isset($resultArray['data'])) { + $this->fail('Expected a successful answer. Got ' . json_encode($resultArray, JSON_PRETTY_PRINT)); } $this->assertNull($resultArray['data']['nullableResult']); } public function testEndToEndFieldAnnotationInProperty(): void { - /** - * @var Schema $schema - */ $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); $queryString = ' query { @@ -1800,7 +1740,7 @@ public function testEndToEndFieldAnnotationInProperty(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $data = $this->getSuccessResult($result); @@ -1820,7 +1760,7 @@ public function testEndToEndFieldAnnotationInProperty(): void GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->expectException(AccessPropertyException::class); @@ -1836,7 +1776,7 @@ public function testEndToEndFieldAnnotationInProperty(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->expectException(AccessPropertyException::class); @@ -1846,10 +1786,8 @@ public function testEndToEndFieldAnnotationInProperty(): void public function testEndToEndInputAnnotations(): void { - /** - * @var Schema $schema - */ $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); $queryString = ' mutation { createPost( @@ -1917,7 +1855,7 @@ public function testEndToEndInputAnnotations(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->assertSame([ @@ -1927,9 +1865,7 @@ public function testEndToEndInputAnnotations(): void 'publishedAt' => '2021-01-24T00:00:00+00:00', 'comment' => 'foo', 'summary' => 'foo', - 'author' => [ - 'name' => 'foo', - ], + 'author' => ['name' => 'foo'], ], 'updatePost' => [ 'id' => 100, @@ -1943,19 +1879,15 @@ public function testEndToEndInputAnnotations(): void 'comment' => 'some description', 'summary' => 'foo', 'magazine' => 'bar', - 'author' => [ - 'name' => 'foo', - ], + 'author' => ['name' => 'foo'], ], ], $this->getSuccessResult($result)); } public function testEndToEndInputAnnotationIssues(): void { - /** - * @var Schema $schema - */ $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); $queryString = ' mutation { createPost( @@ -1970,7 +1902,7 @@ public function testEndToEndInputAnnotationIssues(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->assertSame('Field PostInput.title of required type String! was not provided.', $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS)['errors'][0]['message']); @@ -1993,7 +1925,7 @@ public function testEndToEndInputAnnotationIssues(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->assertSame('Field ArticleInput.title of required type String! was not provided.', $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS)['errors'][0]['message']); @@ -2016,7 +1948,7 @@ public function testEndToEndInputAnnotationIssues(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->expectException(AccessPropertyException::class); @@ -2026,10 +1958,8 @@ public function testEndToEndInputAnnotationIssues(): void public function testEndToEndInputEmptyValues(): void { - /** - * @var Schema $schema - */ $schema = $this->mainContainer->get(Schema::class); + assert($schema instanceof Schema); $queryString = ' mutation { @@ -2051,7 +1981,7 @@ public function testEndToEndInputEmptyValues(): void $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->assertSame([ @@ -2069,11 +1999,11 @@ public function testEndToEndInputTypeValidation(): void $validator = new Validator(); $container = $this->createContainer([ - InputTypeGenerator::class => function (ContainerInterface $container) use ($validator) { + InputTypeGenerator::class => static function (ContainerInterface $container) use ($validator) { return new InputTypeGenerator( $container->get(InputTypeUtils::class), $container->get(FieldsBuilder::class), - $validator + $validator, ); }, ]); @@ -2108,17 +2038,17 @@ public function testEndToEndInputTypeValidation(): void $result->toArray(DebugFlag::RETHROW_INTERNAL_EXCEPTIONS); } - - public function testEndToEndSetterWithSecurity() { + public function testEndToEndSetterWithSecurity(): void + { $container = $this->createContainer([ - AuthenticationServiceInterface::class => static function() { + AuthenticationServiceInterface::class => static function () { return new class implements AuthenticationServiceInterface { public function isLogged(): bool { return true; } - public function getUser(): ?object + public function getUser(): object|null { $user = new stdClass(); $user->bar = 42; @@ -2126,24 +2056,19 @@ public function getUser(): ?object } }; }, - AuthorizationServiceInterface::class => static function() { + AuthorizationServiceInterface::class => static function () { return new class implements AuthorizationServiceInterface { public function isAllowed(string $right, $subject = null): bool { - if ($right === 'CAN_SET_SECRET' || $right === "CAN_SEE_SECRET") { - return true; - } - return false; + return $right === 'CAN_SET_SECRET' || $right === 'CAN_SEE_SECRET'; } }; }, ]); - /** - * @var Schema $schema - */ $schema = $container->get(Schema::class); + assert($schema instanceof Schema); $queryString = ' query { @@ -2155,12 +2080,11 @@ public function isAllowed(string $right, $subject = null): bool $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $data = $this->getSuccessResult($result); $this->assertSame('preset{secret}', $data['trickyProduct']['conditionalSecret']); -// $queryString = ' mutation { updateTrickyProduct( @@ -2182,7 +2106,7 @@ public function isAllowed(string $right, $subject = null): bool $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $data = $this->getSuccessResult($result); @@ -2204,13 +2128,13 @@ public function isAllowed(string $right, $subject = null): bool $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $data = $this->getSuccessResult($result); $this->assertSame('Special box', $data['trickyProduct']['name']); $this->assertSame(11.99, $data['trickyProduct']['price']); - $this->assertSame("hello", $data['trickyProduct']['secret']); + $this->assertSame('hello', $data['trickyProduct']['secret']); $this->assertSame(11.11, $data['trickyProduct']['multi']); $queryString = ' @@ -2231,7 +2155,7 @@ public function isAllowed(string $right, $subject = null): bool $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $data = $this->getSuccessResult($result); @@ -2239,16 +2163,17 @@ public function isAllowed(string $right, $subject = null): bool $this->assertSame(11.99, $data['createTrickyProduct']['price']); } - public function testEndToEndSetterWithSecurityError() { + public function testEndToEndSetterWithSecurityError(): void + { $container = $this->createContainer([ - AuthenticationServiceInterface::class => static function() { + AuthenticationServiceInterface::class => static function () { return new class implements AuthenticationServiceInterface { public function isLogged(): bool { return true; } - public function getUser(): ?object + public function getUser(): object|null { $user = new stdClass(); $user->bar = 42; @@ -2256,23 +2181,18 @@ public function getUser(): ?object } }; }, - AuthorizationServiceInterface::class => static function() { + AuthorizationServiceInterface::class => static function () { return new class implements AuthorizationServiceInterface { public function isAllowed(string $right, $subject = null): bool { - if ($right === 'CAN_SET_SECRET' || $right === "CAN_SEE_SECRET") { - return true; - } - return false; + return $right === 'CAN_SET_SECRET' || $right === 'CAN_SEE_SECRET'; } }; }, ]); - /** - * @var Schema $schema - */ $schema = $container->get(Schema::class); + assert($schema instanceof Schema); // try getConditionalSecret with wrong key $queryString = ' @@ -2285,7 +2205,7 @@ public function isAllowed(string $right, $subject = null): bool $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->assertSame('Access denied.', $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS)['errors'][0]['message']); @@ -2311,20 +2231,20 @@ public function isAllowed(string $right, $subject = null): bool $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->assertSame('Access denied.', $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS)['errors'][0]['message']); $container = $this->createContainer([ - AuthenticationServiceInterface::class => static function() { + AuthenticationServiceInterface::class => static function () { return new class implements AuthenticationServiceInterface { public function isLogged(): bool { return true; } - public function getUser(): ?object + public function getUser(): object|null { $user = new stdClass(); $user->bar = 42; @@ -2332,7 +2252,7 @@ public function getUser(): ?object } }; }, - AuthorizationServiceInterface::class => static function() { + AuthorizationServiceInterface::class => static function () { return new class implements AuthorizationServiceInterface { public function isAllowed(string $right, $subject = null): bool { @@ -2342,10 +2262,8 @@ public function isAllowed(string $right, $subject = null): bool }, ]); - /** - * @var Schema $schema - */ $schema = $container->get(Schema::class); + assert($schema instanceof Schema); // try getSecret with sufficient rights $queryString = ' @@ -2360,7 +2278,7 @@ public function isAllowed(string $right, $subject = null): bool $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->assertSame('You do not have sufficient rights to access this field', $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS)['errors'][0]['message']); @@ -2386,18 +2304,18 @@ public function isAllowed(string $right, $subject = null): bool $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->assertSame('You do not have sufficient rights to access this field', $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS)['errors'][0]['message']); $container = $this->createContainer([ - AuthenticationServiceInterface::class => static function() { + AuthenticationServiceInterface::class => static function () { return new class implements AuthenticationServiceInterface { public function isLogged(): bool { return true; } - public function getUser(): ?object + public function getUser(): object|null { $user = new stdClass(); $user->bar = 43; @@ -2405,14 +2323,11 @@ public function getUser(): ?object } }; }, - AuthorizationServiceInterface::class => static function() { + AuthorizationServiceInterface::class => static function () { return new class implements AuthorizationServiceInterface { public function isAllowed(string $right, $subject = null): bool { - if ($right === 'CAN_SET_SECRET' || $right === "CAN_SEE_SECRET") { - return true; - } - return false; + return $right === 'CAN_SET_SECRET' || $right === 'CAN_SEE_SECRET'; } }; }, @@ -2422,7 +2337,7 @@ public function isAllowed(string $right, $subject = null): bool // set conditionalSecret with wrong user $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $this->assertSame('Access denied.', $result->toArray(DebugFlag::RETHROW_UNSAFE_EXCEPTIONS)['errors'][0]['message']); } @@ -2444,14 +2359,14 @@ public function testCircularInput(): void public function testArrayInput(): void { $container = $this->createContainer([ - AuthenticationServiceInterface::class => static function() { + AuthenticationServiceInterface::class => static function () { return new class implements AuthenticationServiceInterface { public function isLogged(): bool { return true; } - public function getUser(): ?object + public function getUser(): object|null { $user = new stdClass(); $user->bar = 42; @@ -2459,14 +2374,11 @@ public function getUser(): ?object } }; }, - AuthorizationServiceInterface::class => static function() { + AuthorizationServiceInterface::class => static function () { return new class implements AuthorizationServiceInterface { public function isAllowed(string $right, $subject = null): bool { - if ($right === 'CAN_SET_SECRET' || $right === "CAN_SEE_SECRET") { - return true; - } - return false; + return $right === 'CAN_SET_SECRET' || $right === 'CAN_SEE_SECRET'; } }; }, @@ -2494,10 +2406,10 @@ public function isAllowed(string $right, $subject = null): bool $result = GraphQL::executeQuery( $schema, - $queryString + $queryString, ); $data = $this->getSuccessResult($result); - $this->assertSame(["graph", "ql"], $data['updateTrickyProduct']['list']); + $this->assertSame(['graph', 'ql'], $data['updateTrickyProduct']['list']); } }