Completed
Pull Request — master (#69)
by Christoffer
03:54 queued 01:50
created

ComparisonContext   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 86
rs 10
c 0
b 0
f 0
wmc 8

7 Methods

Rating   Name   Duplication   Size   Complexity  
A registerField() 0 11 2
A reportConflict() 0 5 1
A getFieldMap() 0 3 1
A getFragmentNames() 0 3 1
A registerFragment() 0 5 1
A hasConflicts() 0 3 1
A getConflicts() 0 3 1
1
<?php
2
3
namespace Digia\GraphQL\Validation\Conflict;
4
5
use Digia\GraphQL\Language\AST\Node\FragmentDefinitionNode;
0 ignored issues
show
Bug introduced by
The type Digia\GraphQL\Language\A...\FragmentDefinitionNode was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Digia\GraphQL\Language\AST\Node\FragmentSpreadNode;
0 ignored issues
show
Bug introduced by
The type Digia\GraphQL\Language\AST\Node\FragmentSpreadNode was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Digia\GraphQL\Language\AST\Node\InlineFragmentNode;
0 ignored issues
show
Bug introduced by
The type Digia\GraphQL\Language\AST\Node\InlineFragmentNode was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Digia\GraphQL\Language\AST\Node\NodeInterface;
0 ignored issues
show
Bug introduced by
The type Digia\GraphQL\Language\AST\Node\NodeInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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();
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