ProfilerListener::construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.7462

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 3
cts 7
cp 0.4286
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2.7462
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