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

ValueHelper::fromAST()   C

Complexity

Conditions 10
Paths 10

Size

Total Lines 47
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 47
rs 5.1578
c 0
b 0
f 0
cc 10
eloc 21
nc 10
nop 3

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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