From 38a70a95e05c2c6d496306ae0f4554ec844f994e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Szigeti?= Date: Mon, 21 Jun 2021 12:43:58 +0200 Subject: [PATCH 01/26] Fix composer cache path --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 35c938b..f736602 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -36,7 +36,7 @@ jobs: - name: composer-cache uses: actions/cache@v2.1.6 with: - path: ${{ needs.prepare.outputs.composercachedir }} + path: ${{ steps.composercache.outputs.dir }} key: composer-${{ hashFiles('**/composer.json') }}-${{ matrix.install-args }} restore-keys: | composer-${{ hashFiles('**/composer.json') }}-${{ matrix.install-args }} From 431b03ea46aec24512351322c98590c1464b4d7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Szigeti?= Date: Mon, 21 Jun 2021 14:07:38 +0200 Subject: [PATCH 02/26] drop check-platform-reqs --- .github/workflows/test.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index f736602..4da63a1 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -45,7 +45,6 @@ jobs: - name: composer run: | - composer check-platform-reqs --no-interaction composer update ${{ matrix.install-args }} --no-interaction --no-progress --prefer-dist - name: phpunit From 206e2d16aa78232f83d703c02f479ff6b00c357a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Szigeti?= Date: Mon, 21 Jun 2021 14:19:14 +0200 Subject: [PATCH 03/26] Add BC package-versions --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3e0f96e..6de6d2b 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,8 @@ "beberlei/porpaginas": "^1.2", "php-coveralls/php-coveralls": "^2.1.0", "symfony/phpunit-bridge": "^4.1.9 | ^5.1", - "thecodingmachine/phpstan-strict-rules": "^0.12.1" + "thecodingmachine/phpstan-strict-rules": "^0.12.1", + "composer/package-versions-deprecated": "^1.8" }, "scripts": { "phpstan": "phpstan analyse GraphqliteBundle.php DependencyInjection/ Controller/ Resources/ Security/ -c phpstan.neon --level=7 --no-progress" From 10f78cceced6e157741b325a3887c7fc4df72434 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Szigeti?= Date: Mon, 21 Jun 2021 14:43:38 +0200 Subject: [PATCH 04/26] Drop redundant phpunit, suppress deprecations --- .github/workflows/test.yaml | 2 +- Tests/FunctionalTest.php | 3 +++ composer.json | 3 +-- phpstan.neon | 5 ++++- phpunit.xml.dist | 4 ++++ 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 4da63a1..ead2230 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -49,7 +49,7 @@ jobs: - name: phpunit run: | - vendor/bin/phpunit + vendor/bin/simple-phpunit - name: phpstan-cache uses: actions/cache@v2.1.6 diff --git a/Tests/FunctionalTest.php b/Tests/FunctionalTest.php index 2075b74..586795f 100644 --- a/Tests/FunctionalTest.php +++ b/Tests/FunctionalTest.php @@ -534,6 +534,9 @@ private function logIn(ContainerInterface $container) $container->get('security.token_storage')->setToken($token); } + /** + * @requires PHP 8.0 + */ public function testPhp8Attributes(): void { $kernel = new GraphqliteTestingKernel(); diff --git a/composer.json b/composer.json index 6de6d2b..8750d55 100644 --- a/composer.json +++ b/composer.json @@ -33,8 +33,7 @@ "require-dev": { "symfony/security-bundle": "^4.1.9 | ^5", "symfony/yaml": "^4.1.9 | ^5", - "phpunit/phpunit": "^8.5.5", - "phpstan/phpstan": "^0.12.25", + "phpstan/phpstan": "^0.12.90", "beberlei/porpaginas": "^1.2", "php-coveralls/php-coveralls": "^2.1.0", "symfony/phpunit-bridge": "^4.1.9 | ^5.1", diff --git a/phpstan.neon b/phpstan.neon index 65342ca..8b77c13 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -10,6 +10,8 @@ parameters: - vendor - cache - .phpstan-cache + bootstrapFiles: + - vendor/bin/.phpunit/phpunit/vendor/autoload.php level: max polluteScopeWithLoopInitialAssignments: false polluteScopeWithAlwaysIterableForeach: false @@ -23,4 +25,5 @@ parameters: checkTooWideReturnTypesInProtectedAndPublicMethods: true treatPhpDocTypesAsCertain: false ignoreErrors: - - "#Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeDefinition::children\\(\\)#" + # Symfony's TreeBuilder has problem - some method(s) in the chain have a wrong return typehint: + - '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition::\w+\(\).#' diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 0548e50..7d58105 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -10,6 +10,10 @@ stopOnFailure="false" bootstrap="vendor/autoload.php" > + + + + ./Tests/ From 3389b64989d7e9b4542c7dfc0ce80e709f63fc3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Szigeti?= Date: Mon, 21 Jun 2021 14:45:39 +0200 Subject: [PATCH 05/26] fixes upon fixes --- .github/workflows/test.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index ead2230..b7a42e8 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -65,5 +65,4 @@ jobs: - name: phpstan run: | mkdir -p .phpstan-cache - APP_ENV=dev bin/console cache:clear vendor/bin/phpstan analyse --no-progress --no-interaction --memory-limit=1G From fc6a074ac8f2b1459e3f9e6ac535ee8ba72d2a58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Szigeti?= Date: Mon, 21 Jun 2021 14:59:56 +0200 Subject: [PATCH 06/26] Address missing config --- Tests/GraphqliteTestingKernel.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Tests/GraphqliteTestingKernel.php b/Tests/GraphqliteTestingKernel.php index 0b3111e..4b214db 100644 --- a/Tests/GraphqliteTestingKernel.php +++ b/Tests/GraphqliteTestingKernel.php @@ -108,9 +108,12 @@ public function configureContainer(ContainerBuilder $c, LoaderInterface $loader) 'app' => 'cache.adapter.array', ]; - $frameworkConf['router'] =[ - 'utf8' => true, - ]; + // @phpstan-ignore-next-line + if (self::VERSION_ID >= 42000) { + $frameworkConf['router'] =[ + 'utf8' => true, + ]; + } if ($this->enableSession) { $frameworkConf['session'] =[ From 6841e82c4dd2b5cbd822542df16beb35223a70d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Szigeti?= Date: Mon, 21 Jun 2021 15:33:46 +0200 Subject: [PATCH 07/26] one more round --- .github/workflows/test.yaml | 2 +- Tests/GraphqliteTestingKernel.php | 9 +++------ Tests/NoSecurityBundleTest.php | 1 + Types/SymfonyUserInterfaceType.php | 5 +++-- composer.json | 17 +++++++++------- phpstan.baseline.neon | 32 ++++++++++++++++++++++++++---- phpstan.neon | 1 + 7 files changed, 47 insertions(+), 20 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index b7a42e8..2b8692a 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -49,7 +49,7 @@ jobs: - name: phpunit run: | - vendor/bin/simple-phpunit + vendor/bin/simple-phpunit --no-coverage - name: phpstan-cache uses: actions/cache@v2.1.6 diff --git a/Tests/GraphqliteTestingKernel.php b/Tests/GraphqliteTestingKernel.php index 4b214db..0b3111e 100644 --- a/Tests/GraphqliteTestingKernel.php +++ b/Tests/GraphqliteTestingKernel.php @@ -108,12 +108,9 @@ public function configureContainer(ContainerBuilder $c, LoaderInterface $loader) 'app' => 'cache.adapter.array', ]; - // @phpstan-ignore-next-line - if (self::VERSION_ID >= 42000) { - $frameworkConf['router'] =[ - 'utf8' => true, - ]; - } + $frameworkConf['router'] =[ + 'utf8' => true, + ]; if ($this->enableSession) { $frameworkConf['session'] =[ diff --git a/Tests/NoSecurityBundleTest.php b/Tests/NoSecurityBundleTest.php index a71f617..5cf5290 100644 --- a/Tests/NoSecurityBundleTest.php +++ b/Tests/NoSecurityBundleTest.php @@ -29,6 +29,7 @@ public function testServiceWiring(): void $kernel = new GraphqliteTestingKernel(true, null, false, null, true, null, null, ['TheCodingMachine\\Graphqlite\\Bundle\\Tests\\NoSecurityBundleFixtures\\Controller\\']); $kernel->boot(); $container = $kernel->getContainer(); + self::assertNotNull($container); $schema = $container->get(Schema::class); $this->assertInstanceOf(Schema::class, $schema); diff --git a/Types/SymfonyUserInterfaceType.php b/Types/SymfonyUserInterfaceType.php index 3dc99d5..bbc1f5a 100644 --- a/Types/SymfonyUserInterfaceType.php +++ b/Types/SymfonyUserInterfaceType.php @@ -3,6 +3,7 @@ namespace TheCodingMachine\Graphqlite\Bundle\Types; +use Symfony\Component\Security\Core\Role\Role; use TheCodingMachine\GraphQLite\Annotations\Field; use TheCodingMachine\GraphQLite\Annotations\SourceField; use TheCodingMachine\GraphQLite\Annotations\Type; @@ -22,8 +23,8 @@ public function getRoles(UserInterface $user): array { $roles = []; foreach ($user->getRoles() as $role) { - $roles[] = (string) $role; + $roles[] = $role instanceof Role ? $role->getRole() : $role; } return $roles; } -} \ No newline at end of file +} diff --git a/composer.json b/composer.json index 8750d55..90a1884 100644 --- a/composer.json +++ b/composer.json @@ -19,9 +19,9 @@ "php" : ">=7.2", "thecodingmachine/graphqlite" : "^4.1", "thecodingmachine/graphqlite-symfony-validator-bridge" : "^4.1", - "symfony/framework-bundle": "^4.1.9 | ^5", - "symfony/validator": "^4.1.9 | ^5", - "symfony/translation": "^4.1.9 | ^5", + "symfony/framework-bundle": "^4.2 || ^5", + "symfony/validator": "^4.2 || ^5", + "symfony/translation": "^4.2 || ^5", "doctrine/annotations": "^1.6", "doctrine/cache": "^1.8", "symfony/psr-http-message-bridge": "^2.0", @@ -31,15 +31,18 @@ "thecodingmachine/cache-utils": "^1" }, "require-dev": { - "symfony/security-bundle": "^4.1.9 | ^5", - "symfony/yaml": "^4.1.9 | ^5", + "symfony/security-bundle": "^4.2 || ^5", + "symfony/yaml": "^4.2 || ^5", "phpstan/phpstan": "^0.12.90", "beberlei/porpaginas": "^1.2", "php-coveralls/php-coveralls": "^2.1.0", - "symfony/phpunit-bridge": "^4.1.9 | ^5.1", - "thecodingmachine/phpstan-strict-rules": "^0.12.1", + "symfony/phpunit-bridge": "^5.3", + "thecodingmachine/phpstan-strict-rules": "^v0.12.1", "composer/package-versions-deprecated": "^1.8" }, + "conflict": { + "symfony/event-dispatcher": "<4.3" + }, "scripts": { "phpstan": "phpstan analyse GraphqliteBundle.php DependencyInjection/ Controller/ Resources/ Security/ -c phpstan.neon --level=7 --no-progress" }, diff --git a/phpstan.baseline.neon b/phpstan.baseline.neon index 21658cb..f685b67 100644 --- a/phpstan.baseline.neon +++ b/phpstan.baseline.neon @@ -1,5 +1,10 @@ parameters: ignoreErrors: + - + message: "#^Method Symfony\\\\Contracts\\\\EventDispatcher\\\\EventDispatcherInterface\\:\\:dispatch\\(\\) invoked with 2 parameters, 1 required\\.$#" + count: 1 + path: Controller/GraphQL/LoginController.php + - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" count: 1 @@ -101,20 +106,35 @@ parameters: path: Tests/Fixtures/Entities/Contact.php - - message: "#^Cannot call method assertValid\\(\\) on object\\|null\\.$#" + message: "#^Call to an undefined method object\\:\\:assertValid\\(\\)\\.$#" count: 2 path: Tests/FunctionalTest.php - - message: "#^Cannot call method handleRequest\\(\\) on object\\|null\\.$#" + message: "#^Call to an undefined method object\\:\\:handleRequest\\(\\)\\.$#" count: 1 path: Tests/FunctionalTest.php + - + message: "#^Cannot call method get\\(\\) on Symfony\\\\Component\\\\DependencyInjection\\\\ContainerInterface\\|null\\.$#" + count: 3 + path: Tests/FunctionalTest.php + + - + message: "#^Cannot call method set\\(\\) on Symfony\\\\Component\\\\DependencyInjection\\\\ContainerInterface\\|null\\.$#" + count: 4 + path: Tests/FunctionalTest.php + - message: "#^Method TheCodingMachine\\\\Graphqlite\\\\Bundle\\\\Tests\\\\FunctionalTest\\:\\:logIn\\(\\) has no return typehint specified\\.$#" count: 1 path: Tests/FunctionalTest.php + - + message: "#^Parameter \\#1 \\$container of method TheCodingMachine\\\\Graphqlite\\\\Bundle\\\\Tests\\\\FunctionalTest\\:\\:logIn\\(\\) expects Psr\\\\Container\\\\ContainerInterface, Symfony\\\\Component\\\\DependencyInjection\\\\ContainerInterface\\|null given\\.$#" + count: 1 + path: Tests/FunctionalTest.php + - message: "#^Parameter \\#1 \\$json of function json_decode expects string, string\\|false given\\.$#" count: 15 @@ -151,12 +171,16 @@ parameters: path: Tests/GraphqliteTestingKernel.php - - message: "#^Cannot call method assertValid\\(\\) on object\\|null\\.$#" + message: "#^Call to an undefined method object\\:\\:assertValid\\(\\)\\.$#" count: 1 path: Tests/NoSecurityBundleTest.php - - message: "#^Parameter \\#1 \\$json of function json_decode expects string, string\\|false given\\.$#" + message: "#^Cannot call method get\\(\\) on Symfony\\\\Component\\\\DependencyInjection\\\\ContainerInterface\\|null\\.$#" count: 1 path: Tests/NoSecurityBundleTest.php + - + message: "#^Parameter \\#1 \\$json of function json_decode expects string, string\\|false given\\.$#" + count: 1 + path: Tests/NoSecurityBundleTest.php diff --git a/phpstan.neon b/phpstan.neon index 8b77c13..fd86821 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -24,6 +24,7 @@ parameters: checkMissingClosureNativeReturnTypehintRule: true checkTooWideReturnTypesInProtectedAndPublicMethods: true treatPhpDocTypesAsCertain: false + reportUnmatchedIgnoredErrors: false ignoreErrors: # Symfony's TreeBuilder has problem - some method(s) in the chain have a wrong return typehint: - '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition::\w+\(\).#' From 820f788811d6c858083c76a74ea31e41eb37f92d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Szigeti?= Date: Mon, 21 Jun 2021 19:44:36 +0200 Subject: [PATCH 08/26] Fix lowest deps --- composer.json | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 90a1884..79b5fde 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ ], "require" : { "php" : ">=7.2", - "thecodingmachine/graphqlite" : "^4.1", + "thecodingmachine/graphqlite" : "^4.1.2", "thecodingmachine/graphqlite-symfony-validator-bridge" : "^4.1", "symfony/framework-bundle": "^4.2 || ^5", "symfony/validator": "^4.2 || ^5", @@ -41,7 +41,10 @@ "composer/package-versions-deprecated": "^1.8" }, "conflict": { - "symfony/event-dispatcher": "<4.3" + "mouf/classname-mapper": "<1.0.2", + "symfony/event-dispatcher": "<4.3", + "symfony/security-core": "<4.3", + "symfony/routing": "<4.3" }, "scripts": { "phpstan": "phpstan analyse GraphqliteBundle.php DependencyInjection/ Controller/ Resources/ Security/ -c phpstan.neon --level=7 --no-progress" From acf874d10cf902058cf6f9c4359d03f5b2f9341a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Szigeti?= Date: Mon, 21 Jun 2021 19:49:34 +0200 Subject: [PATCH 09/26] phpunit config --- phpunit.xml.dist | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 7d58105..bfa1f6f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,22 +1,21 @@ - - + + + + - - ./Tests/ + + Tests @@ -32,20 +31,13 @@ ./var - + - - - - - - 0 - - - + + From 75fd20cc506a8aab334846cb78b13ed79e97f915 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Szigeti?= Date: Mon, 21 Jun 2021 19:53:19 +0200 Subject: [PATCH 10/26] do not fail on deprecations --- phpunit.xml.dist | 1 + 1 file changed, 1 insertion(+) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index bfa1f6f..4610fed 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -11,6 +11,7 @@ + From 9226d1b91c18e31c84618c609c3f3cd434acf3c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Szigeti?= Date: Mon, 21 Jun 2021 20:02:48 +0200 Subject: [PATCH 11/26] do not fail on deprecations --- phpunit.xml.dist | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 4610fed..3808ac3 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -3,6 +3,7 @@ @@ -20,25 +21,7 @@ - - - ./ - - cache - build - ./Resources - ./Tests - ./vendor - ./var - - - - - - - - From 04348e0b9818584f4e49648311983234ee287eb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Szigeti?= Date: Mon, 21 Jun 2021 20:06:38 +0200 Subject: [PATCH 12/26] Do not fail fast in github matrix --- .github/workflows/test.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 2b8692a..2133c9d 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -13,6 +13,7 @@ jobs: matrix: install-args: ['', '--prefer-lowest'] php-version: ['7.2', '7.3', '7.4', '8.0'] + fail-fast: false steps: # Cancel previous runs of the same branch - name: cancel From f9e0cab3090d91039b2bb9c2b73fb4e4bb576d51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Szigeti?= Date: Mon, 21 Jun 2021 20:08:45 +0200 Subject: [PATCH 13/26] downgrade phpunit --- phpunit.xml.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 3808ac3..9a9e0b2 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -11,7 +11,7 @@ - + From 874835affd7aad396cbc23e83c2da04afc017b83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Szigeti?= Date: Tue, 22 Jun 2021 07:01:36 +0200 Subject: [PATCH 14/26] Stan fixes --- Controller/GraphQL/LoginController.php | 1 + Controller/GraphqliteController.php | 10 +- .../GraphqliteCompilerPass.php | 5 +- DependencyInjection/GraphqliteExtension.php | 28 ++- .../OverblogGraphiQLEndpointWiringPass.php | 2 - GraphiQL/EndpointResolver.php | 6 + Mappers/RequestParameterMiddleware.php | 5 +- Server/ServerConfig.php | 13 +- composer.json | 3 +- phpstan.baseline.neon | 186 ------------------ phpstan.neon | 3 +- 11 files changed, 45 insertions(+), 217 deletions(-) delete mode 100644 phpstan.baseline.neon diff --git a/Controller/GraphQL/LoginController.php b/Controller/GraphQL/LoginController.php index 2188e51..b2d8eb7 100644 --- a/Controller/GraphQL/LoginController.php +++ b/Controller/GraphQL/LoginController.php @@ -82,6 +82,7 @@ public function login(string $userName, string $password, Request $request): Use // Fire the login event manually $event = new InteractiveLoginEvent($request, $token); + // @phpstan-ignore-next-line BC for Symfony4 $this->eventDispatcher->dispatch($event, 'security.interactive_login'); return $user; diff --git a/Controller/GraphqliteController.php b/Controller/GraphqliteController.php index 61ea3fe..3efde0f 100644 --- a/Controller/GraphqliteController.php +++ b/Controller/GraphqliteController.php @@ -106,18 +106,16 @@ private function handlePsr7Request(ServerRequestInterface $request, Request $sym return new JsonResponse($result->toArray($this->debug), $httpCodeDecider->decideHttpStatusCode($result)); } if (is_array($result)) { - $finalResult = array_map(function (ExecutionResult $executionResult) { + $finalResult = array_map(function (ExecutionResult $executionResult): array { return $executionResult->toArray($this->debug); }, $result); // Let's return the highest result. $statuses = array_map([$httpCodeDecider, 'decideHttpStatusCode'], $result); $status = empty($statuses) ? 500 : max($statuses); + return new JsonResponse($finalResult, $status); } - if ($result instanceof Promise) { - throw new RuntimeException('Only SyncPromiseAdapter is supported'); - } - /* @phpstan-ignore-next-line */ - throw new RuntimeException('Unexpected response from StandardServer::executePsrRequest'); // @codeCoverageIgnore + + throw new RuntimeException('Only SyncPromiseAdapter is supported'); } } diff --git a/DependencyInjection/GraphqliteCompilerPass.php b/DependencyInjection/GraphqliteCompilerPass.php index e661e5e..93fcc01 100644 --- a/DependencyInjection/GraphqliteCompilerPass.php +++ b/DependencyInjection/GraphqliteCompilerPass.php @@ -333,7 +333,7 @@ private function mapAdderToTag(string $tag, string $methodName, ContainerBuilder */ private function makePublicInjectedServices(ReflectionClass $refClass, AnnotationReader $reader, ContainerBuilder $container, bool $isController): void { - $services = $this->getCodeCache()->get($refClass, function() use ($refClass, $reader, $container, $isController) { + $services = $this->getCodeCache()->get($refClass, function() use ($refClass, $reader, $container, $isController): array { $services = []; foreach ($refClass->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { $field = $reader->getRequestAnnotation($method, Field::class) ?? $reader->getRequestAnnotation($method, Query::class) ?? $reader->getRequestAnnotation($method, Mutation::class); @@ -347,6 +347,7 @@ private function makePublicInjectedServices(ReflectionClass $refClass, Annotatio } } } + return $services; }); @@ -485,7 +486,7 @@ private function getClassList(string $namespace, int $globTtl = 2, bool $recursi // The autoloader might trigger errors if the file does not respect PSR-4 or if the // Symfony DebugAutoLoader is installed. (see https://github.com/thecodingmachine/graphqlite/issues/216) require_once $phpFile; - // Does it exists now? + // @phpstan-ignore-next-line Does it exists now? if (! class_exists($className, false)) { continue; } diff --git a/DependencyInjection/GraphqliteExtension.php b/DependencyInjection/GraphqliteExtension.php index 403a70c..2943c2c 100644 --- a/DependencyInjection/GraphqliteExtension.php +++ b/DependencyInjection/GraphqliteExtension.php @@ -42,7 +42,12 @@ public function load(array $configs, ContainerBuilder $container): void if (!is_array($controllers)) { $controllers = [ $controllers ]; } - $namespaceController = array_map(function($namespace) { return rtrim($namespace, '\\') . '\\'; }, $controllers); + $namespaceController = array_map( + function($namespace): string { + return rtrim($namespace, '\\') . '\\'; + }, + $controllers + ); } else { $namespaceController = []; } @@ -51,7 +56,12 @@ public function load(array $configs, ContainerBuilder $container): void if (!is_array($types)) { $types = [ $types ]; } - $namespaceType = array_map(function($namespace) { return rtrim($namespace, '\\') . '\\'; }, $types); + $namespaceType = array_map( + function($namespace): string { + return rtrim($namespace, '\\') . '\\'; + }, + $types + ); } else { $namespaceType = []; } @@ -84,20 +94,6 @@ public function load(array $configs, ContainerBuilder $container): void ->addTag('graphql.root_type_mapper_factory'); } - private function getNamespaceDir(string $namespace): string - { - $classNameMapper = ClassNameMapper::createFromComposerFile(null, null, true); - - $possibleFileNames = $classNameMapper->getPossibleFileNames($namespace.'Xxx'); - if (count($possibleFileNames) > 1) { - throw new \RuntimeException(sprintf('According to your composer.json, classes belonging to the "%s" namespace can be located in several directories: %s. This is an issue for the GraphQLite lib. Please make sure that a namespace can only be resolved to one PHP file.', $namespace, implode(", ", $possibleFileNames))); - } elseif (empty($possibleFileNames)) { - throw new \RuntimeException(sprintf('Files in namespace "%s" cannot be autoloaded by Composer. Please set up a PSR-4 autoloader in Composer or change the namespace configured in "graphqlite.namespace.controllers" and "graphqlite.namespace.types"', $namespace)); - } - - return substr($possibleFileNames[0], 0, -8); - } - /** * @param array $debug * @return int diff --git a/DependencyInjection/OverblogGraphiQLEndpointWiringPass.php b/DependencyInjection/OverblogGraphiQLEndpointWiringPass.php index 43df7ef..4b50c6a 100644 --- a/DependencyInjection/OverblogGraphiQLEndpointWiringPass.php +++ b/DependencyInjection/OverblogGraphiQLEndpointWiringPass.php @@ -2,8 +2,6 @@ namespace TheCodingMachine\Graphqlite\Bundle\DependencyInjection; -use Overblog\GraphiQLBundle\Config\GraphiQLControllerEndpoint; -use Overblog\GraphiQLBundle\Config\GraphqlEndpoint\RootResolver; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; diff --git a/GraphiQL/EndpointResolver.php b/GraphiQL/EndpointResolver.php index 26f6698..4064844 100644 --- a/GraphiQL/EndpointResolver.php +++ b/GraphiQL/EndpointResolver.php @@ -3,10 +3,15 @@ namespace TheCodingMachine\Graphqlite\Bundle\GraphiQL; use Overblog\GraphiQLBundle\Config\GraphiQLControllerEndpoint; +use Overblog\GraphiQLBundle\Config\GraphQLEndpoint\GraphQLEndpointInvalidSchemaException; use Symfony\Component\HttpFoundation\RequestStack; +use Webmozart\Assert\Assert; final class EndpointResolver implements GraphiQLControllerEndpoint { + /** + * @var RequestStack + */ protected $requestStack; public function __construct(RequestStack $requestStack) @@ -18,6 +23,7 @@ public function getBySchema($name) { if ('default' === $name) { $request = $this->requestStack->getCurrentRequest(); + Assert::notNull($request); return $request->getBaseUrl().'/graphql'; } diff --git a/Mappers/RequestParameterMiddleware.php b/Mappers/RequestParameterMiddleware.php index 2f67f3c..9f23d5a 100644 --- a/Mappers/RequestParameterMiddleware.php +++ b/Mappers/RequestParameterMiddleware.php @@ -6,6 +6,7 @@ use phpDocumentor\Reflection\DocBlock; use phpDocumentor\Reflection\Type; +use ReflectionNamedType; use ReflectionParameter; use Symfony\Component\HttpFoundation\Request; use TheCodingMachine\GraphQLite\Annotations\ParameterAnnotations; @@ -15,13 +16,13 @@ class RequestParameterMiddleware implements ParameterMiddlewareInterface { - public function mapParameter(ReflectionParameter $parameter, DocBlock $docBlock, ?Type $paramTagType, ParameterAnnotations $parameterAnnotations, ParameterHandlerInterface $next): ParameterInterface { $parameterType = $parameter->getType(); - if ($parameterType && $parameterType->getName() === Request::class) { + if ($parameterType instanceof ReflectionNamedType && $parameterType->getName() === Request::class) { return new RequestParameter(); } + return $next->mapParameter($parameter, $docBlock, $paramTagType, $parameterAnnotations); } } diff --git a/Server/ServerConfig.php b/Server/ServerConfig.php index ef0f4e1..b831f15 100644 --- a/Server/ServerConfig.php +++ b/Server/ServerConfig.php @@ -4,6 +4,9 @@ namespace TheCodingMachine\Graphqlite\Bundle\Server; use GraphQL\Error\InvariantViolation; +use GraphQL\GraphQL; +use GraphQL\Language\AST\DocumentNode; +use GraphQL\Server\OperationParams; use GraphQL\Utils\Utils; use GraphQL\Validator\DocumentValidator; use GraphQL\Validator\Rules\ValidationRule; @@ -27,7 +30,15 @@ class ServerConfig extends \GraphQL\Server\ServerConfig */ public function setValidationRules($validationRules) { - parent::setValidationRules(array_merge(DocumentValidator::defaultRules(), $validationRules)); + parent::setValidationRules( + function (OperationParams $params, DocumentNode $doc, string $operationType) use ($validationRules): array { + $validationRules = is_callable($validationRules) + ? $validationRules($params, $doc, $operationType) + : $validationRules; + + return array_merge(DocumentValidator::defaultRules(), $validationRules); + } + ); return $this; } diff --git a/composer.json b/composer.json index 79b5fde..a57c58b 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,8 @@ "php-coveralls/php-coveralls": "^2.1.0", "symfony/phpunit-bridge": "^5.3", "thecodingmachine/phpstan-strict-rules": "^v0.12.1", - "composer/package-versions-deprecated": "^1.8" + "composer/package-versions-deprecated": "^1.8", + "phpstan/phpstan-webmozart-assert": "^0.12.12" }, "conflict": { "mouf/classname-mapper": "<1.0.2", diff --git a/phpstan.baseline.neon b/phpstan.baseline.neon deleted file mode 100644 index f685b67..0000000 --- a/phpstan.baseline.neon +++ /dev/null @@ -1,186 +0,0 @@ -parameters: - ignoreErrors: - - - message: "#^Method Symfony\\\\Contracts\\\\EventDispatcher\\\\EventDispatcherInterface\\:\\:dispatch\\(\\) invoked with 2 parameters, 1 required\\.$#" - count: 1 - path: Controller/GraphQL/LoginController.php - - - - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 1 - path: Controller/GraphqliteController.php - - - - message: "#^Instanceof between GraphQL\\\\Executor\\\\Promise\\\\Promise and GraphQL\\\\Executor\\\\Promise\\\\Promise will always evaluate to true\\.$#" - count: 1 - path: Controller/GraphqliteController.php - - - - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 1 - path: DependencyInjection/GraphqliteCompilerPass.php - - - - message: "#^Argument of an invalid type array\\|bool\\|float\\|int\\|string\\|null supplied for foreach, only iterables are supported\\.$#" - count: 3 - path: DependencyInjection/GraphqliteCompilerPass.php - - - - message: "#^Binary operation \"\\.\" between 'security\\.firewall…' and array\\|bool\\|float\\|int\\|string\\|null results in an error\\.$#" - count: 2 - path: DependencyInjection/GraphqliteCompilerPass.php - - - - message: "#^Cannot cast \\(array&nonEmpty\\)\\|float\\|int\\\\|int\\<1, max\\>\\|string\\|true to int\\.$#" - count: 2 - path: DependencyInjection/GraphqliteCompilerPass.php - - - - message: "#^Negated boolean expression is always true\\.$#" - count: 1 - path: DependencyInjection/GraphqliteCompilerPass.php - - - - message: "#^Property TheCodingMachine\\\\Graphqlite\\\\Bundle\\\\DependencyInjection\\\\GraphqliteCompilerPass\\:\\:\\$cacheDir \\(string\\) does not accept array\\|bool\\|float\\|int\\|string\\|null\\.$#" - count: 1 - path: DependencyInjection/GraphqliteCompilerPass.php - - - - message: "#^Anonymous function should have native return typehint \"string\"\\.$#" - count: 2 - path: DependencyInjection/GraphqliteExtension.php - - - - message: "#^Method TheCodingMachine\\\\Graphqlite\\\\Bundle\\\\DependencyInjection\\\\GraphqliteExtension\\:\\:getNamespaceDir\\(\\) is unused\\.$#" - count: 1 - path: DependencyInjection/GraphqliteExtension.php - - - - message: "#^Class Overblog\\\\GraphiQLBundle\\\\Config\\\\GraphQLEndpoint\\\\RootResolver referenced with incorrect case\\: Overblog\\\\GraphiQLBundle\\\\Config\\\\GraphqlEndpoint\\\\RootResolver\\.$#" - count: 1 - path: DependencyInjection/OverblogGraphiQLEndpointWiringPass.php - - - - message: "#^Call to static method forSchemaAndResolver\\(\\) on an unknown class TheCodingMachine\\\\Graphqlite\\\\Bundle\\\\GraphiQL\\\\GraphQLEndpointInvalidSchemaException\\.$#" - count: 1 - path: GraphiQL/EndpointResolver.php - - - - message: "#^Property TheCodingMachine\\\\Graphqlite\\\\Bundle\\\\GraphiQL\\\\EndpointResolver\\:\\:\\$requestStack has no typehint specified\\.$#" - count: 1 - path: GraphiQL/EndpointResolver.php - - - - message: "#^Call to an undefined method ReflectionType\\:\\:getName\\(\\)\\.$#" - count: 1 - path: Mappers/RequestParameterMiddleware.php - - - - message: "#^Parameter \\#2 \\.\\.\\.\\$args of function array_merge expects array, array\\\\|\\(callable\\) given\\.$#" - count: 1 - path: Server/ServerConfig.php - - - - message: "#^Method TheCodingMachine\\\\Graphqlite\\\\Bundle\\\\Tests\\\\Fixtures\\\\Controller\\\\TestGraphqlController\\:\\:contacts\\(\\) return type has no value type specified in iterable type Porpaginas\\\\Arrays\\\\ArrayResult\\.$#" - count: 1 - path: Tests/Fixtures/Controller/TestGraphqlController.php - - - - message: "#^PHPDoc tag @return with type array\\ is incompatible with native type Porpaginas\\\\Arrays\\\\ArrayResult\\.$#" - count: 1 - path: Tests/Fixtures/Controller/TestGraphqlController.php - - - - message: "#^Method TheCodingMachine\\\\Graphqlite\\\\Bundle\\\\Tests\\\\Fixtures\\\\Entities\\\\Contact\\:\\:injectServicePrefetch\\(\\) has parameter \\$prefetchData with no typehint specified\\.$#" - count: 1 - path: Tests/Fixtures/Entities/Contact.php - - - - message: "#^Method TheCodingMachine\\\\Graphqlite\\\\Bundle\\\\Tests\\\\Fixtures\\\\Entities\\\\Contact\\:\\:prefetchData\\(\\) has no return typehint specified\\.$#" - count: 1 - path: Tests/Fixtures/Entities/Contact.php - - - - message: "#^Method TheCodingMachine\\\\Graphqlite\\\\Bundle\\\\Tests\\\\Fixtures\\\\Entities\\\\Contact\\:\\:prefetchData\\(\\) has parameter \\$iterable with no value type specified in iterable type iterable\\.$#" - count: 1 - path: Tests/Fixtures/Entities/Contact.php - - - - message: "#^Call to an undefined method object\\:\\:assertValid\\(\\)\\.$#" - count: 2 - path: Tests/FunctionalTest.php - - - - message: "#^Call to an undefined method object\\:\\:handleRequest\\(\\)\\.$#" - count: 1 - path: Tests/FunctionalTest.php - - - - message: "#^Cannot call method get\\(\\) on Symfony\\\\Component\\\\DependencyInjection\\\\ContainerInterface\\|null\\.$#" - count: 3 - path: Tests/FunctionalTest.php - - - - message: "#^Cannot call method set\\(\\) on Symfony\\\\Component\\\\DependencyInjection\\\\ContainerInterface\\|null\\.$#" - count: 4 - path: Tests/FunctionalTest.php - - - - message: "#^Method TheCodingMachine\\\\Graphqlite\\\\Bundle\\\\Tests\\\\FunctionalTest\\:\\:logIn\\(\\) has no return typehint specified\\.$#" - count: 1 - path: Tests/FunctionalTest.php - - - - message: "#^Parameter \\#1 \\$container of method TheCodingMachine\\\\Graphqlite\\\\Bundle\\\\Tests\\\\FunctionalTest\\:\\:logIn\\(\\) expects Psr\\\\Container\\\\ContainerInterface, Symfony\\\\Component\\\\DependencyInjection\\\\ContainerInterface\\|null given\\.$#" - count: 1 - path: Tests/FunctionalTest.php - - - - message: "#^Parameter \\#1 \\$json of function json_decode expects string, string\\|false given\\.$#" - count: 15 - path: Tests/FunctionalTest.php - - - - message: "#^Parameter \\#3 \\$message of method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\) expects string, string\\|false given\\.$#" - count: 1 - path: Tests/FunctionalTest.php - - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 1 - path: Tests/GraphqliteTestingKernel.php - - - - message: "#^Method TheCodingMachine\\\\Graphqlite\\\\Bundle\\\\Tests\\\\GraphqliteTestingKernel\\:\\:configureContainer\\(\\) has no return typehint specified\\.$#" - count: 1 - path: Tests/GraphqliteTestingKernel.php - - - - message: "#^Method TheCodingMachine\\\\Graphqlite\\\\Bundle\\\\Tests\\\\GraphqliteTestingKernel\\:\\:configureRoutes\\(\\) has no return typehint specified\\.$#" - count: 1 - path: Tests/GraphqliteTestingKernel.php - - - - message: "#^Method TheCodingMachine\\\\Graphqlite\\\\Bundle\\\\Tests\\\\GraphqliteTestingKernel\\:\\:configureRoutes\\(\\) has parameter \\$routes with no typehint specified\\.$#" - count: 1 - path: Tests/GraphqliteTestingKernel.php - - - - message: "#^Property TheCodingMachine\\\\Graphqlite\\\\Bundle\\\\Tests\\\\GraphqliteTestingKernel\\:\\:\\$enableLogin \\(string\\) does not accept string\\|null\\.$#" - count: 1 - path: Tests/GraphqliteTestingKernel.php - - - - message: "#^Call to an undefined method object\\:\\:assertValid\\(\\)\\.$#" - count: 1 - path: Tests/NoSecurityBundleTest.php - - - - message: "#^Cannot call method get\\(\\) on Symfony\\\\Component\\\\DependencyInjection\\\\ContainerInterface\\|null\\.$#" - count: 1 - path: Tests/NoSecurityBundleTest.php - - - - message: "#^Parameter \\#1 \\$json of function json_decode expects string, string\\|false given\\.$#" - count: 1 - path: Tests/NoSecurityBundleTest.php diff --git a/phpstan.neon b/phpstan.neon index fd86821..e360a44 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,7 +1,7 @@ includes: - vendor/phpstan/phpstan/conf/bleedingEdge.neon + - vendor/phpstan/phpstan-webmozart-assert/extension.neon - vendor/thecodingmachine/phpstan-strict-rules/phpstan-strict-rules.neon - - phpstan.baseline.neon parameters: tmpDir: .phpstan-cache paths: @@ -10,6 +10,7 @@ parameters: - vendor - cache - .phpstan-cache + - Tests bootstrapFiles: - vendor/bin/.phpunit/phpunit/vendor/autoload.php level: max From 4208ff02f36b617c839014ba68529d7a121712bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Szigeti?= Date: Tue, 22 Jun 2021 07:14:54 +0200 Subject: [PATCH 15/26] Stan fixes for latest deps --- .../GraphqliteCompilerPass.php | 27 ++++++++++++++----- Types/SymfonyUserInterfaceType.php | 7 ++++- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/DependencyInjection/GraphqliteCompilerPass.php b/DependencyInjection/GraphqliteCompilerPass.php index 93fcc01..99a1f1f 100644 --- a/DependencyInjection/GraphqliteCompilerPass.php +++ b/DependencyInjection/GraphqliteCompilerPass.php @@ -13,6 +13,7 @@ use Symfony\Component\Cache\Psr16Cache; use TheCodingMachine\GraphQLite\Mappers\StaticClassListTypeMapper; use TheCodingMachine\GraphQLite\Mappers\StaticClassListTypeMapperFactory; +use Webmozart\Assert\Assert; use function class_exists; use Doctrine\Common\Annotations\AnnotationException; use Doctrine\Common\Annotations\AnnotationReader as DoctrineAnnotationReader; @@ -102,14 +103,19 @@ class GraphqliteCompilerPass implements CompilerPassInterface public function process(ContainerBuilder $container): void { $reader = $this->getAnnotationReader(); - $this->cacheDir = $container->getParameter('kernel.cache_dir'); + $cacheDir = $container->getParameter('kernel.cache_dir'); + Assert::string($cacheDir); + $this->cacheDir = $cacheDir; //$inputTypeUtils = new InputTypeUtils($reader, $namingStrategy); // Let's scan the whole container and tag the services that belong to the namespace we want to inspect. $controllersNamespaces = $container->getParameter('graphqlite.namespace.controllers'); + Assert::isIterable($controllersNamespaces); $typesNamespaces = $container->getParameter('graphqlite.namespace.types'); + Assert::isIterable($typesNamespaces); $firewallName = $container->getParameter('graphqlite.security.firewall_name'); + Assert::string($firewallName); $firewallConfigServiceName = 'security.firewall.map.config.'.$firewallName; // 2 seconds of TTL in environment mode. Otherwise, let's cache forever! @@ -183,13 +189,20 @@ public function process(ContainerBuilder $container): void if ($container->getParameter('graphqlite.security.introspection') === false) { $rulesDefinition[] = $container->findDefinition(DisableIntrospection::class); } - if ($container->getParameter('graphqlite.security.maximum_query_complexity')) { - $complexity = (int) $container->getParameter('graphqlite.security.maximum_query_complexity'); - $rulesDefinition[] = $container->findDefinition(QueryComplexity::class)->setArgument(0, $complexity); + if ($container->hasParameter('graphqlite.security.maximum_query_complexity')) { + $complexity = $container->getParameter('graphqlite.security.maximum_query_complexity'); + Assert::integerish($complexity); + + $rulesDefinition[] = $container->findDefinition(QueryComplexity::class) + ->setArgument(0, (int) $complexity); } - if ($container->getParameter('graphqlite.security.maximum_query_depth')) { - $depth = (int) $container->getParameter('graphqlite.security.maximum_query_depth'); - $rulesDefinition[] = $container->findDefinition(QueryDepth::class)->setArgument(0, $depth); + + if ($container->hasParameter('graphqlite.security.maximum_query_depth')) { + $depth = $container->getParameter('graphqlite.security.maximum_query_depth'); + Assert::integerish($depth); + + $rulesDefinition[] = $container->findDefinition(QueryDepth::class) + ->setArgument(0, (int) $depth); } $serverConfigDefinition->addMethodCall('setValidationRules', [$rulesDefinition]); diff --git a/Types/SymfonyUserInterfaceType.php b/Types/SymfonyUserInterfaceType.php index bbc1f5a..ecb01a7 100644 --- a/Types/SymfonyUserInterfaceType.php +++ b/Types/SymfonyUserInterfaceType.php @@ -23,7 +23,12 @@ public function getRoles(UserInterface $user): array { $roles = []; foreach ($user->getRoles() as $role) { - $roles[] = $role instanceof Role ? $role->getRole() : $role; + // @phpstan-ignore-next-line BC for Symfony 4 + if (class_exists(Role::class) && $role instanceof Role) { + $role = $role->getRole(); + } + + $roles[] = $role; } return $roles; } From ca4181c622473faa552801ad0aabe7febbcee8a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Szigeti?= Date: Tue, 22 Jun 2021 07:26:13 +0200 Subject: [PATCH 16/26] fixing the fix --- DependencyInjection/GraphqliteCompilerPass.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/DependencyInjection/GraphqliteCompilerPass.php b/DependencyInjection/GraphqliteCompilerPass.php index 99a1f1f..e040070 100644 --- a/DependencyInjection/GraphqliteCompilerPass.php +++ b/DependencyInjection/GraphqliteCompilerPass.php @@ -189,21 +189,23 @@ public function process(ContainerBuilder $container): void if ($container->getParameter('graphqlite.security.introspection') === false) { $rulesDefinition[] = $container->findDefinition(DisableIntrospection::class); } - if ($container->hasParameter('graphqlite.security.maximum_query_complexity')) { - $complexity = $container->getParameter('graphqlite.security.maximum_query_complexity'); + + $complexity = $container->getParameter('graphqlite.security.maximum_query_complexity'); + if ($complexity) { Assert::integerish($complexity); $rulesDefinition[] = $container->findDefinition(QueryComplexity::class) ->setArgument(0, (int) $complexity); } - if ($container->hasParameter('graphqlite.security.maximum_query_depth')) { - $depth = $container->getParameter('graphqlite.security.maximum_query_depth'); + $depth = $container->getParameter('graphqlite.security.maximum_query_depth'); + if ($depth) { Assert::integerish($depth); $rulesDefinition[] = $container->findDefinition(QueryDepth::class) ->setArgument(0, (int) $depth); } + $serverConfigDefinition->addMethodCall('setValidationRules', [$rulesDefinition]); if ($disableMe === false) { From 7db60af417f55e03ee82d5987585388b1b488163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Szigeti?= Date: Tue, 22 Jun 2021 07:31:52 +0200 Subject: [PATCH 17/26] Leftover --- DependencyInjection/GraphqliteCompilerPass.php | 2 +- phpstan.neon | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/DependencyInjection/GraphqliteCompilerPass.php b/DependencyInjection/GraphqliteCompilerPass.php index e040070..6a2fa71 100644 --- a/DependencyInjection/GraphqliteCompilerPass.php +++ b/DependencyInjection/GraphqliteCompilerPass.php @@ -501,7 +501,7 @@ private function getClassList(string $namespace, int $globTtl = 2, bool $recursi // The autoloader might trigger errors if the file does not respect PSR-4 or if the // Symfony DebugAutoLoader is installed. (see https://github.com/thecodingmachine/graphqlite/issues/216) require_once $phpFile; - // @phpstan-ignore-next-line Does it exists now? + // @phpstan-ignore-next-line Does it exist now? if (! class_exists($className, false)) { continue; } diff --git a/phpstan.neon b/phpstan.neon index e360a44..05e8f67 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -11,8 +11,6 @@ parameters: - cache - .phpstan-cache - Tests - bootstrapFiles: - - vendor/bin/.phpunit/phpunit/vendor/autoload.php level: max polluteScopeWithLoopInitialAssignments: false polluteScopeWithAlwaysIterableForeach: false @@ -27,5 +25,5 @@ parameters: treatPhpDocTypesAsCertain: false reportUnmatchedIgnoredErrors: false ignoreErrors: - # Symfony's TreeBuilder has problem - some method(s) in the chain have a wrong return typehint: + # Wrong return type hint in Symfony's TreeBuilder - '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition::\w+\(\).#' From f6dd4944a5588d9805e927504d5077901daeb44f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Szigeti?= Date: Tue, 22 Jun 2021 07:35:27 +0200 Subject: [PATCH 18/26] Bump doctrine annotations for php8 compatibility --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a57c58b..fe2f4ee 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "symfony/framework-bundle": "^4.2 || ^5", "symfony/validator": "^4.2 || ^5", "symfony/translation": "^4.2 || ^5", - "doctrine/annotations": "^1.6", + "doctrine/annotations": "^1.10.4", "doctrine/cache": "^1.8", "symfony/psr-http-message-bridge": "^2.0", "nyholm/psr7": "^1.1", From eea039db268e7ebf9b36820f506a63ff443bf5d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Szigeti?= Date: Tue, 22 Jun 2021 07:47:25 +0200 Subject: [PATCH 19/26] Enforce stable deps --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index fe2f4ee..e7ed3c0 100644 --- a/composer.json +++ b/composer.json @@ -63,6 +63,5 @@ "dev-master": "4.1.x-dev" } }, - "minimum-stability": "dev", "prefer-stable": true } From caf2288eb7b2747a71bafb6db47e1fc9dcca0df7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Szigeti?= Date: Tue, 22 Jun 2021 08:38:49 +0200 Subject: [PATCH 20/26] Forward compatibility for Symfony 5.3 user interface --- Types/SymfonyUserInterfaceType.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Types/SymfonyUserInterfaceType.php b/Types/SymfonyUserInterfaceType.php index ecb01a7..5cc0d12 100644 --- a/Types/SymfonyUserInterfaceType.php +++ b/Types/SymfonyUserInterfaceType.php @@ -8,13 +8,30 @@ use TheCodingMachine\GraphQLite\Annotations\SourceField; use TheCodingMachine\GraphQLite\Annotations\Type; use Symfony\Component\Security\Core\User\UserInterface; +use TheCodingMachine\GraphQLite\FieldNotFoundException; /** * @Type(class=UserInterface::class) - * @SourceField(name="userName") */ class SymfonyUserInterfaceType { + /** + * @Field + */ + public function getUserName(UserInterface $user): string + { + // @phpstan-ignore-next-line Forward Compatibility for Symfony 5.3 + if (method_exists($user, 'getUserIdentifier')) { + return $user->getUserIdentifier(); + } + + if (method_exists($user, 'getUserName')) { + return $user->getUserName(); + } + + throw FieldNotFoundException::missingField(UserInterface::class, 'userName'); + } + /** * @Field() * @return string[] From 8829560dbe47c0fae99f158af0ae99d27e72f380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Szigeti?= Date: Tue, 22 Jun 2021 08:46:36 +0200 Subject: [PATCH 21/26] Bump minimum phpdoc type resolver --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e7ed3c0..002d7bb 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,8 @@ "mouf/classname-mapper": "<1.0.2", "symfony/event-dispatcher": "<4.3", "symfony/security-core": "<4.3", - "symfony/routing": "<4.3" + "symfony/routing": "<4.3", + "phpdocumentor/type-resolver": "<1.4" }, "scripts": { "phpstan": "phpstan analyse GraphqliteBundle.php DependencyInjection/ Controller/ Resources/ Security/ -c phpstan.neon --level=7 --no-progress" From a15ea6f46a698d7a9e0e7f0239f0dadf6fc1ab39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Szigeti?= Date: Tue, 22 Jun 2021 08:48:42 +0200 Subject: [PATCH 22/26] stan fix --- Types/SymfonyUserInterfaceType.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Types/SymfonyUserInterfaceType.php b/Types/SymfonyUserInterfaceType.php index 5cc0d12..ea0fd2c 100644 --- a/Types/SymfonyUserInterfaceType.php +++ b/Types/SymfonyUserInterfaceType.php @@ -20,13 +20,14 @@ class SymfonyUserInterfaceType */ public function getUserName(UserInterface $user): string { - // @phpstan-ignore-next-line Forward Compatibility for Symfony 5.3 + // @phpstan-ignore-next-line Forward Compatibility for Symfony >=5.3 if (method_exists($user, 'getUserIdentifier')) { return $user->getUserIdentifier(); } - if (method_exists($user, 'getUserName')) { - return $user->getUserName(); + // @phpstan-ignore-next-line Backward Compatibility for Symfony <5.3 + if (method_exists($user, 'getUsername')) { + return $user->getUsername(); } throw FieldNotFoundException::missingField(UserInterface::class, 'userName'); From 6c52c55639ed6b9433b98a2e5ff4a6b366ea5a71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Szigeti?= Date: Tue, 22 Jun 2021 09:04:14 +0200 Subject: [PATCH 23/26] readd coverage and stuff --- phpunit.xml.dist | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 9a9e0b2..9c1411b 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -21,7 +21,34 @@ + + + + ./ + + cache + build + ./Resources + ./Tests + ./vendor + ./var + + + + + + + + - + + + + + + 0 + + + From a9f747f7d5f1d725bf7697bee7d419b383d288a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Szigeti?= Date: Tue, 22 Jun 2021 09:05:23 +0200 Subject: [PATCH 24/26] revert more --- phpunit.xml.dist | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 9c1411b..a557705 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -16,8 +16,8 @@ - - Tests + + ./Tests/ From 57411e670b09051c82ec23e3b8b0999a618002e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Szigeti?= Date: Tue, 22 Jun 2021 09:08:44 +0200 Subject: [PATCH 25/26] not needed --- phpunit.xml.dist | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a557705..cdfcc0f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -41,14 +41,6 @@ - - - - - - 0 - - - + From 7053b43545cc58906400b6f2b15c103f1ee60a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Szigeti?= Date: Tue, 22 Jun 2021 09:13:43 +0200 Subject: [PATCH 26/26] Add ext-json dep --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 002d7bb..0643288 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,7 @@ ], "require" : { "php" : ">=7.2", + "ext-json": "*", "thecodingmachine/graphqlite" : "^4.1.2", "thecodingmachine/graphqlite-symfony-validator-bridge" : "^4.1", "symfony/framework-bundle": "^4.2 || ^5",