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

FieldPluginManager   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 59
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 59
loc 59
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 20 20 1
A getInstance() 7 7 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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