Passed
Push — master ( 05f929...203740 )
by Kacper
03:48 queued 01:02
created

ContextualToken::isEnd()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
ccs 2
cts 2
cp 1
cc 1
eloc 2
nc 1
nop 0
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
    private $_type;
24
25 2
    public function __construct($options)
26
    {
27 2
        parent::__construct($options);
28 2
        $this->_type = parent::isStart();
29 2
    }
30
31 1
    public function isEnd()
32
    {
33 1
        return !$this->_type;
34
    }
35
36 1
    public function isStart()
37
    {
38 1
        return $this->_type;
39
    }
40
41 2
    protected function validate(Language $language, $context)
42
    {
43 2
        if($language !== $this->getRule()->language) {
44 1
            $this->setValid(false);
45 1
            return false;
46
        }
47
48 2
        $start = !in_array($this->name, $context, false);
49
50 2
        if ($start) {
51 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...
52 1
                $this->setValid(false);
53 1
            } else {
54 1
                $this->_valid = true;
55 1
                $this->_end->_valid = false;
56
            }
57 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...
58 1
            if (!$this->getRule()->validateContext($context, [$this->name => Rule::CONTEXT_IN])) {
59
                $this->setValid(false);
60
            } else {
61 1
                $this->_valid = false;
62 1
                $this->_end->_valid = true;
63
            }
64
        }
65
66 2
        $this->_end->_start = null;
67 2
        $this->_end = null;
68
69 2
        return true;
70
    }
71
}