Passed
Push — master ( 651f47...1b6630 )
by Edward
03:03
created

AvgAggregator::aggregateNumericData()   A

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
declare(strict_types=1);
3
4
namespace Remorhaz\JSON\Path\Runtime\Aggregator;
5
6
use function array_sum;
7
use function count;
8
use Remorhaz\JSON\Path\Value\LiteralScalarValue;
9
use Remorhaz\JSON\Data\Value\ScalarValueInterface;
10
use Remorhaz\JSON\Data\Value\ValueInterface;
11
12
final class AvgAggregator extends NumericAggregator
13
{
14
15 2
    protected function aggregateNumericData(array $dataList, ScalarValueInterface ...$elements): ?ValueInterface
16
    {
17 2
        return empty($dataList)
18
            // @codeCoverageIgnoreStart
19
            ? null
20
            // @codeCoverageIgnoreEnd
21 2
            : new LiteralScalarValue(array_sum($dataList) / count($dataList));
22
    }
23
}
24