Completed
Pull Request — 8.x-3.x (#519)
by Sebastian
03:53
created

ComplexityAwarePluginTrait::buildCost()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 8
nc 5
nop 0
dl 0
loc 16
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\GraphQL\ComplexFieldInterface;
7
8
trait ComplexityAwarePluginTrait {
9
10
  /**
11
   * {@inheritdoc}
12
   */
13
  abstract public function getPluginDefinition();
14
15
  /**
16
   * Build the field's cost for static query complexity analysis.
17
   *
18
   * @return int|callable
19
   *   The cost of this field or a callable to calculate the cost at runtime.
20
   */
21
  protected function buildCost() {
22
    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...
23
      $definition = $this->getPluginDefinition();
24
      if (isset($definition['cost'])) {
25
        return $definition['cost'];
26
      }
27
    }
28
29
    if ($this instanceof ComplexFieldInterface) {
30
      return [get_class($this), 'calculateCost'];
31
    }
32
33
    // The query processor has a default value of '1' for fields that do not
34
    // declare their cost by themselves.
35
    return NULL;
36
  }
37
38
}
39