Completed
Push — master ( 947530...274bb9 )
by Kacper
02:22
created

TokenTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 65
Duplicated Lines 24.62 %

Coupling/Cohesion

Components 2
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 2
cbo 5
dl 16
loc 65
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testCreation() 0 10 1
A testCreationWithStart() 8 8 1
A testCreationWithEnd() 8 8 1
A testCreationWithLength() 0 6 1
A testLength() 0 6 1
A testIsStart() 0 8 1
A testIsEnd() 0 10 1

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
 *
5
 * Copyright (C) 2016, 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\Tests;
17
18
19
use Kadet\Highlighter\Parser\CloseRule;
20
use Kadet\Highlighter\Parser\OpenRule;
21
use Kadet\Highlighter\Parser\Rule;
22
use Kadet\Highlighter\Parser\Token;
23
24
class TokenTest extends \PHPUnit_Framework_TestCase
25
{
26
    public function testCreation()
27
    {
28
        $rule  = new Rule();
29
        $token = new Token(['test.name', 'pos' => 10, 'index' => 10, 'rule' => $rule]);
30
31
        $this->assertEquals($token->name, 'test.name', 'Token name is invalid');
32
        $this->assertEquals($token->pos, 10, 'Position is invalid');
33
        $this->assertEquals($token->index, 10, 'Index is invalid');
34
        $this->assertEquals($token->getRule(), $rule, 'Rule is invalid');
35
    }
36
37 View Code Duplication
    public function testCreationWithStart()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in 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...
38
    {
39
        $start = new Token(['test.name', 'pos' => 5]);
40
        $token = new Token(['test.name', 'pos' => 10, 'start' => $start]);
41
42
        $this->assertEquals($token->getStart(), $start, 'Token is not pointing to start.');
43
        $this->assertEquals($start->getEnd(), $token, 'Start is not pointing to token.');
44
    }
45
46 View Code Duplication
    public function testCreationWithEnd()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in 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...
47
    {
48
        $end   = new Token(['test.name', 'pos' => 15]);
49
        $token = new Token(['test.name', 'pos' => 10, 'end' => $end]);
50
51
        $this->assertEquals($token->getEnd(), $end, 'Token is not pointing to end.');
52
        $this->assertEquals($end->getStart(), $token, 'End is not pointing to token.');
53
    }
54
55
    public function testCreationWithLength()
56
    {
57
        $token = new Token(['test.name', 'pos' => 15, 'length' => 10]);
58
59
        $this->assertEquals($token->getEnd()->pos, 25, 'Token is not pointing to end.');
60
    }
61
62
    public function testLength()
63
    {
64
        $token = new Token(['test.name', 'pos' => 15, 'length' => 10]);
65
66
        $this->assertEquals($token->getLength(), 10, 'Length is invalid');
67
    }
68
69
    public function testIsStart()
70
    {
71
        $token = new Token(['test.name', 'pos' => 10]);
72
        $close = new Token(['test.name', 'pos' => 10, 'rule' => new CloseRule()]);
73
74
        $this->assertTrue($token->isStart());
75
        $this->assertFalse($close->isStart());
76
    }
77
78
    public function testIsEnd()
79
    {
80
        $token = new Token(['test.name', 'pos' => 15]);
81
        new Token(['test.name', 'pos' => 10, 'end' => $token]);
82
83
        $close = new Token(['test.name', 'pos' => 10, 'rule' => new OpenRule()]);
84
85
        $this->assertTrue($token->isEnd());
86
        $this->assertFalse($close->isEnd());
87
    }
88
}
89