Passed
Push — master ( 3d58fd...651f47 )
by Edward
05:09
created

UniqueNumericAggregator::findNumericElements()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 1
dl 0
loc 13
ccs 9
cts 9
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Remorhaz\JSON\Path\Runtime\Aggregator;
5
6
use Remorhaz\JSON\Data\Value\ScalarValueInterface;
7
use Remorhaz\JSON\Data\Value\ValueInterface;
8
9
abstract class UniqueNumericAggregator extends NumericAggregator
10
{
11
12
    /**
13
     * @param ValueInterface $value
14
     * @return ScalarValueInterface[]
15
     */
16 2
    protected function findNumericElements(ValueInterface $value): array
17
    {
18 2
        $elements = [];
19 2
        $uniqueDataList = [];
20 2
        foreach (parent::findNumericElements($value) as $element) {
21 2
            if (in_array($element->getData(), $uniqueDataList, true)) {
22 1
                continue;
23
            }
24 2
            $uniqueDataList[] = $element->getData();
25 2
            $elements[] = $element;
26
        }
27
28 2
        return $elements;
29
    }
30
}
31