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

Schema::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\graphql\GraphQL\Schema;
4
5
use Drupal\Component\Plugin\ConfigurablePluginInterface;
6
use Drupal\graphql\Plugin\GraphQL\SchemaPluginInterface;
7
use Youshido\GraphQL\Config\Schema\SchemaConfig;
8
use Youshido\GraphQL\Schema\AbstractSchema;
9
10
class Schema extends AbstractSchema {
11
12
  /**
13
   * The corresponding plugin for this schema.
14
   *
15
   * @var \Drupal\graphql\Plugin\GraphQL\SchemaPluginInterface
16
   */
17
  protected $plugin;
18
19
  /**
20
   * Schema constructor.
21
   *
22
   * @param \Drupal\graphql\Plugin\GraphQL\SchemaPluginInterface $plugin
23
   *   The corresponding plugin instance for this schema.
24
   * @param array $config
25
   *   The schema configuration array.
26
   */
27
  public function __construct(SchemaPluginInterface $plugin, array $config = []) {
28
    parent::__construct($config);
29
    $this->plugin = $plugin;
30
  }
31
32
  /**
33
   * Retrieves the schema's plugin instance.
34
   *
35
   * @return \Drupal\graphql\Plugin\GraphQL\SchemaPluginInterface
36
   *   The schema plugin instance.
37
   */
38
  public function getSchemaPlugin() {
39
    if (is_array($this->plugin)) {
40
      /** @var \Drupal\graphql\Plugin\GraphQL\SchemaPluginManager $manager */
41
      $manager = \Drupal::service('plugin.manager.graphql.schema');
42
43
      // Recover the schema plugin reference.
44
      $this->plugin = $manager->createInstance($this->plugin['id'], $this->plugin['configuration']);
45
    }
46
47
    return $this->plugin;
48
  }
49
50
  /**
51
   * {@inheritdoc}
52
   */
53
  public function build(SchemaConfig $config) {
54
    // Nothing to do here.
55
  }
56
57
  /**
58
   * {@inheritdoc}
59
   */
60 View Code Duplication
  public function __sleep() {
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...
61
    // Instead of serializing the referenced plugin, we just serialize the
62
    // plugin id and configuration.
63
    $this->plugin = [
0 ignored issues
show
Documentation Bug introduced by
It seems like array('id' => $this->plu...figuration() : array()) of type array<string,?,{"id":"?","configuration":"?"}> is incompatible with the declared type object<Drupal\graphql\Pl...\SchemaPluginInterface> of property $plugin.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
64
      'id' => $this->plugin->getPluginId(),
65
      'configuration' => $this->plugin instanceof ConfigurablePluginInterface ? $this->plugin->getConfiguration() : [],
0 ignored issues
show
Bug introduced by
The class Drupal\Component\Plugin\...igurablePluginInterface 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...
66
    ];
67
68
    return array_keys(get_object_vars($this));
69
  }
70
71
}
72