Completed
Push — master ( 514dbf...ba76d3 )
by Wim
11s
created

NewFunctionArrayDereferencingSniffTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 56
Duplicated Lines 32.14 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 18
loc 56
rs 10
c 0
b 0
f 0

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
 * New function array dereferencing sniff test file
4
 *
5
 * @package PHPCompatibility
6
 */
7
8
9
/**
10
 * New function array dereferencing sniff tests
11
 *
12
 * @uses BaseSniffTest
13
 * @package PHPCompatibility
14
 * @author Wim Godden <[email protected]>
15
 */
16
class NewFunctionArrayDereferencingSniffTest extends BaseSniffTest
17
{
18
    const TEST_FILE = 'sniff-examples/new_function_array_dereferencing.php';
19
20
    /**
21
     * testArrayDereferencing
22
     *
23
     * @group functionArrayDereferencing
24
     *
25
     * @return void
26
     */
27
    public function testArrayDereferencing()
28
    {
29
        $file = $this->sniffFile(self::TEST_FILE, '5.3');
30
        $this->assertError($file, 3, 'Function array dereferencing is not present in PHP version 5.3 or earlier');
31
32
        $file = $this->sniffFile(self::TEST_FILE, '5.4');
33
        $this->assertNoViolation($file, 3);
34
    }
35
36
37
    /**
38
     * testNoViolation
39
     *
40
     * @group functionArrayDereferencing
41
     *
42
     * @dataProvider dataNoViolation
43
     *
44
     * @param int $line Line number with valid code.
45
     *
46
     * @return void
47
     */
48
    public function testNoViolation($line)
49
    {
50
        $file = $this->sniffFile(self::TEST_FILE, '5.2');
51
        $this->assertNoViolation($file, $line);
52
    }
53
54
    /**
55
     * dataNoViolation
56
     *
57
     * @see testNoViolation()
58
     *
59
     * @return array
60
     */
61
    public function dataNoViolation() {
62
        return array(
63
            array(5),
64
            array(8),
65
            array(9),
66
            array(10),
67
            array(11),
68
            array(14),
69
        );
70
    }
71
}
72