AggregatorCollection::byName()   A
last analyzed

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
3
declare(strict_types=1);
4
5
namespace Remorhaz\JSON\Path\Runtime\Aggregator;
6
7
final class AggregatorCollection implements AggregatorCollectionInterface
8
{
9
10
    private const MIN = 'min';
11
    private const MAX = 'max';
12
    private const LENGTH = 'length';
13
    private const AVG = 'avg';
14
    private const STDDEV = 'stddev';
15
16 6
    public function byName(string $name): ValueAggregatorInterface
17
    {
18
        switch ($name) {
19 6
            case self::MIN:
20 1
                return new MinAggregator();
21
22 5
            case self::MAX:
23 1
                return new MaxAggregator();
24
25 4
            case self::LENGTH:
26 1
                return new LengthAggregator();
27
28 3
            case self::AVG:
29 1
                return new AvgAggregator();
30
31 2
            case self::STDDEV:
32 1
                return new StdDevAggregator();
33
        }
34
35 1
        throw new Exception\AggregateFunctionNotFoundException($name);
36
    }
37
}
38