Passed
Branch fuck-54 (18c095)
by Kacper
03:37
created

ContextualToken   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 36.84 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 91.3%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
c 2
b 0
f 0
lcom 1
cbo 2
dl 14
loc 38
ccs 21
cts 23
cp 0.913
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 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 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
}