Completed
Pull Request — master (#27)
by Frederic
05:43
created

MetricServiceFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 27
ccs 6
cts 7
cp 0.8571
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 15 3
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 DogStatsDMetricService|StatsDMetricService
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