ContextRepository::addContextProvider()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 2
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Drupal\graphql\GraphQL\Context;
4
5
use Drupal\Core\Plugin\Context\ContextProviderInterface;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\Plugin\Conte...ontextProviderInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Drupal\Core\Plugin\Context\ContextRepositoryInterface;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\Plugin\Conte...textRepositoryInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
8
/**
9
 * Non-lazy un-optimized context repository.
10
 *
11
 * Intermediate solution for graphql requests that change context within one
12
 * request and would confuse the LazyContextBuilder.
13
 */
14
class ContextRepository implements ContextRepositoryInterface {
15
16
  /**
17
   * The list of content providers.
18
   *
19
   * @var \Drupal\Core\Plugin\Context\ContextProviderInterface[]
20
   */
21
  protected $contextProviders = [];
22
23
  /**
24
   * Add a context provider.
25
   *
26
   * @param \Drupal\Core\Plugin\Context\ContextProviderInterface $contextProvider
27
   *   The context provider to add.
28
   */
29
  public function addContextProvider(ContextProviderInterface $contextProvider) {
30
    $this->contextProviders[] = $contextProvider;
31
  }
32
33
  /**
34
   * {@inheritdoc}
35
   */
36
  public function getRuntimeContexts(array $contextIds) {
37
    $contexts = [];
38
    foreach ($this->contextProviders as $contextProvider) {
39
      foreach ($contextProvider->getRuntimeContexts($contextIds) as $id => $context) {
40
        $contexts[$id] = $context;
41
      }
42
    }
43
    return $contexts;
44
  }
45
46
  /**
47
   * {@inheritdoc}
48
   */
49
  public function getAvailableContexts() {
50
    $contexts = [];
51
    foreach ($this->contextProviders as $contextProvider) {
52
      foreach ($contextProvider->getAvailableContexts() as $id => $context) {
53
        $contexts[$id] = $context;
54
      }
55
    }
56
    return $contexts;
57
  }
58
59
}
60