Completed
Push — 8.x-3.x ( 58ea89...9f5f1b )
by Sebastian
02:22
created

DeleteEntityDeriver::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 5
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 5
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\graphql_mutation\Plugin\Deriver\Mutations;
4
5
use Drupal\Component\Plugin\Derivative\DeriverBase;
6
use Drupal\Core\Entity\ContentEntityTypeInterface;
7
use Drupal\Core\Entity\EntityTypeManagerInterface;
8
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
9
use Drupal\graphql\Utility\StringHelper;
10
use Drupal\graphql_content_mutation\ContentEntityMutationSchemaConfig;
11
use Symfony\Component\DependencyInjection\ContainerInterface;
12
13 View Code Duplication
class DeleteEntityDeriver extends DeriverBase implements ContainerDeriverInterface {
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...
14
  /**
15
   * The entity type manager service.
16
   *
17
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
18
   */
19
  protected $entityTypeManager;
20
21
  /**
22
   * {@inheritdoc}
23
   */
24
  public static function create(ContainerInterface $container, $basePluginId) {
25
    return new static(
26
      $container->get('entity_type.manager')
27
    );
28
  }
29
30
  /**
31
   * {@inheritdoc}
32
   */
33
  public function __construct(
34
    EntityTypeManagerInterface $entityTypeManager
35
  ) {
36
    $this->entityTypeManager = $entityTypeManager;
37
  }
38
  /**
39
   * {@inheritdoc}
40
   */
41
  public function getDerivativeDefinitions($basePluginDefinition) {
42
    foreach ($this->entityTypeManager->getDefinitions() as $entityTypeId => $type) {
43
44
      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...
45
        continue;
46
      }
47
48
      $this->derivatives[$entityTypeId] = [
49
        'name' => 'delete' . StringHelper::camelCase($entityTypeId),
50
        'entity_type' => $entityTypeId,
51
      ] + $basePluginDefinition;
52
    }
53
54
    return parent::getDerivativeDefinitions($basePluginDefinition);
55
  }
56
57
}
58