Completed
Pull Request — master (#27)
by Frederic
04:50 queued 02:40
created

MetricServiceFactory::create()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.0261

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 6
cts 7
cp 0.8571
rs 9.7666
c 0
b 0
f 0
cc 3
nc 3
nop 3
crap 3.0261
1
<?php
2
3
namespace Burrow\Metric;
4
5
use Beberlei\Metrics\Collector\DogStatsD;
6
use Beberlei\Metrics\Collector\StatsD;
7
use Beberlei\Metrics\Factory;
8
use Beberlei\Metrics\MetricsException;
9
10
class MetricServiceFactory
11
{
12
    /**
13
     * @param       $type
14
     * @param array $options
15
     * @param array $contextualTags
16
     *
17
     * @return MetricService
18
     * @throws MetricsException
19
     * @throws \Exception
20
     */
21 6
    public static function create($type, $options = [], $contextualTags = [])
22
    {
23 6
        $collector = Factory::create($type, $options);
24
25
        switch ($type) {
26 6
            case 'dogstatsd':
27
                /** @var DogStatsD $collector */
28 3
                return new DogStatsDMetricService($collector, $contextualTags);
29 3
            case 'statsd':
30
                /** @var StatsD $collector */
31 3
                return new StatsDMetricService($collector);
32
        }
33
34
        throw new \Exception(sprintf('MetricService for %s is not implemented', $type));
35
    }
36
}
37