Completed
Pull Request — master (#259)
by Sam
04:50
created

ValueHelper::compareValues()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 2
1
<?php
2
3
namespace Digia\GraphQL\Util;
4
5
use Digia\GraphQL\Language\Node\ArgumentNode;
6
use function Digia\GraphQL\printNode;
7
8
class ValueHelper
9
{
10
    /**
11
     * @param ArgumentNode[] $argumentsA
12
     * @param ArgumentNode[] $argumentsB
13
     * @return bool
14
     */
15
    public static function compareArguments(array $argumentsA, array $argumentsB): bool
16
    {
17
        if (\count($argumentsA) !== \count($argumentsB)) {
18
            return false;
19
        }
20
21
        return arrayEvery($argumentsA, function (ArgumentNode $argumentA) use ($argumentsB) {
22
            $argumentB = find($argumentsB, function (ArgumentNode $argument) use ($argumentA) {
23
                return $argument->getNameValue() === $argumentA->getNameValue();
24
            });
25
26
            if (null === $argumentB) {
27
                return false;
28
            }
29
30
            return printNode($argumentA->getValue()) === printNode($argumentB->getValue());
31
        });
32
    }
33
}
34