1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* CodingStandard_Sniffs_PHP_NoSilencedErrorsSniffSniff |
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
|
|
|
// @codeCoverageIgnoreStart |
15
|
|
|
if (class_exists('Generic_Sniffs_PHP_NoSilencedErrorsSniff', true) === false) { |
16
|
|
|
$error = 'Class Generic_Sniffs_PHP_NoSilencedErrorsSniff not found'; |
17
|
|
|
throw new PHP_CodeSniffer_Exception($error); |
18
|
|
|
} |
19
|
|
|
// @codeCoverageIgnoreEnd |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* CodingStandard_Sniffs_PHP_NoSilencedErrorsSniffSniff. |
23
|
|
|
* |
24
|
|
|
* Throws an error or warning when any code prefixed with an asperand is encountered. |
25
|
|
|
* |
26
|
|
|
* <code> |
27
|
|
|
* if (@in_array($array, $needle)) |
28
|
|
|
* { |
29
|
|
|
* doSomething(); |
30
|
|
|
* } |
31
|
|
|
* </code> |
32
|
|
|
* |
33
|
|
|
* @category PHP |
34
|
|
|
* @package PHP_CodeSniffer |
35
|
|
|
* @author Alexander Obuhovich <[email protected]> |
36
|
|
|
* @license https://github.com/aik099/CodingStandard/blob/master/LICENSE BSD 3-Clause |
37
|
|
|
* @link https://github.com/aik099/CodingStandard |
38
|
|
|
*/ |
39
|
|
|
class CodingStandard_Sniffs_PHP_NoSilencedErrorsSniff extends Generic_Sniffs_PHP_NoSilencedErrorsSniff |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Processes this test, when one of its tokens is encountered. |
44
|
|
|
* |
45
|
|
|
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
46
|
|
|
* @param int $stackPtr The position of the current token |
47
|
|
|
* in the stack passed in $tokens. |
48
|
|
|
* |
49
|
|
|
* @return void |
50
|
|
|
*/ |
51
|
1 |
|
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
52
|
|
|
{ |
53
|
1 |
|
$tokens = $phpcsFile->getTokens(); |
54
|
1 |
|
$secondTokenData = $tokens[($stackPtr + 1)]; |
55
|
1 |
|
$thirdTokenData = $tokens[($stackPtr + 2)]; |
56
|
|
|
|
57
|
|
|
// This is a silenced "trigger_error" function call. |
58
|
1 |
|
if ($secondTokenData['code'] === T_STRING |
59
|
1 |
|
&& $secondTokenData['content'] === 'trigger_error' |
60
|
1 |
|
&& $thirdTokenData['code'] === T_OPEN_PARENTHESIS |
61
|
1 |
|
&& isset($thirdTokenData['parenthesis_closer']) === true |
62
|
1 |
|
) { |
63
|
1 |
|
$lastArgumentToken = $phpcsFile->findPrevious( |
64
|
1 |
|
PHP_CodeSniffer_Tokens::$emptyTokens, |
65
|
1 |
|
($thirdTokenData['parenthesis_closer'] - 1), |
66
|
1 |
|
($thirdTokenData['parenthesis_opener'] + 1), |
67
|
|
|
true |
68
|
1 |
|
); |
69
|
|
|
|
70
|
1 |
|
$lastArgumentTokenData = $tokens[$lastArgumentToken]; |
71
|
|
|
|
72
|
1 |
|
if ($lastArgumentTokenData['code'] === T_STRING |
73
|
1 |
|
&& $lastArgumentTokenData['content'] === 'E_USER_DEPRECATED' |
74
|
1 |
|
) { |
75
|
1 |
|
return; |
76
|
|
|
} |
77
|
1 |
|
} |
78
|
|
|
|
79
|
1 |
|
parent::process($phpcsFile, $stackPtr); |
80
|
|
|
|
81
|
1 |
|
}//end process() |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
}//end class |
85
|
|
|
|
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.