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

ContextualToken   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 51
Duplicated Lines 27.45 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 92.86%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 2
cbo 2
dl 14
loc 51
rs 10
ccs 26
cts 28
cp 0.9286

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A isEnd() 0 4 1
A isStart() 0 4 1
B validate() 14 30 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}