InputObjectType::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 3
crap 1
1
<?php
2
3
namespace Fubhy\GraphQL\Type\Definition\Types;
4
5
use Fubhy\GraphQL\Type\Definition\InputObjectField;
6
7
/**
8
 * Input Object Type Definition.
9
 *
10
 * An input object defines a structured collection of fields which may be
11
 * supplied to a field argument.
12
 *
13
 * Using `NonNull` will ensure that a value must be provided by the query.
14
 */
15
class InputObjectType extends Type implements InputTypeInterface, NullableTypeInterface, UnmodifiedTypeInterface
16
{
17
    /**
18
     * @var array
19
     */
20
    protected $fields;
21
22
    /**
23
     * @var array
24
     */
25
    protected $fieldMap;
26
27
    /**
28
     * Constructor.
29
     *
30
     * @param string $name
31
     * @param array $fields
32
     * @param string|null $description
33
     */
34 84
    public function __construct($name, array $fields = [], $description = NULL)
35
    {
36 84
        parent::__construct($name, $description);
37
38 84
        $this->fields = $fields;
39 84
    }
40
41
    /**
42
     * @return \Fubhy\GraphQL\Type\Definition\InputObjectField[]
43
     */
44 9 View Code Duplication
    public function getFields()
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...
45
    {
46 9
        if (!isset($this->fieldMap)) {
47 9
            $this->fieldMap = [];
48 9
            foreach ($this->fields as $name => $field) {
49 9
                if (!isset($field['name'])) {
50 9
                    $field['name'] = $name;
51 9
                }
52
53 9
                $this->fieldMap[$name] = new InputObjectField($field);
54 9
            }
55 9
        }
56
57 9
        return $this->fieldMap;
58
    }
59
}
60