EntityQueryDeriver   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 20
c 0
b 0
f 0
dl 0
loc 65
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A create() 0 4 1
A getDerivativeDefinitions() 0 19 4
1
<?php
2
3
namespace Drupal\graphql_core\Plugin\Deriver\Fields;
4
5
use Drupal\Component\Plugin\Derivative\DeriverBase;
0 ignored issues
show
Bug introduced by
The type Drupal\Component\Plugin\Derivative\DeriverBase 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\Entity\ContentEntityTypeInterface;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\Entity\ContentEntityTypeInterface 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\Entity\EntityTypeManagerInterface;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\Entity\EntityTypeManagerInterface 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\Discovery\ContainerDeriverInterface;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\Plugin\Disco...ntainerDeriverInterface 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
use Drupal\Core\StringTranslation\StringTranslationTrait;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\StringTransl...\StringTranslationTrait 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...
10
use Drupal\Core\TypedData\TypedDataManager;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\TypedData\TypedDataManager 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...
11
use Drupal\graphql\Utility\StringHelper;
12
use Symfony\Component\DependencyInjection\ContainerInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Depend...tion\ContainerInterface 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...
13
14
class EntityQueryDeriver extends DeriverBase implements ContainerDeriverInterface {
15
  use StringTranslationTrait;
16
17
  /**
18
   * The entity type manager service.
19
   *
20
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
21
   */
22
  protected $entityTypeManager;
23
24
  /**
25
   * The typed data manager service.
26
   *
27
   * @var \Drupal\Core\TypedData\TypedDataManager
28
   */
29
  protected $typedDataManager;
30
31
  /**
32
   * {@inheritdoc}
33
   */
34
  public static function create(ContainerInterface $container, $basePluginId) {
35
    return new static(
36
      $container->get('entity_type.manager'),
37
      $container->get('typed_data_manager')
38
    );
39
  }
40
41
  /**
42
   * EntityQueryDeriver constructor.
43
   *
44
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
45
   *   The entity type manager service.
46
   * @param \Drupal\Core\TypedData\TypedDataManager $typedDataManager
47
   *   The typed data manager service.
48
   */
49
  public function __construct(
50
    EntityTypeManagerInterface $entityTypeManager,
51
    TypedDataManager $typedDataManager
52
  ) {
53
    $this->entityTypeManager = $entityTypeManager;
54
    $this->typedDataManager = $typedDataManager;
55
  }
56
57
  /**
58
   * {@inheritdoc}
59
   */
60
  public function getDerivativeDefinitions($basePluginDefinition) {
61
    foreach ($this->entityTypeManager->getDefinitions() as $id => $type) {
62
      if ($type instanceof ContentEntityTypeInterface) {
63
        $derivative = [
64
          'name' => StringHelper::propCase($id, 'query'),
65
          'description' => $this->t("Loads '@type' entities.", ['@type' => $type->getLabel()]),
66
          'entity_type' => $id,
67
        ] + $basePluginDefinition;
68
69
        if ($id === 'node') {
70
          // TODO: Make this more generic.
71
          $derivative['response_cache_contexts'][] = 'user.node_grants:view';
72
        }
73
74
        $this->derivatives[$id] = $derivative;
0 ignored issues
show
Bug Best Practice introduced by
The property derivatives does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
75
      }
76
    }
77
78
    return parent::getDerivativeDefinitions($basePluginDefinition);
79
  }
80
81
}
82