Completed
Push — master ( bc7135...aca075 )
by Asmir
10s
created

ReplaceDoctypeAsTwigExpressionSubscriber   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 1

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 6 1
A replaceDoctype() 0 10 1
1
<?php
2
3
namespace Goetas\Twital\EventSubscriber;
4
5
use Goetas\Twital\EventDispatcher\CompilerEvents;
6
use Goetas\Twital\EventDispatcher\SourceEvent;
7
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
8
9
/**
10
 *
11
 * @author Asmir Mustafic <[email protected]>
12
 *
13
 */
14
class ReplaceDoctypeAsTwigExpressionSubscriber implements EventSubscriberInterface
15
{
16 25
    public static function getSubscribedEvents()
17
    {
18
        return array(
19 25
            CompilerEvents::PRE_LOAD => array('replaceDoctype', 130),
20 25
        );
21
    }
22
23
    /**
24
     *
25
     * @param SourceEvent $event
26
     */
27 24
    public function replaceDoctype(SourceEvent $event)
28
    {
29 24
        $source = $event->getTemplate();
30
31 24
        $source = preg_replace_callback('/^<!doctype.*?>/im', function ($mch) {
32 2
            return '{{ \'' . addslashes($mch[0]) . '\' }}';
33 24
        }, $source);
34
35 24
        $event->setTemplate($source);
36 24
    }
37
}
38