Completed
Pull Request — 8.x-3.x (#519)
by Sebastian
04:48 queued 02:15
created

CacheMetadataVisitor   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A visit() 0 8 2
A reduce() 0 8 2
A initial() 0 3 1
1
<?php
2
3
namespace Drupal\graphql\GraphQL\Execution\Visitor;
4
5
use Drupal\Core\Cache\CacheableDependencyInterface;
6
use Drupal\Core\Cache\CacheableMetadata;
7
use Drupal\graphql\GraphQL\CacheableEdgeInterface;
8
use Youshido\GraphQL\Field\FieldInterface;
9
10
class CacheMetadataVisitor implements VisitorInterface {
11
12
  /**
13
   * {@inheritdoc}
14
   */
15
  public function visit(array $args, FieldInterface $field, $child) {
16
    if ($field instanceof CacheableEdgeInterface) {
17
      $metadata = new CacheableMetadata();
18
      $metadata->addCacheableDependency($field->getResponseCacheMetadata());
19
      $metadata->addCacheableDependency($field->getSchemaCacheMetadata());
20
      return $metadata;
21
    }
22
  }
23
24
  /**
25
   * {@inheritdoc}
26
   */
27
  public function reduce($carry, $current) {
28
    /** @var \Drupal\Core\Cache\RefinableCacheableDependencyInterface $carry */
29
    if ($current instanceof CacheableDependencyInterface) {
0 ignored issues
show
Bug introduced by
The class Drupal\Core\Cache\CacheableDependencyInterface does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
30
      $carry->addCacheableDependency($current);
31
    }
32
33
    return $carry;
34
  }
35
36
  /**
37
   * {@inheritdoc}
38
   */
39
  public function initial() {
40
    return new CacheableMetadata();
41
  }
42
43
}