EventProfilerFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 13 2
1
<?php
2
/**
3
 * Webino (http://webino.sk/)
4
 *
5
 * @link        https://github.com/webino/WebinoDebug/ for the canonical source repository
6
 * @copyright   Copyright (c) 2014-2017 Webino, s. r. o. (http://webino.sk/)
7
 * @license     BSD-3-Clause
8
 */
9
10
namespace WebinoDebug\Factory;
11
12
use WebinoDebug\Listener\EventProfilerListener;
13
use WebinoDebug\Service\EventProfiler;
14
use Zend\ModuleManager\ModuleManager;
15
use Zend\ServiceManager\FactoryInterface;
16
use Zend\ServiceManager\ServiceLocatorInterface;
17
18
/**
19
 * Factory for an event profiler
20
 */
21
class EventProfilerFactory
22
{
23
    /**
24
     * Event profiler service name
25
     */
26
    const SERVICE = 'EventProfiler';
27
28
    /**
29
     * @param object|ModuleManager $modules
30
     * @return EventProfiler
31
     */
32
    public function create(ModuleManager $modules)
33
    {
34
        $services = $modules->getEvent()->getParam('ServiceManager');
35
        if ($services->has($this::SERVICE)) {
36
            return $services->get($this::SERVICE);
37
        }
38
39
        $sharedEvents = $modules->getEventManager()->getSharedManager();
40
        $eventProfiler = new EventProfiler($services->get(DebuggerFactory::SERVICE), $sharedEvents);
41
        $sharedEvents->attachAggregate(new EventProfilerListener($eventProfiler));
42
        $services->setService($this::SERVICE, $eventProfiler);
43
        return $eventProfiler;
44
    }
45
}
46