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

MinAggregator::findElementIndex()   A

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
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
use function array_search;
9
use function min;
10
11
final class MinAggregator extends UniqueNumericAggregator
12
{
13
14 2
    protected function aggregateNumericData(array $dataList, ScalarValueInterface ...$elements): ?ValueInterface
15
    {
16 2
        $elementIndex = $this->findElementIndex($dataList);
17 2
        if (isset($elementIndex, $elements[$elementIndex])) {
18 2
            return $elements[$elementIndex];
19
        }
20
21
        // @codeCoverageIgnoreStart
22
        throw new Exception\MaxElementNotFoundException($dataList, $elements);
23
        // @codeCoverageIgnoreEnd
24
    }
25
26 2
    private function findElementIndex(array $dataList): ?int
27
    {
28 2
        $elementIndex = array_search(min($dataList), $dataList, true);
29
30 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...
31
    }
32
}
33