Completed
Push — master ( 6054a8...c11aa8 )
by Kacper
04:06
created

Html   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 15.09 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 7
Bugs 2 Features 0
Metric Value
c 7
b 2
f 0
dl 8
loc 53
rs 10
wmc 3
lcom 1
cbo 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
B setupRules() 0 33 1
A getIdentifier() 0 4 1
A getMetadata() 8 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
    public function setupRules()
30
    {
31
        parent::setupRules();
32
33
        $css = new Css();
34
        $js  = new JavaScript();
35
        $this->rules->addMany([
36
            'language.'.$js->getIdentifier() => [
37
                new OpenRule(new RegexMatcher('/<script.*?>()/'), [
38
                    'factory'     => new TokenFactory(LanguageToken::class),
39
                    'inject'      => $js,
40
                    'language'    => $this,
41
                    'postProcess' => true
42
                ]),
43
                new CloseRule(new RegexMatcher('/()<\/script>/'), [
44
                    'factory'  => new TokenFactory(LanguageToken::class),
45
                    'language' => $js
46
                ])
47
            ],
48
            'language.'.$css->getIdentifier() => [
49
                new OpenRule(new RegexMatcher('/<style.*?>()/'), [
50
                    'factory'     => new TokenFactory(LanguageToken::class),
51
                    'inject'      => $css,
52
                    'language'    => $this,
53
                    'postProcess' => true
54
                ]),
55
                new CloseRule(new RegexMatcher('/()<\/style>/'), [
56
                    'factory'  => new TokenFactory(LanguageToken::class),
57
                    'language' => $css
58
                ])
59
            ]
60
        ]);
61
    }
62
63
    public function getIdentifier()
64
    {
65
        return 'html';
66
    }
67
68 View Code Duplication
    public static function getMetadata()
69
    {
70
        return [
71
            'name'      => ['html'],
72
            'mime'      => ['text/html'],
73
            'extension' => ['*.html', '*.htm']
74
        ];
75
    }
76
}
77