DOMMessSubscriber   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
cbo 1
dl 0
loc 31
c 0
b 0
f 0
ccs 15
cts 15
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 13 1
A removeCdata() 0 7 1
A fixAttributes() 0 6 1
1
<?php
2
namespace Goetas\Twital\EventSubscriber;
3
4
use Goetas\Twital\EventDispatcher\CompilerEvents;
5
use Goetas\Twital\EventDispatcher\SourceEvent;
6
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
7
8
/**
9
 *
10
 * @author Asmir Mustafic <[email protected]>
11
 *
12
 */
13
class DOMMessSubscriber implements EventSubscriberInterface
14
{
15 487
    public static function getSubscribedEvents()
16
    {
17
        return array(
18 487
            CompilerEvents::POST_DUMP => array(
19
                array(
20
                    'removeCdata'
21 487
                ),
22
                array(
23
                    'fixAttributes'
24 487
                )
25 487
            )
26 487
        );
27
    }
28
29 484
    public function removeCdata(SourceEvent $event)
30
    {
31 484
        $event->setTemplate(str_replace(array(
32 484
            "<![CDATA[__[__",
33
            "__]__]]>"
34 484
        ), "", $event->getTemplate()));
35 484
    }
36
37
    public function fixAttributes(SourceEvent $event)
38
    {
39 484
        $event->setTemplate(preg_replace_callback('/ __attr__="(__a[0-9a-f]+)"/', function ($mch) {
40 13
            return '{% for ____ak,____av in ' . $mch[1] . ' %}{% if (____av|length > 0) and not (____av|length == 1 and ____av[0] is same as(false)) %} {{____ak|raw}}{% if ____av|length > 1 or ____av[0] is not same as(true) %}="{{ ____av|join(\'\') }}"{% endif %}{% endif %}{% endfor %}';
41 484
        }, $event->getTemplate()));
42 484
    }
43
}
44