1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* CodingStandard_Sniffs_ControlStructures_ControlSignatureSniff. |
4
|
|
|
* |
5
|
|
|
* PHP version 5 |
6
|
|
|
* |
7
|
|
|
* @category PHP |
8
|
|
|
* @package PHP_CodeSniffer |
9
|
|
|
* @author Greg Sherwood <[email protected]> |
10
|
|
|
* @author Marc McIntyre <[email protected]> |
11
|
|
|
* @author Alexander Obuhovich <[email protected]> |
12
|
|
|
* @license https://github.com/aik099/CodingStandard/blob/master/LICENSE BSD 3-Clause |
13
|
|
|
* @link https://github.com/aik099/CodingStandard |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
// @codeCoverageIgnoreStart |
17
|
|
|
if (class_exists('PHP_CodeSniffer_Standards_AbstractPatternSniff', true) === false) { |
18
|
|
|
$error = 'Class PHP_CodeSniffer_Standards_AbstractPatternSniff not found'; |
19
|
|
|
throw new PHP_CodeSniffer_Exception($error); |
20
|
|
|
} |
21
|
|
|
// @codeCoverageIgnoreEnd |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Verifies that control statements conform to their coding standards. |
25
|
|
|
* |
26
|
|
|
* @category PHP |
27
|
|
|
* @package PHP_CodeSniffer |
28
|
|
|
* @author Greg Sherwood <[email protected]> |
29
|
|
|
* @author Marc McIntyre <[email protected]> |
30
|
|
|
* @author Alexander Obuhovich <[email protected]> |
31
|
|
|
* @license https://github.com/aik099/CodingStandard/blob/master/LICENSE BSD 3-Clause |
32
|
|
|
* @link https://github.com/aik099/CodingStandard |
33
|
|
|
*/ |
34
|
|
|
class CodingStandard_Sniffs_ControlStructures_ControlSignatureSniff extends |
|
|
|
|
35
|
|
|
PHP_CodeSniffer_Standards_AbstractPatternSniff |
36
|
|
|
{ |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* A list of tokenizers this sniff supports. |
40
|
|
|
* |
41
|
|
|
* @var array |
42
|
|
|
*/ |
43
|
|
|
public $supportedTokenizers = array( |
44
|
|
|
'PHP', |
45
|
|
|
'JS', |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Constructs a PEAR_Sniffs_ControlStructures_ControlSignatureSniff. |
51
|
|
|
*/ |
52
|
1 |
|
public function __construct() |
53
|
|
|
{ |
54
|
1 |
|
parent::__construct(true); |
55
|
|
|
|
56
|
1 |
|
}//end __construct() |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Returns the patterns that this test wishes to verify. |
61
|
|
|
* |
62
|
|
|
* @return string[] |
63
|
|
|
*/ |
64
|
1 |
|
protected function getPatterns() |
65
|
|
|
{ |
66
|
|
|
return array( |
67
|
1 |
|
'do {EOL...} while (...);EOL', |
68
|
1 |
|
'while (...) {EOL', |
69
|
1 |
|
'switch (...) {EOL', |
70
|
1 |
|
'for (...) {EOL', |
71
|
1 |
|
'if (...) {EOL', |
72
|
1 |
|
'foreach (...) {EOL', |
73
|
1 |
|
'}EOLelseif (...) {EOL', |
74
|
1 |
|
'}EOLelse {EOL', |
75
|
1 |
|
'do {EOL', |
76
|
1 |
|
'try {EOL', |
77
|
|
|
'}EOLcatch (...) {EOL' |
78
|
1 |
|
); |
79
|
|
|
|
80
|
|
|
}//end getPatterns() |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
}//end class |
84
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.