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

FieldPluginManager::getInstance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 7
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\graphql\Plugin;
4
5
use Drupal\Core\Cache\CacheBackendInterface;
6
use Drupal\Core\Extension\ModuleHandlerInterface;
7
use Drupal\Core\Plugin\DefaultPluginManager;
8
9 View Code Duplication
class FieldPluginManager extends DefaultPluginManager {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
11
  /**
12
   * Static cache of plugin instances.
13
   *
14
   * @var \Drupal\graphql\Plugin\FieldPluginInterface[]
15
   */
16
  protected $instances;
17
18
  /**
19
   * FieldPluginManager constructor.
20
   *
21
   * @param bool|string $pluginSubdirectory
22
   *   The plugin's subdirectory.
23
   * @param \Traversable $namespaces
24
   *   An object that implements \Traversable which contains the root paths
25
   *   keyed by the corresponding namespace to look for plugin implementations.
26
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
27
   *   The module handler.
28
   * @param \Drupal\Core\Cache\CacheBackendInterface $cacheBackend
29
   *   The cache backend.
30
   * @param string|null $pluginInterface
31
   *   The interface each plugin should implement.
32
   * @param string $pluginAnnotationName
33
   *   The name of the annotation that contains the plugin definition.
34
   */
35
  public function __construct(
36
    $pluginSubdirectory,
37
    \Traversable $namespaces,
38
    ModuleHandlerInterface $moduleHandler,
39
    CacheBackendInterface $cacheBackend,
40
    $pluginInterface,
41
    $pluginAnnotationName
42
  ) {
43
    parent::__construct(
44
      $pluginSubdirectory,
45
      $namespaces,
46
      $moduleHandler,
47
      $pluginInterface,
48
      $pluginAnnotationName
49
    );
50
51
    $this->alterInfo('graphql_fields');
52
    $this->useCaches(TRUE);
53
    $this->setCacheBackend($cacheBackend, 'fields', ['graphql', 'graphql:fields']);
54
  }
55
56
  /**
57
   * {@inheritdoc}
58
   */
59
  public function getInstance(array $options) {
60
    if (!isset($this->instances[$options['id']])) {
61
      $this->instances[$options['id']] = $this->createInstance($options['id']);
62
    }
63
64
    return $this->instances[$options['id']];
65
  }
66
67
}
68