1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the mo4-coding-standard (phpcs standard) |
5
|
|
|
* |
6
|
|
|
* PHP version 5 |
7
|
|
|
* |
8
|
|
|
* @category PHP |
9
|
|
|
* @package PHP_CodeSniffer-MO4 |
10
|
|
|
* @author Xaver Loppenstedt <[email protected]> |
11
|
|
|
* @license http://spdx.org/licenses/MIT MIT License |
12
|
|
|
* @version GIT: master |
13
|
|
|
* @link https://github.com/Mayflower/mo4-coding-standard |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Unit test class for the VariableInDoubleQuotedString sniff. |
18
|
|
|
* |
19
|
|
|
* A sniff unit test checks a .inc file for expected violations of a single |
20
|
|
|
* coding standard. Expected errors and warnings are stored in this class. |
21
|
|
|
* |
22
|
|
|
* @category PHP |
23
|
|
|
* @package PHP_CodeSniffer-MO4 |
24
|
|
|
* @author Xaver Loppenstedt <[email protected]> |
25
|
|
|
* @copyright 2013 Xaver Loppenstedt, some rights reserved. |
26
|
|
|
* @license http://spdx.org/licenses/MIT MIT License |
27
|
|
|
* @link https://github.com/Mayflower/mo4-coding-standard |
28
|
|
|
*/ |
29
|
|
|
namespace MO4\Tests\Strings; |
30
|
|
|
|
31
|
|
|
use PHP_CodeSniffer\Exceptions\RuntimeException; |
32
|
|
|
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; |
33
|
|
|
|
34
|
|
View Code Duplication |
class VariableInDoubleQuotedStringUnitTest extends AbstractSniffUnitTest |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Returns the lines where errors should occur. |
40
|
|
|
* |
41
|
|
|
* The key of the array should represent the line number and the value |
42
|
|
|
* should represent the number of errors that should occur on that line. |
43
|
|
|
* |
44
|
|
|
* @param string $testFile test file |
45
|
|
|
* |
46
|
|
|
* @return array<int, int> |
|
|
|
|
47
|
|
|
* @throws RuntimeException |
48
|
|
|
*/ |
49
|
|
|
protected function getErrorList($testFile='') |
50
|
|
|
{ |
51
|
|
|
switch ($testFile) { |
52
|
|
|
case 'VariableInDoubleQuotedStringUnitTest.pass.inc': |
53
|
|
|
return array(); |
54
|
|
|
case 'VariableInDoubleQuotedStringUnitTest.fail.inc': |
55
|
|
|
return array( |
56
|
|
|
3 => 1, |
57
|
|
|
4 => 1, |
58
|
|
|
5 => 2, |
59
|
|
|
6 => 2, |
60
|
|
|
7 => 1, |
61
|
|
|
8 => 1, |
62
|
|
|
9 => 1, |
63
|
|
|
10 => 1, |
64
|
|
|
11 => 1, |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
throw new RuntimeException("Testfile {$testFile} in ".__DIR__." is not handled by ".__CLASS__); |
69
|
|
|
|
70
|
|
|
}//end getErrorList() |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Returns the lines where warnings should occur. |
75
|
|
|
* |
76
|
|
|
* The key of the array should represent the line number and the value |
77
|
|
|
* should represent the number of warnings that should occur on that line. |
78
|
|
|
* |
79
|
|
|
* @return array<int, int> |
|
|
|
|
80
|
|
|
*/ |
81
|
|
|
protected function getWarningList() |
82
|
|
|
{ |
83
|
|
|
return array(); |
84
|
|
|
|
85
|
|
|
}//end getWarningList() |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
}//end class |
89
|
|
|
|
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.