Passed
Pull Request — master (#69)
by Christoffer
02:03
created

ComparisonContext::getConflicts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Digia\GraphQL\Validation\Conflict;
4
5
use Digia\GraphQL\Language\AST\Node\FragmentDefinitionNode;
6
use Digia\GraphQL\Language\AST\Node\FragmentSpreadNode;
7
use Digia\GraphQL\Language\AST\Node\InlineFragmentNode;
8
use Digia\GraphQL\Language\AST\Node\NodeInterface;
9
10
class ComparisonContext
11
{
12
    /**
13
     * @var array
14
     */
15
    protected $fieldMap = [];
16
17
    /**
18
     * @var array
19
     */
20
    protected $fragmentNames = [];
21
22
    /**
23
     * @var array|Conflict[]
24
     */
25
    protected $conflicts = [];
26
27
    /**
28
     * @param FieldContext $field
29
     * @return $this
30
     */
31
    public function registerField(FieldContext $field)
32
    {
33
        $responseName = $field->getNode()->getAliasOrNameValue();
34
35
        if (!isset($this->fieldMap[$responseName])) {
36
            $this->fieldMap[$responseName] = [];
37
        }
38
39
        $this->fieldMap[$responseName][] = $field;
40
41
        return $this;
42
    }
43
44
    /**
45
     * @param NodeInterface|FragmentSpreadNode|FragmentDefinitionNode $fragment
46
     * @return $this
47
     */
48
    public function registerFragment(NodeInterface $fragment)
49
    {
50
        $this->fragmentNames[] = $fragment->getNameValue();
0 ignored issues
show
Bug introduced by
The method getNameValue() does not exist on Digia\GraphQL\Language\AST\Node\NodeInterface. It seems like you code against a sub-type of Digia\GraphQL\Language\AST\Node\NodeInterface such as Digia\GraphQL\Language\AST\Node\DirectiveNode or Digia\GraphQL\Language\AST\Node\ArgumentNode or Digia\GraphQL\Language\AST\Node\ObjectFieldNode or Digia\GraphQL\Language\AST\Node\FragmentSpreadNode or Digia\GraphQL\Language\A...\EnumTypeDefinitionNode or Digia\GraphQL\Language\A...EnumValueDefinitionNode or Digia\GraphQL\Language\A...DirectiveDefinitionNode or Digia\GraphQL\Language\A...nputValueDefinitionNode or Digia\GraphQL\Language\A...ode\FieldDefinitionNode or Digia\GraphQL\Language\A...\VariableDefinitionNode or Digia\GraphQL\Language\A...DefinitionNodeInterface or Digia\GraphQL\Language\A...DefinitionNodeInterface or Digia\GraphQL\Language\A...erfaceTypeExtensionNode or Digia\GraphQL\Language\A...ScalarTypeExtensionNode or Digia\GraphQL\Language\A...\UnionTypeExtensionNode or Digia\GraphQL\Language\A...ObjectTypeExtensionNode or Digia\GraphQL\Language\A...e\EnumTypeExtensionNode or Digia\GraphQL\Language\A...ObjectTypeExtensionNode or Digia\GraphQL\Language\AST\Node\VariableNode or Digia\GraphQL\Language\AST\Node\FieldNode or Digia\GraphQL\Language\AST\Node\NamedTypeNode. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

50
        /** @scrutinizer ignore-call */ 
51
        $this->fragmentNames[] = $fragment->getNameValue();
Loading history...
51
52
        return $this;
53
    }
54
55
    /**
56
     * @param Conflict $conflict
57
     * @return $this
58
     */
59
    public function reportConflict(Conflict $conflict)
60
    {
61
        $this->conflicts[] = $conflict;
62
63
        return $this;
64
    }
65
66
    /**
67
     * @return array
68
     */
69
    public function getFieldMap(): array
70
    {
71
        return $this->fieldMap;
72
    }
73
74
    /**
75
     * @return array
76
     */
77
    public function getFragmentNames(): array
78
    {
79
        return $this->fragmentNames;
80
    }
81
82
    /**
83
     * @return bool
84
     */
85
    public function hasConflicts(): bool
86
    {
87
        return !empty($this->conflicts);
88
    }
89
90
    /**
91
     * @return array|Conflict[]
92
     */
93
    public function getConflicts()
94
    {
95
        return $this->conflicts;
96
    }
97
}
98