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

MaxComplexityVisitor::visit()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 4
nop 3
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\graphql\GraphQL\Execution\Visitor;
4
5
use Youshido\GraphQL\Exception\ResolveException;
6
use Youshido\GraphQL\Field\FieldInterface;
7
8
class MaxComplexityVisitor implements VisitorInterface {
9
10
  /**
11
   * @var int
12
   */
13
  protected $defaultCost;
14
15
  /**
16
   * MaxComplexityQueryVisitor constructor.
17
   *
18
   * @param int $maxComplexity
0 ignored issues
show
Bug introduced by
There is no parameter named $maxComplexity. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
19
   *   The allowed maximum complexity.
20
   */
21
  public function __construct($defaultCost = 1) {
22
    $this->defaultCost = $defaultCost;
23
  }
24
25
  /**
26
   * {@inheritdoc}
27
   */
28
  public function visit(array $args, FieldInterface $field, $children) {
29
    /** @var \Youshido\GraphQL\Config\Field\FieldConfig $config */
30
    $config = $field->getConfig();
31
    $cost = $config->get('cost', NULL);
32
33
    if (is_callable($cost)) {
34
      $cost = $cost($args, $field, $children);
35
    }
36
37
    return isset($cost) ? $cost : $this->defaultCost;
38
  }
39
40
  /**
41
   * {@inheritdoc}
42
   */
43
  public function reduce($carry, $current) {
44
    return !empty($current) ? $carry + $current : $carry;
45
  }
46
47
  /**
48
   * {@inheritdoc}
49
   */
50
  public function initial() {
51
    return 0;
52
  }
53
}