Completed
Branch 0.8-dev (5d9532)
by Kacper
02:49
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 1
    public function __construct($name, $options = [])
24
    {
25 1
        parent::__construct($name, $options);
26 1
    }
27
28 1
    protected function validate(Context $context)
29
    {
30 1
        if ($context->language !== $this->rule->language) {
31 1
            $this->setValid(false);
32
33 1
            return false;
34
        }
35
36 1
        if (!$context->has($this->name)) {
37 1 View Code Duplication
            if (!$this->rule->validator->validate($context)) {
38 1
                $this->setValid(false);
39 1
            } else {
40
                $this->_valid       = true;
41
                $this->_end->_valid = false;
42
            }
43 1 View Code Duplication
        } else {
44
            if (!$this->rule->validator->validate($context, [ $this->name => Validator::CONTEXT_IN ])) {
45
                $this->setValid(false);
46
            } else {
47
                $this->_valid       = false;
48
                $this->_end->_valid = true;
49
            }
50
        }
51
52 1
        $this->_end->_start = false;
53 1
        $this->_end         = false;
54
55 1
        return true;
56
    }
57
}
58