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

Cpp   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 18.6 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 8
loc 43
rs 10
wmc 3
lcom 1
cbo 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
B setupRules() 0 26 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
19
use Kadet\Highlighter\Matcher\RegexMatcher;
20
use Kadet\Highlighter\Matcher\WordMatcher;
21
use Kadet\Highlighter\Parser\Rule;
22
use Kadet\Highlighter\Parser\Token\Token;
23
24
class Cpp extends C
25
{
26
    public function setupRules()
27
    {
28
        parent::setupRules();
29
30
        $this->rules->remove('symbol.type', 0); // symbol.type[0] stands for universal type matching in arguments
31
32
        $this->rules->rule('keyword')->setMatcher(new WordMatcher([
33
            'auto', 'align(?:as|of)', 'and(?:_eq)?', 'asm', 'auto', 'bit(and|or)', 'break', 'case', 'catch', 'class',
34
            'compl', 'concept', 'const(?:_cast|expr)?', 'continue', 'decltype', 'default', 'delete', 'do', 'double',
35
            'dynamic_cast', 'else', 'enum', 'explicit', 'export', 'extern', 'for', 'friend', 'goto', 'if', 'inline',
36
            'mutable', 'namespace', 'new', 'noexcept', 'not(?:_eq|ptr)', 'operator', 'or(?:_eq)?', 'private',
37
            'protected', 'public', 'register', 'reinterpret_cast', 'requires', 'return', 'sizeof',
38
            'static(?:_assert|_cast)?', 'struct', 'switch', 'template', 'thread_local', 'throw', 'try', 'typedef',
39
            'typeid', 'typename', 'union', 'using', 'virtual', 'volatile', 'while', 'xor(?:_eq)?',
40
        ], ['escape' => false]));
41
42
        $this->rules->add('symbol.type', new Rule(new WordMatcher(['bool', 'wchar'])));
43
        $this->rules->add('constant.special', new Rule(new WordMatcher(['false', 'null', 'true'])));
44
        $this->rules->add('symbol.class', new Rule(new RegexMatcher('/(\w+)(?:\s+|\s*[*&]\s*)\w+\s*[={}();,]/')));
45
        $this->rules->add('symbol.class.template', new Rule(new RegexMatcher('/(\w+)\s*<.*?>/')));
46
47
        $this->rules->add('symbol.namespace', new Rule(new RegexMatcher('/((?::)?(\w+::)+)(\w+)/', [
48
            1 => Token::NAME,
49
            2 => 'symbol.class'
50
        ])));
51
    }
52
53
    public function getIdentifier()
54
    {
55
        return 'cpp';
56
    }
57
58 View Code Duplication
    public static function getMetadata()
59
    {
60
        return [
61
            'name'      => ['cpp', 'c++'],
62
            'mime'      => ['text/x-c++src', 'text/x-c++hdr'],
63
            'extension' => ['*.cpp', '*.hpp', '*.hxx', '*.cxx', '*.cc', '*.hh']
64
        ];
65
    }
66
}
67