TokenParsersListener   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 4
dl 0
loc 31
ccs 6
cts 7
cp 0.8571
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A implementedEvents() 0 6 1
A construct() 0 10 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 LogicException;
17
use WyriHaximus\TwigView\Lib\Twig\TokenParser;
18
19
/**
20
 * Class TokenParsersListener.
21
 * @package WyriHaximus\TwigView\Event
22
 */
23
final class TokenParsersListener implements EventListenerInterface
24
{
25
    /**
26
     * Return implemented events.
27
     *
28
     * @return array
29
     */
30 14
    public function implementedEvents(): array
31
    {
32
        return [
33 14
            ConstructEvent::EVENT => 'construct',
34
        ];
35
    }
36
37
    /**
38
     * Event handler.
39
     *
40
     * @param \WyriHaximus\TwigView\Event\ConstructEvent $event Event.
41
     *
42
     */
43 1
    public function construct(ConstructEvent $event)
44
    {
45
        // CakePHP specific tags
46
        try {
47 1
            $event->getTwig()->addTokenParser(new TokenParser\Cell());
48 1
            $event->getTwig()->addTokenParser(new TokenParser\Element());
49
        } catch (LogicException $d) {
50
            // Nothing to do as token parser already added.
51
        }
52 1
    }
53
}
54