Completed
Pull Request — 8.x-3.x (#525)
by Sebastian
07:04 queued 01:59
created

CacheMetadataCollector   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isEnabled() 0 3 1
A getVisitor() 0 4 1
1
<?php
2
3
namespace Drupal\graphql\GraphQL\Visitors;
4
5
use Drupal\Core\Cache\RefinableCacheableDependencyInterface;
6
use GraphQL\Language\AST\NodeKind;
7
use GraphQL\Language\AST\SelectionSetNode;
8
use GraphQL\Language\Visitor;
9
use GraphQL\Validator\Rules\AbstractQuerySecurity;
10
use GraphQL\Validator\ValidationContext;
11
12
class CacheMetadataCollector extends AbstractQuerySecurity {
13
14
  /**
15
   * @var \Drupal\Core\Cache\RefinableCacheableDependencyInterface
16
   */
17
  protected $metadata;
18
19
  /**
20
   * @var array
21
   */
22
  protected $variables;
23
24
  /**
25
   * CacheMetadataCollector constructor.
26
   *
27
   * @param \Drupal\Core\Cache\RefinableCacheableDependencyInterface $metadata
28
   * @param array|null $variables
29
   */
30
  public function __construct(RefinableCacheableDependencyInterface $metadata, array $variables = NULL) {
31
    $this->metadata = $metadata;
32
    $this->variables = $variables;
0 ignored issues
show
Documentation Bug introduced by
It seems like $variables can be null. However, the property $variables is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
33
  }
34
35
  /**
36
   * {@inheritdoc}
37
   */
38
  protected function isEnabled() {
39
    return TRUE;
40
  }
41
42
  /**
43
   * {@inheritdoc}
44
   */
45
  public function getVisitor(ValidationContext $context) {
46
    // TODO: Implement cache metadata collection.
47
    return $this->invokeIfNeeded($context, []);
48
  }
49
}