Completed
Pull Request — 8.x-3.x (#505)
by Sebastian
02:59
created

EntityQueryDeriver::getDerivativeDefinitions()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 10

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 3
nop 1
dl 15
loc 15
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\graphql_core\Plugin\Deriver\Fields;
4
5
use Drupal\Component\Plugin\Derivative\DeriverBase;
6
use Drupal\Core\Entity\ContentEntityTypeInterface;
7
use Drupal\Core\Entity\EntityTypeManagerInterface;
8
use Drupal\Core\Field\BaseFieldDefinition;
9
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
10
use Drupal\Core\StringTranslation\StringTranslationTrait;
11
use Drupal\Core\TypedData\TypedDataManager;
12
use Drupal\graphql\Utility\StringHelper;
13
use Symfony\Component\DependencyInjection\ContainerInterface;
14
15
class EntityQueryDeriver extends DeriverBase implements ContainerDeriverInterface {
16
  use StringTranslationTrait;
17
18
  /**
19
   * The entity type manager service.
20
   *
21
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
22
   */
23
  protected $entityTypeManager;
24
25
  /**
26
   * The typed data manager service.
27
   *
28
   * @var \Drupal\Core\TypedData\TypedDataManager
29
   */
30
  protected $typedDataManager;
31
32
  /**
33
   * {@inheritdoc}
34
   */
35
  public static function create(ContainerInterface $container, $basePluginId) {
36
    return new static(
37
      $container->get('entity_type.manager'),
38
      $container->get('typed_data_manager')
39
    );
40
  }
41
42
  /**
43
   * {@inheritdoc}
44
   */
45
  public function __construct(
46
    EntityTypeManagerInterface $entityTypeManager,
47
    TypedDataManager $typedDataManager
48
  ) {
49
    $this->entityTypeManager = $entityTypeManager;
50
    $this->typedDataManager = $typedDataManager;
51
  }
52
53
  /**
54
   * {@inheritdoc}
55
   */
56 View Code Duplication
  public function getDerivativeDefinitions($basePluginDefinition) {
0 ignored issues
show
Duplication introduced by
This method 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...
57
    foreach ($this->entityTypeManager->getDefinitions() as $id => $type) {
58
      if ($type instanceof ContentEntityTypeInterface) {
0 ignored issues
show
Bug introduced by
The class Drupal\Core\Entity\ContentEntityTypeInterface does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
59
        $derivative = [
60
          'name' => StringHelper::propCase($id, 'query'),
61
          'description' => $this->t("Loads '@type' entities.", ['@type' => $type->getLabel()]),
62
          'entity_type' => $id,
63
        ] + $basePluginDefinition;
64
65
        $this->derivatives[$id] = $derivative;
66
      }
67
    }
68
69
    return parent::getDerivativeDefinitions($basePluginDefinition);
70
  }
71
72
}
73