Passed
Push — master ( 42d865...54862f )
by Kacper
03:02
created

LanguageToken::getLanguage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 2
eloc 2
nc 2
nop 0
crap 2
1
<?php
2
/**
3
 * Highlighter
4
 *
5
 * Copyright (C) 2015, 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\Parser\Token;
17
18
use Kadet\Highlighter\Language\Language;
19
20
class LanguageToken extends Token
21
{
22 2
    public function getInjected()
23
    {
24 2
        return $this->getRule()->inject;
25
    }
26
27 11
    public function getLanguage()
28
    {
29 11
        return $this->getStart() ? $this->getStart()->getRule()->inject : $this->getRule()->language;
30
    }
31
32 11
    protected function validate(Language $language, $context)
33
    {
34 11
        $valid = false;
35
36 11
        if ($this->isStart()) {
37 2
            $lang = $this->_rule->language;
38 2
            if ($lang === null && $this->getInjected() !== $language) {
39 1
                $valid = true;
40 2
            } elseif ($language === $lang && $this->_rule->validate($context)) {
41 1
                $valid = true;
42 1
            }
43 2
        } else {
44 11
            $desired = $this->getLanguage();
45 11
            $valid   = $language === $desired && $this->_rule->validate($context);
46
        }
47 11
        $this->setValid($valid);
48 11
    }
49
}
50