getDerivativeDefinitionsFromFieldDefinition()   A
last analyzed

Complexity

Conditions 6
Paths 3

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 14
c 2
b 0
f 0
dl 0
loc 21
rs 9.2222
cc 6
nc 3
nop 2
1
<?php
2
3
namespace Drupal\graphql_core\Plugin\Deriver\Fields;
4
5
use Drupal\Core\Field\FieldDefinitionInterface;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\Field\FieldDefinitionInterface 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\graphql\Utility\StringHelper;
7
use Drupal\graphql_core\Plugin\Deriver\EntityFieldDeriverBase;
8
9
class EntityFieldPropertyDeriver extends EntityFieldDeriverBase {
10
11
  /**
12
   * {@inheritdoc}
13
   */
14
  protected function getDerivativeDefinitionsFromFieldDefinition(FieldDefinitionInterface $fieldDefinition, array $basePluginDefinition) {
15
    $fieldType = $fieldDefinition->getType();
16
17
    if (isset($basePluginDefinition['field_types']) && in_array($fieldType, $basePluginDefinition['field_types'])) {
18
      $fieldName = $fieldDefinition->getName();
19
      $fieldBundle = $fieldDefinition->getTargetBundle() ?: '';
20
      $entityTypeId = $fieldDefinition->getTargetEntityTypeId();
21
      $entityType = $this->entityTypeManager->getDefinition($entityTypeId);
22
      $supportsBundles = $entityType->hasKey('bundle');
23
24
      if (!isset($basePluginDefinition['parents'])) {
25
        $basePluginDefinition['parents'] = [];
26
      }
27
28
      $parents = [StringHelper::camelCase('field', $entityTypeId, $supportsBundles ? $fieldBundle : '', $fieldName)];
29
      return ["$entityTypeId-$fieldBundle-$fieldName" => [
30
        'parents' => array_merge($parents, $basePluginDefinition['parents']),
31
      ] + $basePluginDefinition];
32
    }
33
34
    return [];
35
  }
36
}
37