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

AggregatorCollection::byName()   A

Complexity

Conditions 6
Paths 6

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 6

Importance

Changes 0
Metric Value
cc 6
eloc 12
nc 6
nop 1
dl 0
loc 20
ccs 12
cts 12
cp 1
crap 6
rs 9.2222
c 0
b 0
f 0
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 6
    public function byName(string $name): ValueAggregatorInterface
16
    {
17
        switch ($name) {
18 6
            case self::MIN:
19 1
                return new MinAggregator;
20
21 5
            case self::MAX:
22 1
                return new MaxAggregator;
23
24 4
            case self::LENGTH:
25 1
                return new LengthAggregator;
26
27 3
            case self::AVG:
28 1
                return new AvgAggregator;
29
30 2
            case self::STDDEV:
31 1
                return new StdDevAggregator;
32
        }
33
34 1
        throw new Exception\AggregateFunctionNotFoundException($name);
35
    }
36
}
37