Completed
Pull Request — 8.x-3.x (#497)
by Sebastian
07:46
created

EntityField::resolveValues()   C

Complexity

Conditions 7
Paths 6

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 12
nc 6
nop 3
dl 0
loc 22
rs 6.9811
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\graphql_core\Plugin\GraphQL\Fields\Entity;
4
5
use Drupal\Core\Entity\FieldableEntityInterface;
6
use Drupal\graphql\GraphQL\Cache\CacheableValue;
7
use Drupal\graphql_core\Plugin\GraphQL\Fields\EntityFieldBase;
8
use Youshido\GraphQL\Execution\ResolveInfo;
9
10
/**
11
 * Generic field plugin for rendering entity fields.
12
 *
13
 * @GraphQLField(
14
 *   id = "entity_field",
15
 *   secure = true,
16
 *   weight = -2,
17
 *   deriver = "Drupal\graphql_core\Plugin\Deriver\Fields\EntityFieldDeriver",
18
 * )
19
 */
20
class EntityField extends EntityFieldBase {
0 ignored issues
show
Bug introduced by
There is one abstract method getPluginDefinition in this class; you could implement it, or declare this class as abstract.
Loading history...
21
22
  /**
23
   * {@inheritdoc}
24
   */
25
  public function resolveValues($value, array $args, ResolveInfo $info) {
26
    if ($value instanceof FieldableEntityInterface) {
0 ignored issues
show
Bug introduced by
The class Drupal\Core\Entity\FieldableEntityInterface 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...
27
      $fieldName = $this->getPluginDefinition()['field'];
28
      if ($value->hasField($fieldName)) {
29
        /** @var \Drupal\Core\Field\FieldItemListInterface $items */
30
        $items = $value->get($fieldName);
31
32
        if (($access = $items->access('view', NULL, TRUE)) && $access->isAllowed()) {
33
          $this->commitCacheableDependency($info, $access);
34
35
          foreach ($items as $item) {
36
            if (!empty($this->getPluginDefinition()['property'])) {
37
              yield $this->resolveItem($item, $args, $info);
38
            }
39
            else {
40
              yield $item;
41
            }
42
          }
43
        }
44
      }
45
    }
46
  }
47
48
}
49