Passed
Push — master ( 6aac40...a9afb4 )
by Kacper
05:32
created

UnifiedDiff::setupRules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 23
ccs 0
cts 17
cp 0
crap 2
rs 9.552
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\CommentMatcher;
19
use Kadet\Highlighter\Matcher\RegexMatcher;
20
use Kadet\Highlighter\Parser\Rule;
21
use Kadet\Highlighter\Parser\Token\Token;
22
23
class UnifiedDiff extends GreedyLanguage
24
{
25
    /**
26
     * Tokenization rules
27
     */
28
    public function setupRules()
29
    {
30
        $this->rules->addMany([
31
            'delimiter'      => new Rule(new RegexMatcher("/^(@@ .+? @@)(.*)$/mi", [
32
                1 => Token::NAME,
33
                2 => 'comment'
34
            ])),
35
            'annotation.diff' => [
36
                'add' => new Rule(new RegexMatcher('/^(\+\+\+\s(.+?))\R/mi', [
37
                    1 => Token::NAME,
38
                    2 => 'symbol.path'
39
                ])),
40
                'remove' => new Rule(new RegexMatcher('/^(---\s(.+?))\R/mi', [
41
                    1 => Token::NAME,
42
                    2 => 'symbol.path'
43
                ])),
44
            ],
45
            'diff' => [
46
                'add'    => new Rule(new RegexMatcher('/^(?:^\+.*$)+/mi', [ 0 => Token::NAME ])),
47
                'remove' => new Rule(new RegexMatcher('/^(?:^-.*$)+/mi', [ 0 => Token::NAME ])),
48
            ],
49
        ]);
50
    }
51
52
    /** @inheritdoc */
53 1
    public function getIdentifier()
54
    {
55 1
        return 'diff';
56
    }
57
58 View Code Duplication
    public static function getMetadata()
59
    {
60
        return [
61
            'name'      => ['diff'],
62
            'mime'      => ['text/x-diff', 'text/x-patch', 'application/x-patch', 'application/x-diff'],
63
            'extension' => ['*.patch', '*.diff']
64
        ];
65
    }
66
}
67