Failed Conditions
Push — phpcs-3-upgrade ( d91341 )
by Alexander
02:06
created

ControlStructureSpacingUnitTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 312
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 312
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
B getErrorList() 0 281 3
A getWarningList() 0 4 1
1
<?php
2
/**
3
 * CodingStandard_Tests_WhiteSpace_ControlStructureSpacingUnitTest.
4
 *
5
 * PHP version 5
6
 *
7
 * @category PHP
8
 * @package  PHP_CodeSniffer
9
 * @author   Alexander Obuhovich <[email protected]>
10
 * @license  https://github.com/aik099/CodingStandard/blob/master/LICENSE BSD 3-Clause
11
 * @link     https://github.com/aik099/CodingStandard
12
 */
13
14
namespace CodingStandard\Tests\WhiteSpace;
15
16
use TestSuite\AbstractSniffUnitTest;
17
18
/**
19
 * Unit test class for the ControlStructureSpacing sniff.
20
 *
21
 * @category PHP
22
 * @package  PHP_CodeSniffer
23
 * @author   Alexander Obuhovich <[email protected]>
24
 * @license  https://github.com/aik099/CodingStandard/blob/master/LICENSE BSD 3-Clause
25
 * @link     https://github.com/aik099/CodingStandard
26
 */
27
class ControlStructureSpacingUnitTest extends AbstractSniffUnitTest
28
{
29
30
31
    /**
32
     * Returns the lines where errors should occur.
33
     *
34
     * The key of the array should represent the line number and the value
35
     * should represent the number of errors that should occur on that line.
36
     *
37
     * @param string $testFile Name of the file with test data.
38
     *
39
     * @return array(int => int)
40
     */
41
    public function getErrorList($testFile)
42
    {
43
        if ($testFile === 'ControlStructureSpacingUnitTest.1.inc') {
44
            return array(
45
                // IF (condition spacing, blank line at the scope edges).
46
                77   => 3,
47
                81   => 1,
48
                82   => 3,
49
                86   => 1,
50
                87   => 3,
51
                91   => 1,
52
                92   => 1,
53
                96   => 1,
54
                98   => 3,
55
                102  => 1,
56
                103  => 3,
57
                107  => 1,
58
                108  => 3,
59
                112  => 1,
60
                114  => 3,
61
                118  => 1,
62
                119  => 3,
63
                123  => 1,
64
                124  => 1,
65
                128  => 1,
66
                130  => 3,
67
                134  => 1,
68
                135  => 1,
69
                139  => 1,
70
                141  => 3,
71
                145  => 1,
72
                // WHILE (condition spacing, blank line at the scope edges).
73
                147  => 3,
74
                151  => 1,
75
                // DO (condition spacing, blank line at the scope edges).
76
                153  => 1,
77
                157  => 3,
78
                // FOREACH (condition spacing, blank line at the scope edges).
79
                159  => 3,
80
                163  => 1,
81
                165  => 3,
82
                169  => 1,
83
                // FOR (condition spacing, blank line at the scope edges).
84
                171  => 3,
85
                175  => 1,
86
                // SWITCH (condition spacing, blank line at the scope edges).
87
                177  => 3,
88
                181  => 1,
89
                // TRY/CATCH (condition spacing, blank line at the scope edges).
90
                183  => 1,
91
                187  => 1,
92
                188  => 3,
93
                192  => 1,
94
95
                // IF (empty control structure).
96
                194  => 1,
97
                197  => 1,
98
                200  => 1,
99
                203  => 1,
100
                207  => 1,
101
                210  => 1,
102
                213  => 1,
103
                217  => 1,
104
                220  => 1,
105
                223  => 1,
106
                227  => 1,
107
                230  => 1,
108
                234  => 1,
109
                // WHILE (empty control structure).
110
                238  => 1,
111
                // DO (empty control structure).
112
                242  => 1,
113
                // FOREACH (empty control structure).
114
                246  => 1,
115
                250  => 1,
116
                // FOR (empty control structure).
117
                254  => 1,
118
                // SWITCH (empty control structure).
119
                258  => 1,
120
                // TRY/CATCH (empty control structure).
121
                262  => 1,
122
                265  => 1,
123
124
                // IF (empty line before/after within "case").
125
                474  => 1,
126
                485  => 1,
127
                491  => 1,
128
                499  => 1,
129
                505  => 1,
130
                513  => 1,
131
                519  => 1,
132
                524  => 1,
133
                530  => 1,
134
                532  => 1,
135
                // WHILE (empty line before/after within "case").
136
                538  => 1,
137
                540  => 1,
138
                // DO (empty line before/after within "case").
139
                546  => 1,
140
                548  => 1,
141
                // FOREACH (empty line before/after within "case").
142
                554  => 1,
143
                556  => 1,
144
                562  => 1,
145
                564  => 1,
146
                // FOR (empty line before/after within "case").
147
                570  => 1,
148
                572  => 1,
149
                // SWITCH (empty line before/after within "case").
150
                578  => 1,
151
                580  => 1,
152
                // TRY/CATCH (empty line before/after within "case").
153
                586  => 1,
154
                591  => 1,
155
156
                // IF (empty line before/after within "default").
157
                599  => 1,
158
                610  => 1,
159
                616  => 1,
160
                624  => 1,
161
                630  => 1,
162
                638  => 1,
163
                644  => 1,
164
                649  => 1,
165
                655  => 1,
166
                657  => 1,
167
                // WHILE (empty line before/after within "default").
168
                663  => 1,
169
                665  => 1,
170
                // DO (empty line before/after within "default").
171
                671  => 1,
172
                673  => 1,
173
                // FOREACH (empty line before/after within "default").
174
                679  => 1,
175
                681  => 1,
176
                687  => 1,
177
                689  => 1,
178
                // FOR (empty line before/after within "default").
179
                695  => 1,
180
                697  => 1,
181
                // SWITCH (empty line before/after within "default").
182
                703  => 1,
183
                705  => 1,
184
                // TRY/CATCH (empty line before/after within "default").
185
                711  => 1,
186
                716  => 1,
187
188
                // IF (no blank line before/after).
189
                722  => 1,
190
                733  => 1,
191
                735  => 1,
192
                743  => 1,
193
                745  => 1,
194
                753  => 1,
195
                755  => 1,
196
                760  => 1,
197
                762  => 1,
198
                764  => 1,
199
                // WHILE (no blank line before/after).
200
                766  => 1,
201
                768  => 1,
202
                // DO (no blank line before/after).
203
                770  => 1,
204
                772  => 1,
205
                // FOREACH (no blank line before/after).
206
                774  => 1,
207
                776  => 1,
208
                778  => 1,
209
                780  => 1,
210
                // FOR (no blank line before/after).
211
                782  => 1,
212
                784  => 1,
213
                // SWITCH (no blank line before/after).
214
                786  => 1,
215
                788  => 1,
216
                // TRY/CATCH (no blank line before/after).
217
                790  => 1,
218
                795  => 1,
219
220
                // IF (no blank line before/after inline comment).
221
                1035  => 1,
222
                1046  => 1,
223
                1050  => 1,
224
                1058  => 1,
225
                1062  => 1,
226
                1070  => 1,
227
                1074  => 1,
228
                1079  => 1,
229
                1083  => 1,
230
                1085  => 1,
231
                // WHILE (no blank line before/after inline comment).
232
                1089  => 1,
233
                1091  => 1,
234
                // DO (no blank line before/after inline comment).
235
                1095 => 1,
236
                1097 => 1,
237
                // FOREACH (no blank line before/after inline comment).
238
                1101 => 1,
239
                1103 => 1,
240
                1107 => 1,
241
                1109 => 1,
242
                // FOR (no blank line before/after inline comment).
243
                1113 => 1,
244
                1115 => 1,
245
                // SWITCH (no blank line before/after inline comment).
246
                1119 => 1,
247
                1121 => 1,
248
                // TRY/CATCH (no blank line before/after inline comment).
249
                1125 => 1,
250
                1130 => 1,
251
252
                // ELSE/ELSEIF not on own line.
253
                1265 => 1,
254
                1267 => 1,
255
256
                // CATCH not on own line.
257
                1273 => 1,
258
259
                // Content after opening brace.
260
                1277 => 1,
261
                1280 => 1,
262
                1283 => 1,
263
                1286 => 1,
264
                1290 => 1,
265
                1294 => 1,
266
                1298 => 1,
267
                1302 => 1,
268
                1306 => 1,
269
                1310 => 1,
270
                1313 => 1,
271
272
                // No empty line after control structure before "return" in "switch > case".
273
                1512 => 1,
274
                1521 => 1,
275
                1533 => 1,
276
                1542 => 1,
277
                1548 => 1,
278
                1554 => 1,
279
                1560 => 1,
280
                1566 => 1,
281
                1572 => 1,
282
                1578 => 1,
283
                1587 => 1,
284
285
                // No empty line after control structure before "return" in "switch > default".
286
                1596 => 1,
287
                1605 => 1,
288
                1617 => 1,
289
                1626 => 1,
290
                1632 => 1,
291
                1638 => 1,
292
                1644 => 1,
293
                1650 => 1,
294
                1656 => 1,
295
                1662 => 1,
296
                1671 => 1,
297
298
                // Sequential catch statements not indented right.
299
                1690 => 1,
300
               );
301
        } elseif ($testFile === 'ControlStructureSpacingUnitTest.2.inc') {
302
            return array(
303
                // Blank line at start/end of control structure.
304
                3  => 1,
305
                11 => 1,
306
307
                // Blank lines around nested control structure.
308
                16 => 1,
309
                18 => 1,
310
311
                // Blank line after control structure.
312
                29 => 1,
313
                43 => 1,
314
315
                // Blank line at end of control structure.
316
                47 => 1,
317
            );
318
        }
319
320
        return array();
321
    }//end getErrorList()
322
323
324
    /**
325
     * Returns the lines where warnings should occur.
326
     *
327
     * The key of the array should represent the line number and the value
328
     * should represent the number of warnings that should occur on that line.
329
     *
330
     * @param string $testFile Name of the file with test data.
331
     *
332
     * @return array(int => int)
333
     */
334
    public function getWarningList($testFile)
335
    {
336
        return array();
337
    }//end getWarningList()
338
}//end class
339