Passed
Branch fuck-54 (18c095)
by Kacper
03:37
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 1
crap 1
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;
17
18
19
use Kadet\Highlighter\Language\Language;
20
21
class ContextualToken extends Token
22
{
23 2
    public function __construct($options)
24
    {
25 2
        parent::__construct($options);
26 2
    }
27
28 2
    protected function validate(Language $language, $context)
29
    {
30 2
        if($language !== $this->getRule()->language) {
31 1
            $this->setValid(false);
32 1
            return false;
33
        }
34
35 2
        $start = !in_array($this->name, $context, false);
36
37 2
        if ($start) {
38 2 View Code Duplication
            if (!$this->getRule()->validateContext($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...
39 1
                $this->setValid(false);
40 1
            } else {
41 1
                $this->_valid = true;
42 1
                $this->_end->_valid = false;
43
            }
44 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...
45 1
            if (!$this->getRule()->validateContext($context, [$this->name => Rule::CONTEXT_IN])) {
46
                $this->setValid(false);
47
            } else {
48 1
                $this->_valid = false;
49 1
                $this->_end->_valid = true;
50
            }
51
        }
52
53 2
        $this->_end->_start = false;
0 ignored issues
show
Documentation Bug introduced by
It seems like false of type false is incompatible with the declared type object<Kadet\Highlighter\Parser\Token> of property $_start.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
54 2
        $this->_end = false;
0 ignored issues
show
Documentation Bug introduced by
It seems like false of type false is incompatible with the declared type object<Kadet\Highlighter\Parser\Token> of property $_end.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
55
56 2
        return true;
57
    }
58
}