Passed
Push — master ( 1ba3e3...448aab )
by Kacper
03:26
created

Html::getIdentifier()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Highlighter
4
 *
5
 * Copyright (C) 2016, Some right reserved.
6
 *
7
 * @author Kacper "Kadet" Donat <[email protected]>
8
 *
9
 * Contact with author:
10
 * Xmpp: [email protected]
11
 * E-mail: [email protected]
12
 *
13
 * From Kadet with love.
14
 */
15
16
namespace Kadet\Highlighter\Language;
17
18
use Kadet\Highlighter\Matcher\RegexMatcher;
19
use Kadet\Highlighter\Parser\CloseRule;
20
use Kadet\Highlighter\Parser\Token\LanguageToken;
21
use Kadet\Highlighter\Parser\OpenRule;
22
use Kadet\Highlighter\Parser\TokenFactory;
23
24
class Html extends Xml
25
{
26
    /**
27
     * Tokenization rules
28
     */
29 1
    public function setupRules()
30
    {
31 1
        parent::setupRules();
32
33 1
        $css = new Css();
34 1
        $js  = new JavaScript();
35 1
        $this->rules->addMany([
36 1
            'language.'.$js->getIdentifier() => [
37 1
                new OpenRule(new RegexMatcher('/<script.*?>()/'), [
38 1
                    'factory'     => new TokenFactory(LanguageToken::class),
39 1
                    'inject'      => $js,
40 1
                    'language'    => $this,
41
                    'postProcess' => true
42 1
                ]),
43 1
                new CloseRule(new RegexMatcher('/()<\/script>/'), [
44 1
                    'factory'  => new TokenFactory(LanguageToken::class),
45
                    'language' => $js
46 1
                ])
47 1
            ],
48 1
            'language.'.$css->getIdentifier() => [
49 1
                new OpenRule(new RegexMatcher('/<style.*?>()/'), [
50 1
                    'factory'     => new TokenFactory(LanguageToken::class),
51 1
                    'inject'      => $css,
52 1
                    'language'    => $this,
53
                    'postProcess' => true
54 1
                ]),
55 1
                new CloseRule(new RegexMatcher('/()<\/style>/'), [
56 1
                    'factory'  => new TokenFactory(LanguageToken::class),
57
                    'language' => $css
58 1
                ])
59 1
            ]
60 1
        ]);
61 1
    }
62
63 1
    public function getIdentifier()
64
    {
65 1
        return 'html';
66
    }
67
68 1 View Code Duplication
    public static function getMetadata()
69
    {
70
        return [
71
            'name'      => ['html'],
72
            'mime'      => ['text/html'],
73 1
            'extension' => ['*.html', '*.htm']
74
        ];
75
    }
76
}
77