Completed
Pull Request — master (#171)
by Juliette
03:06
created

dataNoViolation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 12

Duplication

Lines 15
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 15
loc 15
rs 9.4285
cc 1
eloc 12
nc 1
nop 0
1
<?php
2
/**
3
 * Forbidden break and continue variable arguments sniff test file
4
 *
5
 * @package PHPCompatibility
6
 */
7
8
9
/**
10
 * Forbidden break and continue variable arguments sniff test
11
 *
12
 * Checks for using break and continue with a variable afterwards
13
 *     break $varname
14
 *     continue $varname
15
 *
16
 * @uses BaseSniffTest
17
 * @package PHPCompatibility
18
 * @author Jansen Price <[email protected]>
19
 */
20
class ForbiddenBreakContinueVariableArgumentsSniffTest 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...
21
{
22
    const TEST_FILE = 'sniff-examples/forbidden_break_continue_variable_argument.php';
23
24
    /**
25
     * Sniffed file
26
     *
27
     * @var PHP_CodeSniffer_File
28
     */
29
    protected $_sniffFile;
30
31
    /**
32
     * setUp
33
     *
34
     * @return void
35
     */
36
    public function setUp()
37
    {
38
        parent::setUp();
39
40
        $this->_sniffFile = $this->sniffFile(self::TEST_FILE);
41
    }
42
43
44
    /**
45
     * testAllowedBreakAndContinueVariableArgument
46
     *
47
     * In PHP 5.3, none of the statements should give an error.
48
     *
49
     * @group forbiddenBreakContinue
50
     *
51
     * @return void
52
     */
53
    public function testAllowedBreakAndContinueVariableArgument()
54
    {
55
        $file = $this->sniffFile(self::TEST_FILE, '5.3');
56
        $this->assertNoViolation($file);
57
    }
58
59
60
    /**
61
     * testBreakAndContinueVariableArgument
62
     *
63
     * @group forbiddenBreakContinue
64
     *
65
     * @dataProvider dataBreakAndContinueVariableArgument
66
     *
67
     * @param int $line The line number.
68
     *
69
     * @return void
70
     */
71
    public function testBreakAndContinueVariableArgument($line)
72
    {
73
        $this->assertError($this->_sniffFile, $line, 'Using a variable argument on break or continue is forbidden since PHP 5.4');
74
    }
75
76
    /**
77
     * Data provider.
78
     *
79
     * @see testBreakAndContinueVariableArgument()
80
     *
81
     * @return array
82
     */
83 View Code Duplication
    public function dataBreakAndContinueVariableArgument()
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...
84
    {
85
        return array(
86
            array(53),
87
            array(57),
88
            array(62),
89
            array(66),
90
            array(71),
91
            array(75),
92
            array(80),
93
            array(84),
94
            array(89),
95
            array(93),
96
            array(98),
97
            array(102),
98
        );
99
    }
100
101
102
    /**
103
     * testNoViolation
104
     *
105
     * @group forbiddenBreakContinue
106
     *
107
     * @dataProvider dataNoViolation
108
     *
109
     * @param int $line The line number.
110
     *
111
     * @return void
112
     */
113
    public function testNoViolation($line)
114
    {
115
        $this->assertNoViolation($this->_sniffFile, $line);
116
    }
117
118
    /**
119
     * Data provider.
120
     *
121
     * @see testNoViolation()
122
     *
123
     * @return array
124
     */
125 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...
126
    {
127
        return array(
128
            array(8),
129
            array(12),
130
            array(17),
131
            array(21),
132
            array(26),
133
            array(30),
134
            array(35),
135
            array(39),
136
            array(44),
137
            array(48),
138
        );
139
    }
140
}
141
142