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

ContextualToken::validate()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 31
Code Lines 20

Duplication

Lines 14
Ratio 45.16 %

Code Coverage

Tests 20
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 14
loc 31
ccs 20
cts 20
cp 1
rs 8.439
cc 5
eloc 20
nc 5
nop 2
crap 5
1
<?php
2
/**
3
 * Highlighter
4
 *1
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
use Kadet\Highlighter\Parser\Rule;
20
21
class ContextualToken extends Token
22
{
23 3
    public function __construct($options)
24
    {
25 3
        parent::__construct($options);
26 3
    }
27
28 3
    protected function validate(Language $language, $context)
29
    {
30 3
        if ($language !== $this->getRule()->language) {
31 2
            $this->setValid(false);
32
33 2
            return false;
34
        }
35
36 3
        $start = !in_array($this->name, $context, false);
37
38 3
        if ($start) {
39 2 View Code Duplication
            if (!$this->getRule()->validate($context)) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40 1
                $this->setValid(false);
41 1
            } else {
42 1
                $this->_valid       = true;
43 1
                $this->_end->_valid = false;
44
            }
45 2 View Code Duplication
        } else {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46 2
            if (!$this->getRule()->validate($context, [$this->name => Rule::CONTEXT_IN])) {
47 1
                $this->setValid(false);
48 1
            } else {
49 1
                $this->_valid       = false;
50 1
                $this->_end->_valid = true;
51
            }
52
        }
53
54 3
        $this->_end->_start = false;
55 3
        $this->_end         = false;
56
57 3
        return true;
58
    }
59
}
60