Completed
Pull Request — 8.x-3.x (#525)
by Philipp
02:07
created

ArgumentAwarePluginTrait::buildArguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 1
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\graphql\Plugin\GraphQL\Traits;
4
5
use Drupal\graphql\Utility\StringHelper;
6
7
trait ArgumentAwarePluginTrait {
8
9
  /**
10
   * @param $definition
11
   *
12
   * @return array
13
   */
14
  protected function buildArguments($definition) {
15
    return array_map(function ($argument) use ($definition) {
16
      return [
17
        'type' => $this->buildArgumentType($argument, $definition),
0 ignored issues
show
Unused Code introduced by
The call to ArgumentAwarePluginTrait::buildArgumentType() has too many arguments starting with $definition.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
18
        'description' => $this->buildArgumentDescription($argument, $definition),
19
        'defaultValue' => $this->buildArgumentDefault($argument, $definition),
20
      ];
21
    }, $definition['arguments']);
22
  }
23
24
  /**
25
   * @param $argument
26
   *
27
   * @return array
28
   */
29
  protected function buildArgumentType($argument) {
30
    $type = is_array($argument) ? $argument['type'] : $argument;
31
    return StringHelper::parseType($type);
32
  }
33
34
  /**
35
   * @param $argument
36
   * @param $definition
37
   *
38
   * @return string
39
   */
40
  protected function buildArgumentDescription($argument, $definition) {
0 ignored issues
show
Unused Code introduced by
The parameter $definition is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
41
    return (string) (isset($argument['description']) ? $argument['description'] : '');
42
  }
43
44
  /**
45
   * @param $argument
46
   * @param $definition
47
   *
48
   * @return null
49
   */
50
  protected function buildArgumentDefault($argument, $definition) {
0 ignored issues
show
Unused Code introduced by
The parameter $definition is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
51
    return isset($argument['default']) ? $argument['default'] : NULL;
52
  }
53
54
}
55