From c35a1060338e9fd12688e336289b7d6b4d8bc3c4 Mon Sep 17 00:00:00 2001 From: Klaus Purer Date: Thu, 22 Dec 2022 15:00:02 +0100 Subject: [PATCH 1/6] test(github): Enable PHP 8.2 testing --- .github/workflows/testing.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index b7388744a..e1f6d713e 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -13,18 +13,18 @@ jobs: strategy: fail-fast: false matrix: - php-versions: ['7.3', '7.4', '8.0'] + php-versions: ['7.3', '7.4', '8.0', '8.1'] drupal-core: ['9.5.x'] phpstan: ['0'] include: - # We only need to run PHPStan once on the latest PHP version. - - php-versions: '8.1' - drupal-core: '9.5.x' - phpstan: '1' - # Extra run to also test on latest Drupal 10 and PHP 8.1. + # Extra runs to also test on latest Drupal 10. - php-versions: '8.1' drupal-core: '10.0.x' phpstan: '0' + # We only need to run PHPStan once on the latest PHP version. + - php-versions: '8.2' + drupal-core: '10.0.x' + phpstan: '1' steps: - name: Checkout Drupal core uses: actions/checkout@v3 From 920d2d1225dbe72ff6820bbba8e454f66f60e6ec Mon Sep 17 00:00:00 2001 From: Klaus Purer Date: Thu, 22 Dec 2022 15:32:16 +0100 Subject: [PATCH 2/6] fix var in string deprecation --- tests/src/Traits/QueryResultAssertionTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/Traits/QueryResultAssertionTrait.php b/tests/src/Traits/QueryResultAssertionTrait.php index 6917103ee..9b4b24036 100644 --- a/tests/src/Traits/QueryResultAssertionTrait.php +++ b/tests/src/Traits/QueryResultAssertionTrait.php @@ -192,7 +192,7 @@ private function assertResultErrors(ExecutionResult $result, array $expected): v while ($original_error->getPrevious() !== NULL) { $original_error = $original_error->getPrevious(); } - $unexpected[] = "Error message: ${error_message}\n Originated in: {$original_error->getFile()}:{$original_error->getLine()}"; + $unexpected[] = "Error message: {$error_message}\n Originated in: {$original_error->getFile()}:{$original_error->getLine()}"; } } From f37d5e00f4dc4bd42a2f08f31a86396311292991 Mon Sep 17 00:00:00 2001 From: Klaus Purer Date: Thu, 2 Feb 2023 15:46:56 +0100 Subject: [PATCH 3/6] Fix phpstan --- phpstan.neon | 7 ------- src/GraphQL/Execution/Executor.php | 7 +------ src/Plugin/GraphQL/DataProducer/DataProducerProxy.php | 1 - 3 files changed, 1 insertion(+), 14 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index a259df9b3..1c95513ea 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -24,16 +24,9 @@ parameters: # Drupal allows object property access to custom fields, so we cannot fix # that. - "#^Access to an undefined property Drupal\\\\#" - # PHPUnit deprecation warnings in Drupal 9 that we don't care about. - - "#^Method Symfony\\\\Contracts\\\\EventDispatcher\\\\EventDispatcherInterface\\:\\:dispatch\\(\\) invoked with 2 parameters, 1 required\\.$#" # Drupal allows object property access to custom fields, so we cannot fix # that. - "#^Property Drupal\\\\.+ \\(Drupal\\\\Core\\\\Field\\\\FieldItemListInterface\\) does not accept .+\\.$#" - # Incomplete type doc comments in Drupal core that we have to ignore. - - - message: "#^Method Drupal\\\\graphql\\\\Plugin\\\\LanguageNegotiation\\\\OperationLanguageNegotiation\\:\\:getLangcode\\(\\) should return string but returns false\\.$#" - count: 1 - path: src/Plugin/LanguageNegotiation/OperationLanguageNegotiation.php # We forgot to use return type hints on some interfaces, cannot be changed # in stable 4.0. # @todo use return type hints everywhere for 5.0. diff --git a/src/GraphQL/Execution/Executor.php b/src/GraphQL/Execution/Executor.php index 110c946a6..0d0e92edd 100644 --- a/src/GraphQL/Execution/Executor.php +++ b/src/GraphQL/Execution/Executor.php @@ -443,12 +443,7 @@ protected function cacheWrite($prefix, CacheableExecutionResult $result) { * @see \Drupal\Core\Cache\CacheBackendInterface::set() */ protected function maxAgeToExpire($maxAge) { - /* @todo Can be removed when D9 support is dropped. In D9 - * \Drupal\Core\Http\RequestStack is used here for forward compatibility, - * but phpstan thinks it's \Symfony\Component\HttpFoundation\RequestStack - * which doesn't have getMainRequest(), but in Drupal10 (Symfony 6) it has. - */ - /* @phpstan-ignore-next-line */ + // @todo Can be removed when D9 support is dropped. $time = $this->requestStack->getMainRequest()->server->get('REQUEST_TIME'); return ($maxAge === Cache::PERMANENT) ? Cache::PERMANENT : (int) $time + $maxAge; } diff --git a/src/Plugin/GraphQL/DataProducer/DataProducerProxy.php b/src/Plugin/GraphQL/DataProducer/DataProducerProxy.php index 1858af6b6..4e5747099 100644 --- a/src/Plugin/GraphQL/DataProducer/DataProducerProxy.php +++ b/src/Plugin/GraphQL/DataProducer/DataProducerProxy.php @@ -363,7 +363,6 @@ protected function cacheWrite($prefix, $value, FieldContext $field): void { * @see \Drupal\Core\Cache\CacheBackendInterface::set() */ protected function maxAgeToExpire($maxAge) { - /* @phpstan-ignore-next-line */ $time = $this->requestStack->getMainRequest()->server->get('REQUEST_TIME'); return ($maxAge === Cache::PERMANENT) ? Cache::PERMANENT : (int) $time + $maxAge; } From 10bd70d318214aafdb0ff015895f9f5d25cd9be6 Mon Sep 17 00:00:00 2001 From: Klaus Purer Date: Thu, 2 Feb 2023 17:22:49 +0100 Subject: [PATCH 4/6] remove more phpstan errors --- phpstan.neon | 3 --- .../DataProducer/Entity/Fields/Image/ImageDerivative.php | 3 --- 2 files changed, 6 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 1c95513ea..68be96082 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -24,9 +24,6 @@ parameters: # Drupal allows object property access to custom fields, so we cannot fix # that. - "#^Access to an undefined property Drupal\\\\#" - # Drupal allows object property access to custom fields, so we cannot fix - # that. - - "#^Property Drupal\\\\.+ \\(Drupal\\\\Core\\\\Field\\\\FieldItemListInterface\\) does not accept .+\\.$#" # We forgot to use return type hints on some interfaces, cannot be changed # in stable 4.0. # @todo use return type hints everywhere for 5.0. diff --git a/src/Plugin/GraphQL/DataProducer/Entity/Fields/Image/ImageDerivative.php b/src/Plugin/GraphQL/DataProducer/Entity/Fields/Image/ImageDerivative.php index bb9b2064f..04a16bf8c 100644 --- a/src/Plugin/GraphQL/DataProducer/Entity/Fields/Image/ImageDerivative.php +++ b/src/Plugin/GraphQL/DataProducer/Entity/Fields/Image/ImageDerivative.php @@ -101,9 +101,6 @@ public function resolve(FileInterface $entity = NULL, $style, RefinableCacheable $width = $entity->width; $height = $entity->height; - // @todo Not sure why PHPStan complains here, this should be refactored to - // check the entity properties first. - // @phpstan-ignore-next-line if (empty($width) || empty($height)) { /** @var \Drupal\Core\Image\ImageInterface $image */ $image = \Drupal::service('image.factory')->get($entity->getFileUri()); From 7e9f0c63f94f64ee17c18b059ad744149cb46300 Mon Sep 17 00:00:00 2001 From: Klaus Purer Date: Thu, 2 Feb 2023 17:45:42 +0100 Subject: [PATCH 5/6] workaround phpstan drupal --- .github/workflows/testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index e1f6d713e..65c58d009 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -110,7 +110,7 @@ jobs: SIMPLETEST_DB: "sqlite://localhost/:memory:" - name: Run PHPStan - run: if [[ ${{ matrix.phpstan }} == "1" ]]; then cd modules/graphql && ../../vendor/bin/phpstan analyse; fi + run: if [[ ${{ matrix.phpstan }} == "1" ]]; then rm vendor/mglaman/phpstan-drupal/stubs/Drupal/Core/Field/FieldItemList.stub && cd modules/graphql && ../../vendor/bin/phpstan analyse; fi - name: Run PHPCS run: | From efd124d6f958fd25468642f1c888db75641742e1 Mon Sep 17 00:00:00 2001 From: Klaus Purer Date: Thu, 2 Feb 2023 17:52:00 +0100 Subject: [PATCH 6/6] Add comments --- .github/workflows/testing.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 65c58d009..910b2ff28 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -110,6 +110,8 @@ jobs: SIMPLETEST_DB: "sqlite://localhost/:memory:" - name: Run PHPStan + # phpstan-drupal bug, so we remove 1 stub file + # https://github.com/mglaman/phpstan-drupal/issues/509 run: if [[ ${{ matrix.phpstan }} == "1" ]]; then rm vendor/mglaman/phpstan-drupal/stubs/Drupal/Core/Field/FieldItemList.stub && cd modules/graphql && ../../vendor/bin/phpstan analyse; fi - name: Run PHPCS