FixHtmlEntitiesInExpressionSubscriber   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 41
c 0
b 0
f 0
wmc 3
cbo 2
ccs 18
cts 18
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 7 1
A addPlaceholder() 0 11 1
A removePlaceholder() 0 10 1
1
<?php
2
namespace Goetas\Twital\EventSubscriber;
3
4
use Goetas\Twital\EventDispatcher\CompilerEvents;
5
use Goetas\Twital\EventDispatcher\SourceEvent;
6
7
/**
8
 *
9
 * @author Asmir Mustafic <[email protected]>
10
 *
11
 */
12
class FixHtmlEntitiesInExpressionSubscriber extends AbstractTwigExpressionSubscriber
13
{
14 487
    public static function getSubscribedEvents()
15
    {
16
        return array(
17 487
            CompilerEvents::PRE_LOAD => 'addPlaceholder',
18 487
            CompilerEvents::POST_DUMP => 'removePlaceholder',
19 487
        );
20
    }
21
22
    /**
23
     *
24
     * @param SourceEvent $event
25
     */
26 486
    public function addPlaceholder(SourceEvent $event)
27
    {
28 486
        $source = $event->getTemplate();
29 486
        $format = $this->placeholderFormat;
30
31
        $source = $this->processTwig($source, function ($twig) use ($format) {
32 109
            return sprintf($format, htmlspecialchars($twig, ENT_COMPAT, 'UTF-8'));
33 486
        });
34
35 486
        $event->setTemplate($source);
36 486
    }
37
38
    /**
39
     *
40
     * @param SourceEvent $event
41
     */
42 484
    public function removePlaceholder(SourceEvent $event)
43
    {
44 484
        $source = $event->getTemplate();
45
46 484
        $source = $this->processPlaceholder($source, function ($matches) {
47 109
            return html_entity_decode($matches[2], ENT_COMPAT, 'UTF-8');
48 484
        });
49
50 484
        $event->setTemplate($source);
51 484
    }
52
}
53