Skip to content

Commit 0b9d489

Browse files
authored
tests(phpcs): Fix unused variables reported by PHPCS (#1077)
1 parent 7eff2aa commit 0b9d489

7 files changed

Lines changed: 11 additions & 25 deletions

File tree

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,17 @@ install:
8989
# require also triggers a full 'composer install'.
9090
- composer --no-interaction --working-dir=$DRUPAL_BUILD_DIR require webonyx/graphql-php:^0.13.1 drupal/typed_data:^1.0
9191
- composer --no-interaction --working-dir=$DRUPAL_BUILD_DIR run-script drupal-phpunit-upgrade
92-
92+
9393
# Install PHPCS to check for Drupal coding standards.
94-
- travis_retry composer global require drupal/coder
94+
- travis_retry composer global require drupal/coder:8.3.9
9595
- $HOME/.composer/vendor/bin/phpcs --config-set installed_paths $HOME/.composer/vendor/drupal/coder/coder_sniffer
9696

9797
script:
9898
# Run the unit tests using phpdbg if the environment variable is 'true'.
9999
- if [[ "$WITH_PHPDBG_COVERAGE" == "true" ]];
100100
then phpdbg -qrr $DRUPAL_BUILD_DIR/vendor/bin/phpunit --configuration $DRUPAL_BUILD_DIR/core/phpunit.xml --coverage-clover $TRAVIS_BUILD_DIR/coverage.xml $TRAVIS_BUILD_DIR;
101101
fi
102-
102+
103103
# Check for coding standards violations.
104104
- cd $DRUPAL_BUILD_DIR/modules/graphql && $HOME/.composer/vendor/bin/phpcs
105105

phpcs.xml.dist

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,6 @@
88
<rule ref="Drupal"></rule>
99
<rule ref="DrupalPractice"></rule>
1010

11-
<!-- TODO: check if we can fix those reported errors in code-->
12-
<rule ref="DrupalPractice.CodeAnalysis.VariableAnalysis.UnusedVariable">
13-
<exclude-pattern>src/Plugin/GraphQL/DataProducer/DataProducerProxy.php</exclude-pattern>
14-
<exclude-pattern>src/Plugin/GraphQL/DataProducer/Field/EntityReference.php</exclude-pattern>
15-
<exclude-pattern>src/Plugin/GraphQL/DataProducer/Routing/RouteEntity.php</exclude-pattern>
16-
<exclude-pattern>src/Plugin/GraphQL/DataProducer/Entity/EntityLoadMultiple.php</exclude-pattern>
17-
<exclude-pattern>src/Plugin/GraphQL/DataProducer/Entity/EntityLoad.php</exclude-pattern>
18-
<exclude-pattern>tests/src/Kernel/DataProducer/MenuTest.php</exclude-pattern>
19-
</rule>
20-
21-
<rule ref="DrupalPractice.CodeAnalysis.VariableAnalysis.UndefinedVariable">
22-
<exclude-pattern>src/Plugin/GraphQL/DataProducer/Field/EntityReference.php</exclude-pattern>
23-
</rule>
24-
2511
<!-- TODO: those rules are disabled for now until we fix the coding standards for them. -->
2612
<rule ref="Drupal.Commenting.ClassComment.Missing">
2713
<exclude-pattern>src/PermissionProvider.php</exclude-pattern>

src/Plugin/GraphQL/DataProducer/DataProducerProxy.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function resolve($value, $args, ResolveContext $context, ResolveInfo $inf
149149
$plugin = $this->prepare($value, $args, $context, $info, $field);
150150

151151
return DeferredUtility::returnFinally($plugin, function (DataProducerPluginInterface $plugin) use ($context, $field) {
152-
foreach ($plugin->getContexts() as $id => $item) {
152+
foreach ($plugin->getContexts() as $item) {
153153
/** @var \Drupal\Core\Plugin\Context\Context $item */
154154
if ($item->getContextDefinition()->isRequired() && !$item->hasContextValue()) {
155155
return NULL;
@@ -198,7 +198,7 @@ protected function prepare($value, $args, ResolveContext $context, ResolveInfo $
198198
}
199199

200200
$values = DeferredUtility::waitAll($values);
201-
return DeferredUtility::returnFinally($values, function ($values) use ($contexts, $plugin) {
201+
return DeferredUtility::returnFinally($values, function ($values) use ($plugin) {
202202
foreach ($values as $name => $value) {
203203
$plugin->setContextValue($name, $value);
204204
}
@@ -216,7 +216,7 @@ protected function prepare($value, $args, ResolveContext $context, ResolveInfo $
216216
*/
217217
protected function resolveUncached(DataProducerPluginInterface $plugin, ResolveContext $context, FieldContext $field) {
218218
$output = $plugin->resolveField($field);
219-
return DeferredUtility::applyFinally($output, function () use ($context, $plugin, $field) {
219+
return DeferredUtility::applyFinally($output, function () use ($plugin, $field) {
220220
$field->addCacheableDependency($plugin);
221221
});
222222
}
@@ -237,7 +237,7 @@ protected function resolveCached(DataProducerPluginCachingInterface $plugin, Res
237237
}
238238

239239
$output = $this->resolveUncached($plugin, $context, $field);
240-
return DeferredUtility::applyFinally($output, function ($value) use ($context, $field, $prefix) {
240+
return DeferredUtility::applyFinally($output, function ($value) use ($field, $prefix) {
241241
$this->cacheWrite($prefix, $value, $field);
242242
});
243243
}

src/Plugin/GraphQL/DataProducer/Entity/EntityLoad.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function __construct(
142142
public function resolve($type, $id, $language, ?array $bundles, ?bool $access, ?AccountInterface $accessUser, ?string $accessOperation, FieldContext $context) {
143143
$resolver = $this->entityBuffer->add($type, $id);
144144

145-
return new Deferred(function () use ($type, $id, $language, $bundles, $resolver, $context, $access, $accessUser, $accessOperation) {
145+
return new Deferred(function () use ($type, $language, $bundles, $resolver, $context, $access, $accessUser, $accessOperation) {
146146
if (!$entity = $resolver()) {
147147
// If there is no entity with this id, add the list cache tags so that
148148
// the cache entry is purged whenever a new entity of this type is

src/Plugin/GraphQL/DataProducer/Entity/EntityLoadMultiple.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function __construct(
142142
public function resolve($type, array $ids, $language, ?array $bundles, bool $access, ?AccountInterface $accessUser, string $accessOperation, FieldContext $context) {
143143
$resolver = $this->entityBuffer->add($type, $ids);
144144

145-
return new Deferred(function () use ($type, $ids, $language, $bundles, $resolver, $context, $access, $accessUser, $accessOperation) {
145+
return new Deferred(function () use ($type, $language, $bundles, $resolver, $context, $access, $accessUser, $accessOperation) {
146146
/** @var \Drupal\Core\Entity\EntityInterface[] $entities */
147147
if (!$entities = $resolver()) {
148148
// If there is no entity with this id, add the list cache tags so that

src/Plugin/GraphQL/DataProducer/Field/EntityReference.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function resolve(EntityInterface $entity, $field, $language, ?array $bund
156156
$resolver = $this->entityBuffer->add($type, $ids);
157157
return new Deferred(function () use ($type, $language, $bundles, $access, $accessUser, $accessOperation, $resolver, $context) {
158158
$entities = $resolver() ?: [];
159-
$entities = array_filter($entities, function (EntityInterface $entity) use ($bundles, $access, $accessOperation, $accessUser, $context) {
159+
$entities = array_filter($entities, function (EntityInterface $entity) use ($language, $bundles, $access, $accessOperation, $accessUser, $context) {
160160
if (isset($bundles) && !in_array($entity->bundle(), $bundles)) {
161161
return FALSE;
162162
}

src/Plugin/GraphQL/DataProducer/Routing/RouteEntity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function resolve($url, $language, FieldContext $context) {
103103
$id = $parameters[$type];
104104
$resolver = $this->entityBuffer->add($type, $id);
105105

106-
return new Deferred(function () use ($type, $id, $resolver, $context, $language) {
106+
return new Deferred(function () use ($type, $resolver, $context, $language) {
107107
if (!$entity = $resolver()) {
108108
// If there is no entity with this id, add the list cache tags so that
109109
// the cache entry is purged whenever a new entity of this type is

0 commit comments

Comments
 (0)