Skip to content

Commit fbd4291

Browse files
authored
test(phpstan): Update PHPStan and dependencies (#1257)
1 parent 31498a8 commit fbd4291

13 files changed

Lines changed: 61 additions & 16 deletions

File tree

.github/workflows/testing.yml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,21 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
php-versions: ['7.3', '7.4', '8.0', '8.1']
16+
php-versions: ['7.3', '7.4']
17+
phpstan: ['1']
1718
drupal-core: ['9.3.x']
1819
include:
1920
# Extra run to also test on latest Drupal 8 and PHP 7.2.
2021
- php-versions: '7.2'
2122
drupal-core: '8.9.x'
23+
phpstan: '1'
24+
# PHPStan is broken on PHP 8.0 and 8.1 for now, don't run it there.
25+
- php-versions: '8.0'
26+
drupal-core: '9.3.x'
27+
phpstan: '0'
28+
- php-versions: '8.1'
29+
drupal-core: '9.3.x'
30+
phpstan: '0'
2231
steps:
2332
- name: Checkout Drupal core
2433
uses: actions/checkout@v2
@@ -80,11 +89,11 @@ jobs:
8089
webonyx/graphql-php:^14.8 \
8190
drupal/typed_data:^1.0 \
8291
drupal/redirect:^1.6 \
83-
phpstan/phpstan:^0.12.88 \
84-
mglaman/phpstan-drupal:^0.12.8 \
85-
phpstan/phpstan-deprecation-rules:^0.12.2 \
86-
jangregor/phpstan-prophecy:^0.8 \
87-
phpstan/phpstan-phpunit:^0.12
92+
phpstan/phpstan:^1.2.0 \
93+
mglaman/phpstan-drupal:^1.1.2 \
94+
phpstan/phpstan-deprecation-rules:^1.0.0 \
95+
jangregor/phpstan-prophecy:^1.0.0 \
96+
phpstan/phpstan-phpunit:^1.0.0
8897

8998
# We install Coder separately because updating did not work in the local
9099
# Drupal vendor dir.
@@ -103,7 +112,7 @@ jobs:
103112

104113
- name: Run PHPStan
105114
run: |
106-
cd modules/graphql && ../../vendor/bin/phpstan analyse
115+
if [[ ${{ matrix.phpstan }} == "1" ]]; then cd modules/graphql && ../../vendor/bin/phpstan analyse; fi
107116
108117
- name: Run PHPCS
109118
run: |

examples/graphql_example/src/Wrappers/QueryConnection.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function __construct(QueryInterface $query) {
3030
public function total() {
3131
$query = clone $this->query;
3232
$query->range(NULL, NULL)->count();
33+
/** @var int */
3334
return $query->execute();
3435
}
3536

phpstan.neon

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,31 @@ parameters:
9090
count: 1
9191
path: src/Plugin/SchemaExtensionPluginInterface.php
9292

93+
-
94+
message: "#^Method Drupal\\\\graphql\\\\Plugin\\\\PersistedQueryPluginInterface\\:\\:setWeight\\(\\) has no return type specified\\.$#"
95+
count: 1
96+
path: src/Plugin/PersistedQueryPluginInterface.php
97+
98+
-
99+
message: "#^Method Drupal\\\\graphql\\\\Plugin\\\\SchemaExtensionPluginInterface\\:\\:registerResolvers\\(\\) has no return type specified\\.$#"
100+
count: 1
101+
path: src/Plugin/SchemaExtensionPluginInterface.php
102+
103+
-
104+
message: "#^Method Drupal\\\\graphql\\\\Entity\\\\ServerInterface\\:\\:addPersistedQueryInstance\\(\\) has no return type specified\\.$#"
105+
count: 1
106+
path: src/Entity/ServerInterface.php
107+
108+
-
109+
message: "#^Method Drupal\\\\graphql\\\\Entity\\\\ServerInterface\\:\\:removeAllPersistedQueryInstances\\(\\) has no return type specified\\.$#"
110+
count: 1
111+
path: src/Entity/ServerInterface.php
112+
113+
-
114+
message: "#^Method Drupal\\\\graphql\\\\Entity\\\\ServerInterface\\:\\:removePersistedQueryInstance\\(\\) has no return type specified\\.$#"
115+
count: 1
116+
path: src/Entity/ServerInterface.php
117+
93118
-
94119
message: "#^Unable to resolve the template type ExpectedType in call to method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\)$#"
95120
count: 1

src/Entity/Server.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,8 @@ protected function getPersistedQueryLoader() {
517517
*/
518518
protected function getValidationRules() {
519519
return function (OperationParams $params, DocumentNode $document, $operation) {
520+
// queryId is not documented properly in the library, it can be NULL.
521+
// @phpstan-ignore-next-line
520522
if (isset($params->queryId)) {
521523
// Assume that pre-parsed documents are already validated. This allows
522524
// us to store pre-validated query documents e.g. for persisted queries

src/EventSubscriber/CurrentLanguageResetTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ trait CurrentLanguageResetTrait {
1919
/**
2020
* The language negotiator.
2121
*
22-
* @var \Drupal\language\LanguageNegotiatorInterface
22+
* @var \Drupal\language\LanguageNegotiatorInterface|null
2323
*/
2424
protected $languageNegotiator;
2525

src/GraphQL/Utility/DeferredUtility.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class DeferredUtility {
1414
/**
1515
* The promise adapter.
1616
*
17-
* @var \GraphQL\Executor\Promise\Adapter\SyncPromiseAdapter
17+
* @var \GraphQL\Executor\Promise\Adapter\SyncPromiseAdapter|null
1818
*/
1919
public static $promiseAdapter;
2020

src/Plugin/GraphQL/DataProducer/Entity/Fields/Image/ImageDerivative.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ public function resolve(FileInterface $entity = NULL, $style, RefinableCacheable
101101
$width = $entity->width;
102102
$height = $entity->height;
103103

104+
// @todo Not sure why PHPStan complains here, this should be refactored to
105+
// check the entity properties first.
106+
// @phpstan-ignore-next-line
104107
if (empty($width) || empty($height)) {
105108
/** @var \Drupal\Core\Image\ImageInterface $image */
106109
$image = \Drupal::service('image.factory')->get($entity->getFileUri());

src/Plugin/GraphQL/DataProducer/Taxonomy/TermFieldAutocomplete.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ class TermFieldAutocomplete extends DataProducerPluginBase implements ContainerF
7575
/**
7676
* The term storage.
7777
*
78-
* @var \Drupal\taxonomy\TermStorageInterface
78+
* @var \Drupal\taxonomy\TermStorageInterface|null
7979
*/
8080
protected $termStorage;
8181

8282
/**
8383
* The term type.
8484
*
85-
* @var \Drupal\Core\Entity\ContentEntityTypeInterface
85+
* @var \Drupal\Core\Entity\ContentEntityTypeInterface|null
8686
*/
8787
protected $termType;
8888

src/Plugin/LanguageNegotiation/OperationLanguageNegotiation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class OperationLanguageNegotiation extends LanguageNegotiationMethodBase {
3333
/**
3434
* The current execution context.
3535
*
36-
* @var \Drupal\graphql\GraphQL\Execution\ResolveContext
36+
* @var \Drupal\graphql\GraphQL\Execution\ResolveContext|null
3737
*/
3838
protected static $context;
3939

tests/modules/graphql_resolver_builder_test/src/TypedData/Definition/TreeDefinition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class TreeDefinition extends ComplexDataDefinitionBase {
1414
* {@inheritdoc}
1515
*/
1616
public function getPropertyDefinitions() {
17-
if (!isset($this->propertyDefinitions)) {
17+
if (empty($this->propertyDefinitions)) {
1818
$info = &$this->propertyDefinitions;
1919

2020
$info['left'] = self::create('tree')

0 commit comments

Comments
 (0)