Issues (645)

src/Plugin/SchemaPluginManager.php (5 issues)

1
<?php
2
3
namespace Drupal\graphql\Plugin;
4
5
use Drupal\Core\Cache\Cache;
0 ignored issues
show
The type Drupal\Core\Cache\Cache 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\Cache\CacheBackendInterface;
0 ignored issues
show
The type Drupal\Core\Cache\CacheBackendInterface 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
use Drupal\Core\Extension\ModuleHandlerInterface;
0 ignored issues
show
The type Drupal\Core\Extension\ModuleHandlerInterface 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...
8
use Drupal\Core\Plugin\DefaultPluginManager;
0 ignored issues
show
The type Drupal\Core\Plugin\DefaultPluginManager 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...
9
10
class SchemaPluginManager extends DefaultPluginManager {
11
12
  /**
13
   * SchemaPluginManager constructor.
14
   *
15
   * @param bool|string $pluginSubdirectory
16
   *   The plugin's subdirectory.
17
   * @param \Traversable $namespaces
18
   *   An object that implements \Traversable which contains the root paths
19
   *   keyed by the corresponding namespace to look for plugin implementations.
20
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
21
   *   The module handler.
22
   * @param \Drupal\Core\Cache\CacheBackendInterface $cacheBackend
23
   *   The cache backend.
24
   * @param string|null $pluginInterface
25
   *   The interface each plugin should implement.
26
   * @param string $pluginAnnotationName
27
   *   The name of the annotation that contains the plugin definition.
28
   * @param array $config
29
   *   The configuration service parameter.
30
   */
31
  public function __construct(
32
    $pluginSubdirectory,
33
    \Traversable $namespaces,
34
    ModuleHandlerInterface $moduleHandler,
35
    CacheBackendInterface $cacheBackend,
36
    $pluginInterface,
37
    $pluginAnnotationName,
38
    array $config
39
  ) {
40
    parent::__construct(
41
      $pluginSubdirectory,
42
      $namespaces,
43
      $moduleHandler,
44
      $pluginInterface,
45
      $pluginAnnotationName
46
    );
47
48
    $this->alterInfo('graphql_schema');
49
    $this->useCaches(empty($config['development']));
50
    $this->setCacheBackend($cacheBackend, 'schemas', ['graphql']);
51
  }
52
53
  /**
54
   * {@inheritdoc}
55
   */
56
  protected function setCachedDefinitions($definitions) {
57
    $this->definitions = $definitions;
0 ignored issues
show
Bug Best Practice introduced by
The property definitions does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
58
    $this->cacheSet($this->cacheKey, $definitions, $this->getCacheMaxAge(), $this->getCacheTags());
59
  }
60
61
  /**
62
   * {@inheritdoc}
63
   */
64
  public function getCacheTags() {
65
    $definitions = $this->getDefinitions();
66
    return array_reduce($definitions, function ($carry, $current) {
67
      if (!empty($current['schema_cache_tags'])) {
68
        return Cache::mergeTags($carry, $current['schema_cache_tags']);
69
      }
70
71
      return $carry;
72
    }, $this->cacheTags);
73
  }
74
75
  /**
76
   * {@inheritdoc}
77
   */
78
  public function getCacheMaxAge() {
79
    $definitions = $this->getDefinitions();
80
    $age = Cache::PERMANENT;
81
    foreach ($definitions as $definition) {
82
      if (!isset($definition['schema_cache_max_age'])) {
83
        continue;
84
      }
85
86
      // Bail out early if the cache max age is 0.
87
      if (($age = Cache::mergeMaxAges($age, $definition['schema_cache_max_age'])) === 0) {
88
        return $age;
89
      }
90
    }
91
92
    return $age;
93
  }
94
}
95