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

FieldablePluginTrait::buildFields()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 11
nc 3
nop 1
dl 0
loc 17
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\graphql\Plugin\GraphQL\Traits;
4
5
use Drupal\Component\Plugin\PluginInspectionInterface;
6
use Drupal\graphql\Plugin\GraphQL\PluggableSchemaBuilderInterface;
7
use Drupal\graphql\Plugin\GraphQL\TypeSystemPluginInterface;
8
use Youshido\GraphQL\Field\FieldInterface;
9
10
/**
11
 * Methods for fieldable graphql plugins.
12
 */
13
trait FieldablePluginTrait {
14
15
  /**
16
   * Build the list of implicit and explicit fields attached to the object type.
17
   *
18
   * @param \Drupal\graphql\Plugin\GraphQL\PluggableSchemaBuilderInterface $schemaBuilder
19
   *   Instance of the schema manager to resolve dependencies.
20
   *
21
   * @return \Youshido\GraphQL\Field\FieldInterface[]
22
   *   The type object.
23
   */
24
  protected function buildFields(PluggableSchemaBuilderInterface $schemaBuilder) {
25
    if ($this instanceof PluginInspectionInterface) {
0 ignored issues
show
Bug introduced by
The class Drupal\Component\Plugin\PluginInspectionInterface 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...
26
      $definition = $this->getPluginDefinition();
27
28
      if ($definition['name']) {
29
        $types = array_merge([$definition['name']], array_key_exists('interfaces', $definition) ? $definition['interfaces'] : []);
30
31
        return array_map(function (TypeSystemPluginInterface $field) use ($schemaBuilder) {
32
          return $field->getDefinition($schemaBuilder);
33
        }, $schemaBuilder->find(function ($field) use ($types) {
34
          return array_intersect($types, $field['parents']);
35
        }, [GRAPHQL_FIELD_PLUGIN]));
36
      }
37
    }
38
39
    return [];
40
  }
41
42
}
43