UniqueNumericAggregator::findNumericElements()   A
last analyzed

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
3
declare(strict_types=1);
4
5
namespace Remorhaz\JSON\Path\Runtime\Aggregator;
6
7
use Remorhaz\JSON\Data\Value\ScalarValueInterface;
8
use Remorhaz\JSON\Data\Value\ValueInterface;
9
10
abstract class UniqueNumericAggregator extends NumericAggregator
11
{
12
13
    /**
14
     * @param ValueInterface $value
15
     * @return ScalarValueInterface[]
16
     */
17 2
    protected function findNumericElements(ValueInterface $value): array
18
    {
19 2
        $elements = [];
20 2
        $uniqueDataList = [];
21 2
        foreach (parent::findNumericElements($value) as $element) {
22 2
            if (in_array($element->getData(), $uniqueDataList, true)) {
23 1
                continue;
24
            }
25 2
            $uniqueDataList[] = $element->getData();
26 2
            $elements[] = $element;
27
        }
28
29 2
        return $elements;
30
    }
31
}
32