FieldsAwareDefinitionTrait::getFields()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/*******************************************************************************
3
 *  This file is part of the GraphQL Bundle package.
4
 *
5
 *  (c) YnloUltratech <[email protected]>
6
 *
7
 *  For the full copyright and license information, please view the LICENSE
8
 *  file that was distributed with this source code.
9
 ******************************************************************************/
10
11
namespace Ynlo\GraphQLBundle\Definition\Traits;
12
13
use Ynlo\GraphQLBundle\Definition\FieldDefinition;
14
use Ynlo\GraphQLBundle\Definition\FieldsAwareDefinitionInterface;
15
16
/**
17
 * Trait FieldsAwareDefinitionTrait
18
 */
19
trait FieldsAwareDefinitionTrait
20
{
21
    /**
22
     * @var FieldDefinition[]
23
     */
24
    protected $fields = [];
25
26
    /**
27
     * @return array|FieldDefinition[]
28
     */
29 33
    public function getFields(): array
30
    {
31 33
        return $this->fields;
32
    }
33
34
    /**
35
     * @param string $name
36
     *
37
     * @return FieldDefinition
38
     */
39 36
    public function getField(string $name): FieldDefinition
40
    {
41 36
        return $this->fields[$name];
42
    }
43
44
    /**
45
     * @param string $name
46
     *
47
     * @return boolean
48
     */
49 39
    public function hasField(string $name): bool
50
    {
51 39
        return array_key_exists($name, $this->fields);
52
    }
53
54
    /**
55
     * @param FieldDefinition $field
56
     *
57
     * @return FieldsAwareDefinitionInterface
58
     */
59 38
    public function addField(FieldDefinition $field): FieldsAwareDefinitionInterface
60
    {
61 38
        $this->fields[$field->getName()] = $field;
62
63 38
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Ynlo\GraphQLBundle\Defin...ldsAwareDefinitionTrait which is incompatible with the type-hinted return Ynlo\GraphQLBundle\Defin...wareDefinitionInterface.
Loading history...
64
    }
65
66
    /**
67
     * @param string $name
68
     *
69
     * @return FieldsAwareDefinitionInterface
70
     */
71 32
    public function removeField(string $name): FieldsAwareDefinitionInterface
72
    {
73 32
        unset($this->fields[$name]);
74
75 32
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Ynlo\GraphQLBundle\Defin...ldsAwareDefinitionTrait which is incompatible with the type-hinted return Ynlo\GraphQLBundle\Defin...wareDefinitionInterface.
Loading history...
76
    }
77
78
    /**
79
     * @param FieldDefinition $field
80
     *
81
     * @return FieldsAwareDefinitionInterface
82
     */
83 1
    public function prependField(FieldDefinition $field): FieldsAwareDefinitionInterface
84
    {
85 1
        $this->fields = array_merge([$field->getName() => $field], $this->fields);
86
87 1
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Ynlo\GraphQLBundle\Defin...ldsAwareDefinitionTrait which is incompatible with the type-hinted return Ynlo\GraphQLBundle\Defin...wareDefinitionInterface.
Loading history...
88
    }
89
}
90