Completed
Push — master ( cb0ced...7754cf )
by Edward
04:45
created

AggregatorCollection::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace Remorhaz\JSON\Path\Runtime\Aggregator;
5
6
final class AggregatorCollection
7
{
8
9
    private const MIN = 'min';
10
    private const MAX = 'max';
11
    private const LENGTH = 'length';
12
    private const AVG = 'avg';
13
    private const STDDEV = 'stddev';
14
15
    public function byName(string $name): ValueAggregatorInterface
16
    {
17
        switch ($name) {
18
            case self::MIN:
19
                return new MinAggregator;
20
21
            case self::MAX:
22
                return new MaxAggregator;
23
24
            case self::LENGTH:
25
                return new LengthAggregator;
26
27
            case self::AVG:
28
                return new AvgAggregator;
29
30
            case self::STDDEV:
31
                return new StdDevAggregator;
32
        }
33
34
        throw new Exception\AggregateFunctionNotFoundException($name);
35
    }
36
}
37