Completed
Pull Request — 8.x-3.x (#494)
by Philipp
02:39
created

QueryResult   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 102
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getData() 0 3 1
A getCacheContexts() 0 3 1
A getCacheTags() 0 3 1
A getCacheMaxAge() 0 3 1
A getResponseMetadata() 0 3 1
A getSchemaResponseMetadata() 0 3 1
1
<?php
2
3
namespace Drupal\graphql\GraphQL\Execution;
4
5
use Drupal\Core\Cache\CacheableDependencyInterface;
6
use Drupal\Core\Cache\CacheableMetadata;
7
8
class QueryResult implements CacheableDependencyInterface {
9
10
  /**
11
   * The query result.
12
   *
13
   * @var mixed
14
   */
15
  protected $data;
16
17
  /**
18
   * Merged cache metadata from the response and the schema.
19
   *
20
   * @var \Drupal\Core\Cache\CacheableDependencyInterface
21
   */
22
  protected $metadata;
23
24
  /**
25
   * Cache metadata collected during query execution.
26
   *
27
   * @var \Drupal\Core\Cache\CacheableDependencyInterface
28
   */
29
  protected $responseMetadata;
30
31
  /**
32
   * Static response cache metadata from the schema.
33
   *
34
   * @var \Drupal\Core\Cache\CacheableDependencyInterface
35
   */
36
  protected $schemaResponseMetadata;
37
38
  /**
39
   * QueryResult constructor.
40
   *
41
   * @param $data
42
   *   Result data.
43
   * @param \Drupal\Core\Cache\CacheableDependencyInterface $responseMetadata
44
   *   The cache metadata collected during query execution.
45
   * @param \Drupal\Core\Cache\CacheableDependencyInterface $schemaResponseMetadata
46
   *   The schema's response cache metadata.
47
   */
48
  public function __construct($data, CacheableDependencyInterface $responseMetadata, CacheableDependencyInterface $schemaResponseMetadata) {
49
    $this->data = $data;
50
    $this->responseMetadata = $responseMetadata;
51
    $this->schemaResponseMetadata = $schemaResponseMetadata;
52
53
    $this->metadata = new CacheableMetadata();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Drupal\Core\Cache\CacheableMetadata() of type object<Drupal\Core\Cache\CacheableMetadata> is incompatible with the declared type object<Drupal\Core\Cache...bleDependencyInterface> of property $metadata.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

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

Loading history...
54
    $this->metadata->addCacheableDependency($responseMetadata);
55
    $this->metadata->addCacheableDependency($schemaResponseMetadata);
56
  }
57
58
  /**
59
   * Retrieve query result data.
60
   *
61
   * @return mixed
62
   *   The result data object.
63
   */
64
  public function getData() {
65
    return $this->data;
66
  }
67
68
  /**
69
   * {@inheritdoc}
70
   */
71
  public function getCacheContexts() {
72
    return $this->metadata->getCacheContexts();
73
  }
74
75
  /**
76
   * {@inheritdoc}
77
   */
78
  public function getCacheTags() {
79
    return $this->metadata->getCacheTags();
80
  }
81
82
  /**
83
   * {@inheritdoc}
84
   */
85
  public function getCacheMaxAge() {
86
    return $this->metadata->getCacheMaxAge();
87
  }
88
89
  /**
90
   * Gets the response cache metadata.
91
   *
92
   * @return \Drupal\Core\Cache\CacheableDependencyInterface
93
   *   The response cache metadata.
94
   */
95
  public function getResponseMetadata() {
96
    return $this->responseMetadata;
97
  }
98
99
  /**
100
   * Gets the schema's response cache metadata.
101
   *
102
   * @return \Drupal\Core\Cache\CacheableDependencyInterface
103
   *   The schema's response cache metadata.
104
   */
105
  public function getSchemaResponseMetadata() {
106
    return $this->schemaResponseMetadata;
107
  }
108
109
}