1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* \PHPCompatibility\Sniffs\FunctionParameters\SetlocaleStringSniff. |
4
|
|
|
* |
5
|
|
|
* PHP version 4.2 |
6
|
|
|
* PHP version 7.0 |
7
|
|
|
* |
8
|
|
|
* @category PHP |
9
|
|
|
* @package PHPCompatibility |
10
|
|
|
* @author Juliette Reinders Folmer <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace PHPCompatibility\Sniffs\FunctionParameters; |
14
|
|
|
|
15
|
|
|
use PHPCompatibility\AbstractFunctionCallParameterSniff; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* \PHPCompatibility\Sniffs\FunctionParameters\SetlocaleStringSniff. |
19
|
|
|
* |
20
|
|
|
* Detect: Support for the category parameter passed as a string has been removed. |
21
|
|
|
* Only LC_* constants can be used as of this version [7.0.0]. |
22
|
|
|
* |
23
|
|
|
* PHP version 4.2 |
24
|
|
|
* PHP version 7.0 |
25
|
|
|
* |
26
|
|
|
* @category PHP |
27
|
|
|
* @package PHPCompatibility |
28
|
|
|
* @author Juliette Reinders Folmer <[email protected]> |
29
|
|
|
*/ |
30
|
|
|
class SetlocaleStringSniff extends AbstractFunctionCallParameterSniff |
31
|
|
|
{ |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Functions to check for. |
35
|
|
|
* |
36
|
|
|
* @var array |
37
|
|
|
*/ |
38
|
|
|
protected $targetFunctions = array( |
39
|
|
|
'setlocale' => true, |
40
|
|
|
); |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Do a version check to determine if this sniff needs to run at all. |
45
|
|
|
* |
46
|
|
|
* @return bool |
47
|
|
|
*/ |
48
|
|
|
protected function bowOutEarly() |
49
|
|
|
{ |
50
|
|
|
return ($this->supportsAbove('4.2') === false); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Process the parameters of a matched function. |
56
|
|
|
* |
57
|
|
|
* @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
58
|
|
|
* @param int $stackPtr The position of the current token in the stack. |
59
|
|
|
* @param string $functionName The token content (function name) which was matched. |
60
|
|
|
* @param array $parameters Array with information about the parameters. |
61
|
|
|
* |
62
|
|
|
* @return int|void Integer stack pointer to skip forward or void to continue |
63
|
|
|
* normal file processing. |
64
|
|
|
*/ |
65
|
|
|
public function processParameters(\PHP_CodeSniffer_File $phpcsFile, $stackPtr, $functionName, $parameters) |
66
|
|
|
{ |
67
|
|
|
if (isset($parameters[1]) === false) { |
68
|
|
|
return; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$tokens = $phpcsFile->getTokens(); |
72
|
|
|
$targetParam = $parameters[1]; |
73
|
|
|
|
74
|
|
|
for ($i = $targetParam['start']; $i <= $targetParam['end']; $i++) { |
75
|
|
|
if ($tokens[$i]['code'] !== T_CONSTANT_ENCAPSED_STRING |
76
|
|
|
&& $tokens[$i]['code'] !== T_DOUBLE_QUOTED_STRING |
77
|
|
|
) { |
78
|
|
|
continue; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
$message = 'Passing the $category as a string to setlocale() has been deprecated since PHP 4.2'; |
82
|
|
|
$isError = false; |
83
|
|
|
$errorCode = 'Deprecated'; |
84
|
|
|
$data = array($targetParam['raw']); |
85
|
|
|
|
86
|
|
View Code Duplication |
if ($this->supportsAbove('7.0') === true) { |
87
|
|
|
$message .= ' and is removed since PHP 7.0'; |
88
|
|
|
$isError = true; |
89
|
|
|
$errorCode = 'Removed'; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
$message .= '; Pass one of the LC_* constants instead. Found: %s'; |
93
|
|
|
|
94
|
|
|
$this->addMessage($phpcsFile, $message, $i, $isError, $errorCode, $data); |
95
|
|
|
break; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
}//end class |
99
|
|
|
|