Code Duplication    Length = 30-30 lines in 2 locations

src/Plugin/GraphQL/InputTypes/InputTypePluginBase.php 1 location

@@ 56-85 (lines=30) @@
53
   * @return \Youshido\GraphQL\Field\FieldInterface[]
54
   *   The list of fields.
55
   */
56
  protected function buildFields(PluggableSchemaBuilderInterface $schemaBuilder) {
57
    if ($this instanceof PluginInspectionInterface) {
58
      $definition = $this->getPluginDefinition();
59
      if (!$definition['fields']) {
60
        return [];
61
      }
62
63
      $arguments = [];
64
      foreach ($definition['fields'] as $name => $argument) {
65
        $type = $this->buildFieldType($schemaBuilder, $argument);
66
67
        if ($type instanceof TypeInterface) {
68
          $config = [
69
            'name' => $name,
70
            'type' => $type,
71
          ];
72
73
          if (is_array($argument) && isset($argument['default'])) {
74
            $config['defaultValue'] = $argument['default'];
75
          }
76
77
          $arguments[$name] = new Field($config);
78
        }
79
      }
80
81
      return $arguments;
82
    }
83
84
    return [];
85
  }
86
87
  /**
88
   * Build the field type.

src/Plugin/GraphQL/Traits/ArgumentAwarePluginTrait.php 1 location

@@ 25-54 (lines=30) @@
22
   * @return \Youshido\GraphQL\Field\InputFieldInterface[]
23
   *   The list of arguments.
24
   */
25
  protected function buildArguments(PluggableSchemaBuilderInterface $schemaBuilder) {
26
    if ($this instanceof PluginInspectionInterface) {
27
      $definition = $this->getPluginDefinition();
28
      if (!$definition['arguments']) {
29
        return [];
30
      }
31
32
      $arguments = [];
33
      foreach ($definition['arguments'] as $name => $argument) {
34
        $type = $this->buildArgumentType($schemaBuilder, $argument);
35
36
        if ($type instanceof TypeInterface) {
37
          $config = [
38
            'name' => $name,
39
            'type' => $type,
40
          ];
41
42
          if (is_array($argument) && isset($argument['default'])) {
43
            $config['defaultValue'] = $argument['default'];
44
          }
45
46
          $arguments[$name] = new InputField($config);
47
        }
48
      }
49
50
      return $arguments;
51
    }
52
53
    return [];
54
  }
55
56
  /**
57
   * Build the argument type.