MinAggregator::findElementIndex()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 2
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
use function array_search;
11
use function min;
12
13
final class MinAggregator extends UniqueNumericAggregator
14
{
15
16 2
    protected function aggregateNumericData(array $dataList, ScalarValueInterface ...$elements): ?ValueInterface
17
    {
18 2
        $elementIndex = $this->findElementIndex($dataList);
19 2
        if (isset($elementIndex, $elements[$elementIndex])) {
20 2
            return $elements[$elementIndex];
21
        }
22
23
        // @codeCoverageIgnoreStart
24
        throw new Exception\MaxElementNotFoundException($dataList, $elements);
25
        // @codeCoverageIgnoreEnd
26
    }
27
28 2
    private function findElementIndex(array $dataList): ?int
29
    {
30 2
        $elementIndex = array_search(min($dataList), $dataList, true);
31
32 2
        return false === $elementIndex ? null : $elementIndex;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false === $elemen... ? null : $elementIndex could return the type string which is incompatible with the type-hinted return integer|null. Consider adding an additional type-check to rule them out.
Loading history...
33
    }
34
}
35