Completed
Pull Request — master (#212)
by Juliette
02:58
created

EmptyNonVariableSniffTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 121
Duplicated Lines 58.68 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 4
c 2
b 1
f 1
lcom 1
cbo 1
dl 71
loc 121
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testEmptyNonVariable() 8 8 1
A testNoViolation() 0 5 1
B dataEmptyNonVariable() 31 31 1
B dataNoViolation() 32 32 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
 * Empty with non variable sniff test file
4
 *
5
 * @package PHPCompatibility
6
 */
7
8
9
/**
10
 * Empty with non variable sniff test file
11
 *
12
 * @uses    BaseSniffTest
13
 * @package PHPCompatibility
14
 * @author  Juliette Reinders Folmer <[email protected]>
15
 */
16
class EmptyNonVariableSniffTest extends BaseSniffTest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
17
{
18
    const TEST_FILE = 'sniff-examples/empty_non_variable.php';
19
20
    /**
21
     * testEmptyNonVariable
22
     *
23
     * @group emptyNonVariable
24
     *
25
     * @dataProvider dataEmptyNonVariable
26
     *
27
     * @param int $line The line number.
28
     *
29
     * @return void
30
     */
31 View Code Duplication
    public function testEmptyNonVariable($line)
0 ignored issues
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...
32
    {
33
        $file = $this->sniffFile(self::TEST_FILE, '5.4');
34
        $this->assertError($file, $line, 'Only variables can be passed to empty() prior to PHP 5.5.');
35
36
        $file = $this->sniffFile(self::TEST_FILE, '5.5');
37
        $this->assertNoViolation($file, $line);
38
    }
39
40
    /**
41
     * Data provider.
42
     *
43
     * @see testEmptyNonVariable()
44
     *
45
     * @return array
46
     */
47 View Code Duplication
    public function dataEmptyNonVariable()
0 ignored issues
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...
48
    {
49
        return array(
50
            array(17),
51
            array(18),
52
53
            array(20),
54
            array(21),
55
            array(22),
56
            array(23),
57
58
            array(25),
59
            array(26),
60
            array(27),
61
            array(28),
62
            array(29),
63
            array(30),
64
            array(31),
65
            array(32),
66
67
            array(34),
68
            array(35),
69
            array(37),
70
            array(38),
71
            array(39),
72
            array(40),
73
74
            array(42),
75
            array(43),
76
        );
77
    }
78
79
80
    /**
81
     * testNoViolation
82
     *
83
     * @group emptyNonVariable
84
     *
85
     * @dataProvider dataNoViolation
86
     *
87
     * @param int $line The line number.
88
     *
89
     * @return void
90
     */
91
    public function testNoViolation($line)
92
    {
93
        $file = $this->sniffFile(self::TEST_FILE, '5.3');
94
        $this->assertNoViolation($file, $line);
95
    }
96
97
    /**
98
     * Data provider.
99
     *
100
     * @see testNoViolation()
101
     *
102
     * @return array
103
     */
104 View Code Duplication
    public function dataNoViolation()
0 ignored issues
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...
105
    {
106
        return array(
107
            array(4),
108
            array(5),
109
            array(6),
110
            array(7),
111
            array(8),
112
            array(9),
113
            array(10),
114
            array(11),
115
            array(12),
116
            array(13),
117
            array(14),
118
119
            // Issue #210.
120
            array(47),
121
            array(48),
122
            array(49),
123
            array(50),
124
            array(51),
125
            array(52),
126
            array(53),
127
            array(54),
128
            array(55),
129
            array(56),
130
            array(57),
131
132
            // Live coding.
133
            array(61),
134
        );
135
    }
136
}
137