DispatcherFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B createService() 0 22 4
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\Engine\Engine;
13
use PhpAb\Event\Dispatcher;
14
use PhpAb\Event\SubscriberInterface;
15
use PhpAb\Storage\Cookie;
16
use PhpAb\Storage\Runtime;
17
use PhpAb\Storage\Session;
18
use RuntimeException;
19
use Zend\ServiceManager\FactoryInterface;
20
use Zend\ServiceManager\ServiceLocatorInterface;
21
22
class DispatcherFactory implements FactoryInterface
23
{
24
    public function createService(ServiceLocatorInterface $serviceLocator)
25
    {
26
        $dispatcher = new Dispatcher();
27
28
        $config = $serviceLocator->get('Config');
29
        $collectorName = $config['phpab']['analytics_collector'];
30
31
        if ($collectorName && $serviceLocator->has($collectorName)) {
32
            $dataCollector = $serviceLocator->get($collectorName);
33
34
            if (!$dataCollector instanceof SubscriberInterface) {
35
                throw new RuntimeException(sprintf(
36
                    'The data collector is not an instance of %s',
37
                    SubscriberInterface::class
38
                ));
39
            }
40
41
            $dispatcher->addSubscriber($dataCollector);
42
        }
43
44
        return $dispatcher;
45
    }
46
}
47