Completed
Push — master ( 348af9...23656b )
by Walter
05:14 queued 02:58
created

DefaultAnalyticsHandlerFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
c 1
b 0
f 1
lcom 0
cbo 1
dl 0
loc 19
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A createService() 0 16 2
1
<?php
2
/**
3
 * This file is part of phpab/phpab-module. (https://github.com/phpab/phpab-module)
4
 *
5
 * @link https://github.com/phpab/phpab-module for the canonical source repository
6
 * @copyright Copyright (c) 2015-2016 phpab. (https://github.com/phpab/)
7
 * @license https://raw.githubusercontent.com/phpab/phpab-module/master/LICENSE MIT
8
 */
9
10
namespace PhpAbModule\Service;
11
12
use PhpAb\Analytics\Renderer\Google\GoogleUniversalAnalytics;
13
use RuntimeException;
14
use Zend\ServiceManager\FactoryInterface;
15
use Zend\ServiceManager\ServiceLocatorInterface;
16
17
class DefaultAnalyticsHandlerFactory implements FactoryInterface
18
{
19
    public function createService(ServiceLocatorInterface $serviceLocator)
20
    {
21
        $config = $serviceLocator->get('Config');
22
        $collectorServiceName = $config['phpab']['analytics']['collector'];
23
24
        if (!$serviceLocator->has($collectorServiceName)) {
25
            throw new RuntimeException(sprintf(
26
                'The data collector "%s" does not exists.',
27
                $config['phpab']['analytics']['collector']
28
            ));
29
        }
30
31
        $analyticsData = $serviceLocator->get($collectorServiceName);
32
33
        return new GoogleUniversalAnalytics($analyticsData->getTestsData());
34
    }
35
}
36