AvgAggregator::aggregateNumericData()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 7
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\Path\Value\LiteralScalarValue;
8
use Remorhaz\JSON\Data\Value\ScalarValueInterface;
9
use Remorhaz\JSON\Data\Value\ValueInterface;
10
11
use function array_sum;
12
use function count;
13
14
final class AvgAggregator extends NumericAggregator
15
{
16
17 2
    protected function aggregateNumericData(array $dataList, ScalarValueInterface ...$elements): ?ValueInterface
18
    {
19 2
        return empty($dataList)
20
            // @codeCoverageIgnoreStart
21
            ? null
22
            // @codeCoverageIgnoreEnd
23 2
            : new LiteralScalarValue(array_sum($dataList) / count($dataList));
24
    }
25
}
26