Passed
Push — master ( 1ee19c...3e5a10 )
by Kacper
02:56
created

PreProcessor   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
c 1
b 0
f 0
lcom 0
cbo 4
dl 0
loc 29
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getRules() 0 21 1
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\Css;
17
18
19
use Kadet\Highlighter\Language\Css;
20
use Kadet\Highlighter\Matcher\CommentMatcher;
21
use Kadet\Highlighter\Matcher\SubStringMatcher;
22
use Kadet\Highlighter\Parser\Rule;
23
24
abstract class PreProcessor extends Css
25
{
26
    /**
27
     * Tokenization rules
28
     *
29
     * @return \Kadet\Highlighter\Parser\Rule[]|\Kadet\Highlighter\Parser\Rule[][]
30
     */
31
    public function getRules()
32
    {
33
        $rules = parent::getRules();
34
35
        $rules['symbol.selector.class']->setContext(['!symbol', '!string', '!number', '!comment']);
36
        $rules['symbol.selector.tag']->setContext(['!symbol', '!string', '!number', '!comment']);
37
        $rules['symbol.selector.class.pseudo']->setContext(['!symbol', '!string', '!number', '!comment']);
38
        $rules['symbol.selector.id']->setContext(['!symbol', '!string', '!constant', '!comment']);
39
        $rules['constant.color']->setContext(['!string', '!symbol', '!comment']);
40
41
        $rules['operator.self'] = new Rule(new SubStringMatcher('&'), ['context' => $this->everywhere()]);
42
        $rules['number']->setContext(['!comment', '!symbol', '!constant', '!string', '!variable']);
43
        $rules['call'] ->setContext(['!comment', '!symbol', '!constant', '!string']);
44
45
        $rules['comment'] = [
46
            $rules['comment'],
47
            new Rule(new CommentMatcher(['//'], []), ['context' => $rules['comment']->validator])
48
        ];
49
50
        return $rules;
51
    }
52
}