Passed
Branch 0.8-dev (5da63a)
by Kacper
02:47
created

ContextualToken::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 1
1
<?php
2
/**
3
 * Highlighter
4
 *1
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\Parser\Token;
17
18
use Kadet\Highlighter\Parser\Context;
19
use Kadet\Highlighter\Parser\Validator\Validator;
20
21
class ContextualToken extends Token
22
{
23 3
    protected function validate(Context $context)
24
    {
25 3
        if ($context->language !== $this->rule->language) {
26 1
            $this->setValid(false);
27
28 1
            return false;
29
        }
30
31 2
        if (!$context->has($this->name)) {
32 2 View Code Duplication
            if (!$this->rule->validator->validate($context)) {
33 1
                $this->setValid(false);
34 1
            } else {
35 1
                $this->_valid       = true;
36 1
                $this->_end->_valid = false;
37
            }
38 2 View Code Duplication
        } else {
39 2
            if (!$this->rule->validator->validate($context, [ $this->name => Validator::CONTEXT_IN ])) {
40 1
                $this->setValid(false);
41 1
            } else {
42 1
                $this->_valid       = false;
43 1
                $this->_end->_valid = true;
44
            }
45
        }
46
47 2
        $this->_end->_start = false;
48 2
        $this->_end         = false;
49
50 2
        return true;
51
    }
52
}
53