LuaInputStreamTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 68
Duplicated Lines 51.47 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 35
loc 68
c 0
b 0
f 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testSimpleNext() 0 4 1
A testMultipleLines() 9 9 1
A testSimpleError() 0 6 1
A testMultipleLineError() 8 8 1
A testMultipleColumnError() 7 7 1
A testMultipleLineAndColumnError() 11 11 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
namespace Vlaswinkel\Lua\Tests;
4
5
use Vlaswinkel\Lua\InputStream;
6
7
/**
8
 * Class LuaInputStreamTest
9
 *
10
 * @author  Koen Vlaswinkel <[email protected]>
11
 * @package Vlaswinkel\Lua\Tests
12
 */
13
class LuaInputStreamTest extends \PHPUnit_Framework_TestCase {
14
    public function testSimpleNext() {
15
        $obj = new InputStream("a");
16
        $this->assertEquals("a", $obj->next());
17
    }
18
19 View Code Duplication
    public function testMultipleLines() {
20
        $obj = new InputStream("a\nb\n");
21
22
        $this->assertEquals("a", $obj->next());
23
        $this->assertEquals("\n", $obj->next());
24
        $this->assertEquals("b", $obj->next());
25
        $this->assertEquals("\n", $obj->next());
26
        $this->assertTrue($obj->eof());
27
    }
28
29
    /**
30
     * @expectedException \Vlaswinkel\Lua\ParseException
31
     * @expectedExceptionMessage Simple error (1:1)
32
     */
33
    public function testSimpleError() {
34
        $obj = new InputStream("a");
35
        $this->assertEquals("a", $obj->next());
36
37
        $obj->error("Simple error");
38
    }
39
40
    /**
41
     * @expectedException \Vlaswinkel\Lua\ParseException
42
     * @expectedExceptionMessage Other error (2:1)
43
     */
44 View Code Duplication
    public function testMultipleLineError() {
45
        $obj = new InputStream("a\nb");
46
        $this->assertEquals("a", $obj->next());
47
        $this->assertEquals("\n", $obj->next());
48
        $this->assertEquals("b", $obj->next());
49
50
        $obj->error("Other error");
51
    }
52
53
    /**
54
     * @expectedException \Vlaswinkel\Lua\ParseException
55
     * @expectedExceptionMessage This error (1:2)
56
     */
57 View Code Duplication
    public function testMultipleColumnError() {
58
        $obj = new InputStream("ab");
59
        $this->assertEquals("a", $obj->next());
60
        $this->assertEquals("b", $obj->next());
61
62
        $obj->error("This error");
63
    }
64
65
    /**
66
     * @expectedException \Vlaswinkel\Lua\ParseException
67
     * @expectedExceptionMessage Complex error (2:2)
68
     */
69 View Code Duplication
    public function testMultipleLineAndColumnError() {
70
        $obj = new InputStream("ab\nab\n");
71
        $this->assertEquals("a", $obj->next());
72
        $this->assertEquals("b", $obj->next());
73
        $this->assertEquals("\n", $obj->next());
74
75
        $this->assertEquals("a", $obj->next());
76
        $this->assertEquals("b", $obj->next());
77
78
        $obj->error("Complex error");
79
    }
80
}