Completed
Branch 0.8-dev (5d9532)
by Kacper
02:49
created

ContextualToken::validate()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 29
Code Lines 19

Duplication

Lines 14
Ratio 48.28 %

Code Coverage

Tests 12
CRAP Score 6.2499

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 14
loc 29
ccs 12
cts 19
cp 0.6316
rs 8.439
cc 5
eloc 19
nc 5
nop 1
crap 6.2499
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