Passed
Pull Request — master (#209)
by Christoffer
02:51
created

ValueHelper::resolveEnumType()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 2
1
<?php
2
3
namespace Digia\GraphQL\Util;
4
5
use Digia\GraphQL\Error\InvalidTypeException;
6
use Digia\GraphQL\Error\InvariantException;
7
use Digia\GraphQL\Error\ResolutionException;
8
use Digia\GraphQL\Language\Node\ArgumentNode;
9
use Digia\GraphQL\Language\Node\EnumValueNode;
10
use Digia\GraphQL\Language\Node\ListValueNode;
11
use Digia\GraphQL\Language\Node\NodeInterface;
12
use Digia\GraphQL\Language\Node\NullValueNode;
13
use Digia\GraphQL\Language\Node\ObjectFieldNode;
14
use Digia\GraphQL\Language\Node\ObjectValueNode;
15
use Digia\GraphQL\Language\Node\ValueNodeInterface;
16
use Digia\GraphQL\Language\Node\VariableNode;
17
use Digia\GraphQL\Type\Definition\EnumType;
18
use Digia\GraphQL\Type\Definition\InputObjectType;
19
use Digia\GraphQL\Type\Definition\InputTypeInterface;
20
use Digia\GraphQL\Type\Definition\ListType;
21
use Digia\GraphQL\Type\Definition\NonNullType;
22
use Digia\GraphQL\Type\Definition\ScalarType;
23
use Digia\GraphQL\Type\Definition\TypeInterface;
24
use function Digia\GraphQL\printNode;
25
26
class ValueHelper
27
{
28
    /**
29
     * @param array $argumentsA
30
     * @param array $argumentsB
31
     * @return bool
32
     */
33
    function compareArguments(array $argumentsA, array $argumentsB): bool
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
34
    {
35
        if (\count($argumentsA) !== \count($argumentsB)) {
36
            return false;
37
        }
38
39
        return arrayEvery($argumentsA, function (ArgumentNode $argumentA) use ($argumentsB) {
40
            $argumentB = find($argumentsB, function (ArgumentNode $argument) use ($argumentA) {
41
                return $argument->getNameValue() === $argumentA->getNameValue();
42
            });
43
44
            if (null === $argumentB) {
45
                return false;
46
            }
47
48
            return $this->compareValues($argumentA->getValue(), $argumentB->getValue());
49
        });
50
    }
51
52
    /**
53
     * @param $valueA
54
     * @param $valueB
55
     * @return bool
56
     */
57
    public function compareValues($valueA, $valueB): bool
58
    {
59
        return printNode($valueA) === printNode($valueB);
60
    }
61
}
62