Completed
Push — master ( 606ca4...edcce7 )
by Kacper
05:58
created

Ini   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 25 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 12.5%

Importance

Changes 0
Metric Value
dl 8
loc 32
rs 10
c 0
b 0
f 0
ccs 2
cts 16
cp 0.125
wmc 3
lcom 1
cbo 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setupRules() 0 11 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\CommentMatcher;
19
use Kadet\Highlighter\Matcher\RegexMatcher;
20
use Kadet\Highlighter\Parser\Rule;
21
22
class Ini extends GreedyLanguage
23
{
24
    /**
25
     * Tokenization rules
26
     */
27
    public function setupRules()
28
    {
29
        $this->rules->addMany([
30
            'comment'        => new Rule(new CommentMatcher([';'], [])),
31
            'symbol.section' => new Rule(new RegexMatcher('/(\[.*?])/i')),
32
            'variable'       => new Rule(new RegexMatcher('/([\.\w]+)\s*=/i')),
33
            'number'         => new Rule(new RegexMatcher('/(-?\d+)/i')),
34
35
            'string' => new Rule(new RegexMatcher('/=\h*(.*?)\R/i')),
36
        ]);
37
    }
38
39
    /** @inheritdoc */
40 1
    public function getIdentifier()
41
    {
42 1
        return 'ini';
43
    }
44
45 View Code Duplication
    public static function getMetadata()
46
    {
47
        return [
48
            'name'      => ['ini'],
49
            'mime'      => ['text/x-ini', 'text/inf'],
50
            'extension' => ['*.ini', '*.cfg', '*.inf']
51
        ];
52
    }
53
}
54