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

AggregatorCollection::byName()   A

Complexity

Conditions 6
Paths 6

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
cc 6
eloc 12
c 0
b 0
f 0
nc 6
nop 1
dl 0
loc 20
ccs 0
cts 12
cp 0
crap 42
rs 9.2222
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