Completed
Pull Request — 8.x-3.x (#525)
by Philipp
06:14
created

CacheMetadataCollector::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\graphql\GraphQL\Visitors;
4
5
use Drupal\Core\Cache\RefinableCacheableDependencyInterface;
6
use GraphQL\Validator\Rules\AbstractQuerySecurity;
7
use GraphQL\Validator\ValidationContext;
8
9
class CacheMetadataCollector extends AbstractQuerySecurity {
10
11
  /**
12
   * @var \Drupal\Core\Cache\RefinableCacheableDependencyInterface
13
   */
14
  protected $metadata;
15
16
  /**
17
   * @var array
18
   */
19
  protected $variables;
20
21
  /**
22
   * CacheMetadataCollector constructor.
23
   *
24
   * @param \Drupal\Core\Cache\RefinableCacheableDependencyInterface $metadata
25
   * @param array|null $variables
26
   */
27
  public function __construct(RefinableCacheableDependencyInterface $metadata, array $variables = NULL) {
28
    $this->metadata = $metadata;
29
    $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...
30
  }
31
32
  /**
33
   * {@inheritdoc}
34
   */
35
  protected function isEnabled() {
36
    return TRUE;
37
  }
38
39
  /**
40
   * {@inheritdoc}
41
   */
42
  public function getVisitor(ValidationContext $context) {
43
    // TODO: Implememt this.
44
    return $this->invokeIfNeeded($context, []);
45
  }
46
}