ProfilerListener   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 55.56%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 6
dl 0
loc 32
ccs 5
cts 9
cp 0.5556
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A implementedEvents() 0 6 1
A construct() 0 11 2
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * This file is part of TwigView.
6
 *
7
 ** (c) 2014 Cees-Jan Kiewiet
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace WyriHaximus\TwigView\Event;
14
15
use Cake\Event\EventListenerInterface;
16
use Cake\Event\EventManager;
17
use Twig\Profiler\Profile;
18
use WyriHaximus\TwigView\Lib\Twig\Extension;
19
20
/**
21
 * Class ExtensionsListener.
22
 * @package WyriHaximus\TwigView\Event
23
 */
24
final class ProfilerListener implements EventListenerInterface
25
{
26
    /**
27
     * Return implemented events.
28
     *
29
     * @return array
30
     */
31 1
    public function implementedEvents(): array
32
    {
33
        return [
34 1
            ConstructEvent::EVENT => 'construct',
35
        ];
36
    }
37
38
    /**
39
     * Event handler.
40
     *
41
     * @param \WyriHaximus\TwigView\Event\ConstructEvent $event Event.
42
     *
43
     */
44 1
    public function construct(ConstructEvent $event)
45
    {
46 1
        if ($event->getTwig()->hasExtension(Extension\Profiler::class)) {
47 1
            return;
48
        }
49
50
        $profile = new Profile();
51
        $event->getTwig()->addExtension(new Extension\Profiler($profile));
52
53
        EventManager::instance()->dispatch(ProfileEvent::create($profile));
54
    }
55
}
56