@@ -30,82 +30,82 @@ |
||
30 | 30 | class RemovedHashAlgorithmsSniff extends AbstractRemovedFeatureSniff |
31 | 31 | { |
32 | 32 | |
33 | - /** |
|
34 | - * A list of removed hash algorithms, which were present in older versions. |
|
35 | - * |
|
36 | - * The array lists : version number with false (deprecated) and true (removed). |
|
37 | - * If's sufficient to list the first version where the hash algorithm was deprecated/removed. |
|
38 | - * |
|
39 | - * @var array(string => array(string => bool)) |
|
40 | - */ |
|
41 | - protected $removedAlgorithms = array( |
|
42 | - 'salsa10' => array( |
|
43 | - '5.4' => true, |
|
44 | - ), |
|
45 | - 'salsa20' => array( |
|
46 | - '5.4' => true, |
|
47 | - ), |
|
48 | - ); |
|
33 | + /** |
|
34 | + * A list of removed hash algorithms, which were present in older versions. |
|
35 | + * |
|
36 | + * The array lists : version number with false (deprecated) and true (removed). |
|
37 | + * If's sufficient to list the first version where the hash algorithm was deprecated/removed. |
|
38 | + * |
|
39 | + * @var array(string => array(string => bool)) |
|
40 | + */ |
|
41 | + protected $removedAlgorithms = array( |
|
42 | + 'salsa10' => array( |
|
43 | + '5.4' => true, |
|
44 | + ), |
|
45 | + 'salsa20' => array( |
|
46 | + '5.4' => true, |
|
47 | + ), |
|
48 | + ); |
|
49 | 49 | |
50 | - /** |
|
51 | - * Returns an array of tokens this test wants to listen for. |
|
52 | - * |
|
53 | - * @return array |
|
54 | - */ |
|
55 | - public function register() |
|
56 | - { |
|
57 | - return array(\T_STRING); |
|
58 | - } |
|
50 | + /** |
|
51 | + * Returns an array of tokens this test wants to listen for. |
|
52 | + * |
|
53 | + * @return array |
|
54 | + */ |
|
55 | + public function register() |
|
56 | + { |
|
57 | + return array(\T_STRING); |
|
58 | + } |
|
59 | 59 | |
60 | 60 | |
61 | - /** |
|
62 | - * Processes this test, when one of its tokens is encountered. |
|
63 | - * |
|
64 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
65 | - * @param int $stackPtr The position of the current token in the |
|
66 | - * stack passed in $tokens. |
|
67 | - * |
|
68 | - * @return void |
|
69 | - */ |
|
70 | - public function process(File $phpcsFile, $stackPtr) |
|
71 | - { |
|
72 | - $algo = $this->getHashAlgorithmParameter($phpcsFile, $stackPtr); |
|
73 | - if (empty($algo) || \is_string($algo) === false) { |
|
74 | - return; |
|
75 | - } |
|
61 | + /** |
|
62 | + * Processes this test, when one of its tokens is encountered. |
|
63 | + * |
|
64 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
65 | + * @param int $stackPtr The position of the current token in the |
|
66 | + * stack passed in $tokens. |
|
67 | + * |
|
68 | + * @return void |
|
69 | + */ |
|
70 | + public function process(File $phpcsFile, $stackPtr) |
|
71 | + { |
|
72 | + $algo = $this->getHashAlgorithmParameter($phpcsFile, $stackPtr); |
|
73 | + if (empty($algo) || \is_string($algo) === false) { |
|
74 | + return; |
|
75 | + } |
|
76 | 76 | |
77 | - // Bow out if not one of the algorithms we're targetting. |
|
78 | - if (isset($this->removedAlgorithms[$algo]) === false) { |
|
79 | - return; |
|
80 | - } |
|
77 | + // Bow out if not one of the algorithms we're targetting. |
|
78 | + if (isset($this->removedAlgorithms[$algo]) === false) { |
|
79 | + return; |
|
80 | + } |
|
81 | 81 | |
82 | - $itemInfo = array( |
|
83 | - 'name' => $algo, |
|
84 | - ); |
|
85 | - $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
86 | - } |
|
82 | + $itemInfo = array( |
|
83 | + 'name' => $algo, |
|
84 | + ); |
|
85 | + $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
86 | + } |
|
87 | 87 | |
88 | 88 | |
89 | - /** |
|
90 | - * Get the relevant sub-array for a specific item from a multi-dimensional array. |
|
91 | - * |
|
92 | - * @param array $itemInfo Base information about the item. |
|
93 | - * |
|
94 | - * @return array Version and other information about the item. |
|
95 | - */ |
|
96 | - public function getItemArray(array $itemInfo) |
|
97 | - { |
|
98 | - return $this->removedAlgorithms[$itemInfo['name']]; |
|
99 | - } |
|
89 | + /** |
|
90 | + * Get the relevant sub-array for a specific item from a multi-dimensional array. |
|
91 | + * |
|
92 | + * @param array $itemInfo Base information about the item. |
|
93 | + * |
|
94 | + * @return array Version and other information about the item. |
|
95 | + */ |
|
96 | + public function getItemArray(array $itemInfo) |
|
97 | + { |
|
98 | + return $this->removedAlgorithms[$itemInfo['name']]; |
|
99 | + } |
|
100 | 100 | |
101 | 101 | |
102 | - /** |
|
103 | - * Get the error message template for this sniff. |
|
104 | - * |
|
105 | - * @return string |
|
106 | - */ |
|
107 | - protected function getErrorMsgTemplate() |
|
108 | - { |
|
109 | - return 'The %s hash algorithm is '; |
|
110 | - } |
|
102 | + /** |
|
103 | + * Get the error message template for this sniff. |
|
104 | + * |
|
105 | + * @return string |
|
106 | + */ |
|
107 | + protected function getErrorMsgTemplate() |
|
108 | + { |
|
109 | + return 'The %s hash algorithm is '; |
|
110 | + } |
|
111 | 111 | } |
@@ -24,83 +24,83 @@ |
||
24 | 24 | class NewArrayReduceInitialTypeSniff extends AbstractFunctionCallParameterSniff |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * Functions to check for. |
|
29 | - * |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - protected $targetFunctions = array( |
|
33 | - 'array_reduce' => true, |
|
34 | - ); |
|
27 | + /** |
|
28 | + * Functions to check for. |
|
29 | + * |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + protected $targetFunctions = array( |
|
33 | + 'array_reduce' => true, |
|
34 | + ); |
|
35 | 35 | |
36 | - /** |
|
37 | - * Tokens which, for the purposes of this sniff, indicate that there is |
|
38 | - * a variable element to the value passed. |
|
39 | - * |
|
40 | - * @var array |
|
41 | - */ |
|
42 | - private $variableValueTokens = array( |
|
43 | - \T_VARIABLE, |
|
44 | - \T_STRING, |
|
45 | - \T_SELF, |
|
46 | - \T_PARENT, |
|
47 | - \T_STATIC, |
|
48 | - \T_DOUBLE_QUOTED_STRING, |
|
49 | - ); |
|
36 | + /** |
|
37 | + * Tokens which, for the purposes of this sniff, indicate that there is |
|
38 | + * a variable element to the value passed. |
|
39 | + * |
|
40 | + * @var array |
|
41 | + */ |
|
42 | + private $variableValueTokens = array( |
|
43 | + \T_VARIABLE, |
|
44 | + \T_STRING, |
|
45 | + \T_SELF, |
|
46 | + \T_PARENT, |
|
47 | + \T_STATIC, |
|
48 | + \T_DOUBLE_QUOTED_STRING, |
|
49 | + ); |
|
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * Do a version check to determine if this sniff needs to run at all. |
|
54 | - * |
|
55 | - * @return bool |
|
56 | - */ |
|
57 | - protected function bowOutEarly() |
|
58 | - { |
|
59 | - return ($this->supportsBelow('5.2') === false); |
|
60 | - } |
|
52 | + /** |
|
53 | + * Do a version check to determine if this sniff needs to run at all. |
|
54 | + * |
|
55 | + * @return bool |
|
56 | + */ |
|
57 | + protected function bowOutEarly() |
|
58 | + { |
|
59 | + return ($this->supportsBelow('5.2') === false); |
|
60 | + } |
|
61 | 61 | |
62 | 62 | |
63 | - /** |
|
64 | - * Process the parameters of a matched function. |
|
65 | - * |
|
66 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
67 | - * @param int $stackPtr The position of the current token in the stack. |
|
68 | - * @param string $functionName The token content (function name) which was matched. |
|
69 | - * @param array $parameters Array with information about the parameters. |
|
70 | - * |
|
71 | - * @return int|void Integer stack pointer to skip forward or void to continue |
|
72 | - * normal file processing. |
|
73 | - */ |
|
74 | - public function processParameters(File $phpcsFile, $stackPtr, $functionName, $parameters) |
|
75 | - { |
|
76 | - if (isset($parameters[3]) === false) { |
|
77 | - return; |
|
78 | - } |
|
63 | + /** |
|
64 | + * Process the parameters of a matched function. |
|
65 | + * |
|
66 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
67 | + * @param int $stackPtr The position of the current token in the stack. |
|
68 | + * @param string $functionName The token content (function name) which was matched. |
|
69 | + * @param array $parameters Array with information about the parameters. |
|
70 | + * |
|
71 | + * @return int|void Integer stack pointer to skip forward or void to continue |
|
72 | + * normal file processing. |
|
73 | + */ |
|
74 | + public function processParameters(File $phpcsFile, $stackPtr, $functionName, $parameters) |
|
75 | + { |
|
76 | + if (isset($parameters[3]) === false) { |
|
77 | + return; |
|
78 | + } |
|
79 | 79 | |
80 | - $targetParam = $parameters[3]; |
|
81 | - if ($this->isNumber($phpcsFile, $targetParam['start'], $targetParam['end'], true) !== false) { |
|
82 | - return; |
|
83 | - } |
|
80 | + $targetParam = $parameters[3]; |
|
81 | + if ($this->isNumber($phpcsFile, $targetParam['start'], $targetParam['end'], true) !== false) { |
|
82 | + return; |
|
83 | + } |
|
84 | 84 | |
85 | - if ($this->isNumericCalculation($phpcsFile, $targetParam['start'], $targetParam['end']) === true) { |
|
86 | - return; |
|
87 | - } |
|
85 | + if ($this->isNumericCalculation($phpcsFile, $targetParam['start'], $targetParam['end']) === true) { |
|
86 | + return; |
|
87 | + } |
|
88 | 88 | |
89 | - $error = 'Passing a non-integer as the value for $initial to array_reduce() is not supported in PHP 5.2 or lower.'; |
|
90 | - if ($phpcsFile->findNext($this->variableValueTokens, $targetParam['start'], ($targetParam['end'] + 1)) === false) { |
|
91 | - $phpcsFile->addError( |
|
92 | - $error . ' Found %s', |
|
93 | - $targetParam['start'], |
|
94 | - 'InvalidTypeFound', |
|
95 | - array($targetParam['raw']) |
|
96 | - ); |
|
97 | - } else { |
|
98 | - $phpcsFile->addWarning( |
|
99 | - $error . ' Variable value found. Found %s', |
|
100 | - $targetParam['start'], |
|
101 | - 'VariableFound', |
|
102 | - array($targetParam['raw']) |
|
103 | - ); |
|
104 | - } |
|
105 | - } |
|
89 | + $error = 'Passing a non-integer as the value for $initial to array_reduce() is not supported in PHP 5.2 or lower.'; |
|
90 | + if ($phpcsFile->findNext($this->variableValueTokens, $targetParam['start'], ($targetParam['end'] + 1)) === false) { |
|
91 | + $phpcsFile->addError( |
|
92 | + $error . ' Found %s', |
|
93 | + $targetParam['start'], |
|
94 | + 'InvalidTypeFound', |
|
95 | + array($targetParam['raw']) |
|
96 | + ); |
|
97 | + } else { |
|
98 | + $phpcsFile->addWarning( |
|
99 | + $error . ' Variable value found. Found %s', |
|
100 | + $targetParam['start'], |
|
101 | + 'VariableFound', |
|
102 | + array($targetParam['raw']) |
|
103 | + ); |
|
104 | + } |
|
105 | + } |
|
106 | 106 | } |
@@ -24,100 +24,100 @@ |
||
24 | 24 | class NewPackFormatSniff extends AbstractFunctionCallParameterSniff |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * Functions to check for. |
|
29 | - * |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - protected $targetFunctions = array( |
|
33 | - 'pack' => true, |
|
34 | - ); |
|
27 | + /** |
|
28 | + * Functions to check for. |
|
29 | + * |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + protected $targetFunctions = array( |
|
33 | + 'pack' => true, |
|
34 | + ); |
|
35 | 35 | |
36 | - /** |
|
37 | - * List of new format character codes added to pack(). |
|
38 | - * |
|
39 | - * @var array Regex pattern => Version array. |
|
40 | - */ |
|
41 | - protected $newFormats = array( |
|
42 | - '`([Z])`' => array( |
|
43 | - '5.4' => false, |
|
44 | - '5.5' => true, |
|
45 | - ), |
|
46 | - '`([qQJP])`' => array( |
|
47 | - '5.6.2' => false, |
|
48 | - '5.6.3' => true, |
|
49 | - ), |
|
50 | - '`([eEgG])`' => array( |
|
51 | - '7.0.14' => false, |
|
52 | - '7.0.15' => true, // And 7.1.1. |
|
53 | - ), |
|
54 | - ); |
|
36 | + /** |
|
37 | + * List of new format character codes added to pack(). |
|
38 | + * |
|
39 | + * @var array Regex pattern => Version array. |
|
40 | + */ |
|
41 | + protected $newFormats = array( |
|
42 | + '`([Z])`' => array( |
|
43 | + '5.4' => false, |
|
44 | + '5.5' => true, |
|
45 | + ), |
|
46 | + '`([qQJP])`' => array( |
|
47 | + '5.6.2' => false, |
|
48 | + '5.6.3' => true, |
|
49 | + ), |
|
50 | + '`([eEgG])`' => array( |
|
51 | + '7.0.14' => false, |
|
52 | + '7.0.15' => true, // And 7.1.1. |
|
53 | + ), |
|
54 | + ); |
|
55 | 55 | |
56 | 56 | |
57 | - /** |
|
58 | - * Do a version check to determine if this sniff needs to run at all. |
|
59 | - * |
|
60 | - * @return bool |
|
61 | - */ |
|
62 | - protected function bowOutEarly() |
|
63 | - { |
|
64 | - return ($this->supportsBelow('7.1') === false); |
|
65 | - } |
|
57 | + /** |
|
58 | + * Do a version check to determine if this sniff needs to run at all. |
|
59 | + * |
|
60 | + * @return bool |
|
61 | + */ |
|
62 | + protected function bowOutEarly() |
|
63 | + { |
|
64 | + return ($this->supportsBelow('7.1') === false); |
|
65 | + } |
|
66 | 66 | |
67 | 67 | |
68 | - /** |
|
69 | - * Process the parameters of a matched function. |
|
70 | - * |
|
71 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
72 | - * @param int $stackPtr The position of the current token in the stack. |
|
73 | - * @param string $functionName The token content (function name) which was matched. |
|
74 | - * @param array $parameters Array with information about the parameters. |
|
75 | - * |
|
76 | - * @return int|void Integer stack pointer to skip forward or void to continue |
|
77 | - * normal file processing. |
|
78 | - */ |
|
79 | - public function processParameters(File $phpcsFile, $stackPtr, $functionName, $parameters) |
|
80 | - { |
|
81 | - if (isset($parameters[1]) === false) { |
|
82 | - return; |
|
83 | - } |
|
68 | + /** |
|
69 | + * Process the parameters of a matched function. |
|
70 | + * |
|
71 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
72 | + * @param int $stackPtr The position of the current token in the stack. |
|
73 | + * @param string $functionName The token content (function name) which was matched. |
|
74 | + * @param array $parameters Array with information about the parameters. |
|
75 | + * |
|
76 | + * @return int|void Integer stack pointer to skip forward or void to continue |
|
77 | + * normal file processing. |
|
78 | + */ |
|
79 | + public function processParameters(File $phpcsFile, $stackPtr, $functionName, $parameters) |
|
80 | + { |
|
81 | + if (isset($parameters[1]) === false) { |
|
82 | + return; |
|
83 | + } |
|
84 | 84 | |
85 | - $tokens = $phpcsFile->getTokens(); |
|
86 | - $targetParam = $parameters[1]; |
|
85 | + $tokens = $phpcsFile->getTokens(); |
|
86 | + $targetParam = $parameters[1]; |
|
87 | 87 | |
88 | - for ($i = $targetParam['start']; $i <= $targetParam['end']; $i++) { |
|
89 | - if ($tokens[$i]['code'] !== \T_CONSTANT_ENCAPSED_STRING |
|
90 | - && $tokens[$i]['code'] !== \T_DOUBLE_QUOTED_STRING |
|
91 | - ) { |
|
92 | - continue; |
|
93 | - } |
|
88 | + for ($i = $targetParam['start']; $i <= $targetParam['end']; $i++) { |
|
89 | + if ($tokens[$i]['code'] !== \T_CONSTANT_ENCAPSED_STRING |
|
90 | + && $tokens[$i]['code'] !== \T_DOUBLE_QUOTED_STRING |
|
91 | + ) { |
|
92 | + continue; |
|
93 | + } |
|
94 | 94 | |
95 | - $content = $tokens[$i]['content']; |
|
96 | - if ($tokens[$i]['code'] === \T_DOUBLE_QUOTED_STRING) { |
|
97 | - $content = $this->stripVariables($content); |
|
98 | - } |
|
95 | + $content = $tokens[$i]['content']; |
|
96 | + if ($tokens[$i]['code'] === \T_DOUBLE_QUOTED_STRING) { |
|
97 | + $content = $this->stripVariables($content); |
|
98 | + } |
|
99 | 99 | |
100 | - foreach ($this->newFormats as $pattern => $versionArray) { |
|
101 | - if (preg_match($pattern, $content, $matches) !== 1) { |
|
102 | - continue; |
|
103 | - } |
|
100 | + foreach ($this->newFormats as $pattern => $versionArray) { |
|
101 | + if (preg_match($pattern, $content, $matches) !== 1) { |
|
102 | + continue; |
|
103 | + } |
|
104 | 104 | |
105 | - foreach ($versionArray as $version => $present) { |
|
106 | - if ($present === false && $this->supportsBelow($version) === true) { |
|
107 | - $phpcsFile->addError( |
|
108 | - 'Passing the $format(s) "%s" to pack() is not supported in PHP %s or lower. Found %s', |
|
109 | - $targetParam['start'], |
|
110 | - 'NewFormatFound', |
|
111 | - array( |
|
112 | - $matches[1], |
|
113 | - $version, |
|
114 | - $targetParam['raw'], |
|
115 | - ) |
|
116 | - ); |
|
117 | - continue 2; |
|
118 | - } |
|
119 | - } |
|
120 | - } |
|
121 | - } |
|
122 | - } |
|
105 | + foreach ($versionArray as $version => $present) { |
|
106 | + if ($present === false && $this->supportsBelow($version) === true) { |
|
107 | + $phpcsFile->addError( |
|
108 | + 'Passing the $format(s) "%s" to pack() is not supported in PHP %s or lower. Found %s', |
|
109 | + $targetParam['start'], |
|
110 | + 'NewFormatFound', |
|
111 | + array( |
|
112 | + $matches[1], |
|
113 | + $version, |
|
114 | + $targetParam['raw'], |
|
115 | + ) |
|
116 | + ); |
|
117 | + continue 2; |
|
118 | + } |
|
119 | + } |
|
120 | + } |
|
121 | + } |
|
122 | + } |
|
123 | 123 | } |
@@ -24,89 +24,89 @@ |
||
24 | 24 | class NewFopenModesSniff extends AbstractFunctionCallParameterSniff |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * Functions to check for. |
|
29 | - * |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - protected $targetFunctions = array( |
|
33 | - 'fopen' => true, |
|
34 | - ); |
|
27 | + /** |
|
28 | + * Functions to check for. |
|
29 | + * |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + protected $targetFunctions = array( |
|
33 | + 'fopen' => true, |
|
34 | + ); |
|
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * Do a version check to determine if this sniff needs to run at all. |
|
39 | - * |
|
40 | - * @return bool |
|
41 | - */ |
|
42 | - protected function bowOutEarly() |
|
43 | - { |
|
44 | - // Version used here should be (above) the highest version from the `newModes` control, |
|
45 | - // structure below, i.e. the last PHP version in which a new mode was introduced. |
|
46 | - return ($this->supportsBelow('7.1') === false); |
|
47 | - } |
|
37 | + /** |
|
38 | + * Do a version check to determine if this sniff needs to run at all. |
|
39 | + * |
|
40 | + * @return bool |
|
41 | + */ |
|
42 | + protected function bowOutEarly() |
|
43 | + { |
|
44 | + // Version used here should be (above) the highest version from the `newModes` control, |
|
45 | + // structure below, i.e. the last PHP version in which a new mode was introduced. |
|
46 | + return ($this->supportsBelow('7.1') === false); |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * Process the parameters of a matched function. |
|
52 | - * |
|
53 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
54 | - * @param int $stackPtr The position of the current token in the stack. |
|
55 | - * @param string $functionName The token content (function name) which was matched. |
|
56 | - * @param array $parameters Array with information about the parameters. |
|
57 | - * |
|
58 | - * @return int|void Integer stack pointer to skip forward or void to continue |
|
59 | - * normal file processing. |
|
60 | - */ |
|
61 | - public function processParameters(File $phpcsFile, $stackPtr, $functionName, $parameters) |
|
62 | - { |
|
63 | - if (isset($parameters[2]) === false) { |
|
64 | - return; |
|
65 | - } |
|
50 | + /** |
|
51 | + * Process the parameters of a matched function. |
|
52 | + * |
|
53 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
54 | + * @param int $stackPtr The position of the current token in the stack. |
|
55 | + * @param string $functionName The token content (function name) which was matched. |
|
56 | + * @param array $parameters Array with information about the parameters. |
|
57 | + * |
|
58 | + * @return int|void Integer stack pointer to skip forward or void to continue |
|
59 | + * normal file processing. |
|
60 | + */ |
|
61 | + public function processParameters(File $phpcsFile, $stackPtr, $functionName, $parameters) |
|
62 | + { |
|
63 | + if (isset($parameters[2]) === false) { |
|
64 | + return; |
|
65 | + } |
|
66 | 66 | |
67 | - $tokens = $phpcsFile->getTokens(); |
|
68 | - $targetParam = $parameters[2]; |
|
69 | - $errors = array(); |
|
67 | + $tokens = $phpcsFile->getTokens(); |
|
68 | + $targetParam = $parameters[2]; |
|
69 | + $errors = array(); |
|
70 | 70 | |
71 | - for ($i = $targetParam['start']; $i <= $targetParam['end']; $i++) { |
|
72 | - if ($tokens[$i]['code'] !== \T_CONSTANT_ENCAPSED_STRING) { |
|
73 | - continue; |
|
74 | - } |
|
71 | + for ($i = $targetParam['start']; $i <= $targetParam['end']; $i++) { |
|
72 | + if ($tokens[$i]['code'] !== \T_CONSTANT_ENCAPSED_STRING) { |
|
73 | + continue; |
|
74 | + } |
|
75 | 75 | |
76 | - if (strpos($tokens[$i]['content'], 'c+') !== false && $this->supportsBelow('5.2.5')) { |
|
77 | - $errors['cplusFound'] = array( |
|
78 | - 'c+', |
|
79 | - '5.2.5', |
|
80 | - $targetParam['raw'], |
|
81 | - ); |
|
82 | - } elseif (strpos($tokens[$i]['content'], 'c') !== false && $this->supportsBelow('5.2.5')) { |
|
83 | - $errors['cFound'] = array( |
|
84 | - 'c', |
|
85 | - '5.2.5', |
|
86 | - $targetParam['raw'], |
|
87 | - ); |
|
88 | - } |
|
76 | + if (strpos($tokens[$i]['content'], 'c+') !== false && $this->supportsBelow('5.2.5')) { |
|
77 | + $errors['cplusFound'] = array( |
|
78 | + 'c+', |
|
79 | + '5.2.5', |
|
80 | + $targetParam['raw'], |
|
81 | + ); |
|
82 | + } elseif (strpos($tokens[$i]['content'], 'c') !== false && $this->supportsBelow('5.2.5')) { |
|
83 | + $errors['cFound'] = array( |
|
84 | + 'c', |
|
85 | + '5.2.5', |
|
86 | + $targetParam['raw'], |
|
87 | + ); |
|
88 | + } |
|
89 | 89 | |
90 | - if (strpos($tokens[$i]['content'], 'e') !== false && $this->supportsBelow('7.0.15')) { |
|
91 | - $errors['eFound'] = array( |
|
92 | - 'e', |
|
93 | - '7.0.15', |
|
94 | - $targetParam['raw'], |
|
95 | - ); |
|
96 | - } |
|
97 | - } |
|
90 | + if (strpos($tokens[$i]['content'], 'e') !== false && $this->supportsBelow('7.0.15')) { |
|
91 | + $errors['eFound'] = array( |
|
92 | + 'e', |
|
93 | + '7.0.15', |
|
94 | + $targetParam['raw'], |
|
95 | + ); |
|
96 | + } |
|
97 | + } |
|
98 | 98 | |
99 | - if (empty($errors) === true) { |
|
100 | - return; |
|
101 | - } |
|
99 | + if (empty($errors) === true) { |
|
100 | + return; |
|
101 | + } |
|
102 | 102 | |
103 | - foreach ($errors as $errorCode => $errorData) { |
|
104 | - $phpcsFile->addError( |
|
105 | - 'Passing "%s" as the $mode to fopen() is not supported in PHP %s or lower. Found %s', |
|
106 | - $targetParam['start'], |
|
107 | - $errorCode, |
|
108 | - $errorData |
|
109 | - ); |
|
110 | - } |
|
111 | - } |
|
103 | + foreach ($errors as $errorCode => $errorData) { |
|
104 | + $phpcsFile->addError( |
|
105 | + 'Passing "%s" as the $mode to fopen() is not supported in PHP %s or lower. Found %s', |
|
106 | + $targetParam['start'], |
|
107 | + $errorCode, |
|
108 | + $errorData |
|
109 | + ); |
|
110 | + } |
|
111 | + } |
|
112 | 112 | } |
@@ -27,96 +27,96 @@ |
||
27 | 27 | class RemovedMbstringModifiersSniff extends AbstractFunctionCallParameterSniff |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * Functions to check for. |
|
32 | - * |
|
33 | - * Key is the function name, value the parameter position of the options parameter. |
|
34 | - * |
|
35 | - * @var array |
|
36 | - */ |
|
37 | - protected $targetFunctions = array( |
|
38 | - 'mb_ereg_replace' => 4, |
|
39 | - 'mb_eregi_replace' => 4, |
|
40 | - 'mb_regex_set_options' => 1, |
|
41 | - 'mbereg_replace' => 4, // Undocumented, but valid function alias. |
|
42 | - 'mberegi_replace' => 4, // Undocumented, but valid function alias. |
|
43 | - ); |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * Do a version check to determine if this sniff needs to run at all. |
|
48 | - * |
|
49 | - * @return bool |
|
50 | - */ |
|
51 | - protected function bowOutEarly() |
|
52 | - { |
|
53 | - // Version used here should be the highest version from the `$newModifiers` array, |
|
54 | - // i.e. the last PHP version in which a new modifier was introduced. |
|
55 | - return ($this->supportsAbove('7.1') === false); |
|
56 | - } |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * Process the parameters of a matched function. |
|
61 | - * |
|
62 | - * This method has to be made concrete in child classes. |
|
63 | - * |
|
64 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
65 | - * @param int $stackPtr The position of the current token in the stack. |
|
66 | - * @param string $functionName The token content (function name) which was matched. |
|
67 | - * @param array $parameters Array with information about the parameters. |
|
68 | - * |
|
69 | - * @return int|void Integer stack pointer to skip forward or void to continue |
|
70 | - * normal file processing. |
|
71 | - */ |
|
72 | - public function processParameters(File $phpcsFile, $stackPtr, $functionName, $parameters) |
|
73 | - { |
|
74 | - $tokens = $phpcsFile->getTokens(); |
|
75 | - $functionNameLc = strtolower($functionName); |
|
76 | - |
|
77 | - // Check whether the options parameter in the function call is passed. |
|
78 | - if (isset($parameters[$this->targetFunctions[$functionNameLc]]) === false) { |
|
79 | - return; |
|
80 | - } |
|
81 | - |
|
82 | - $optionsParam = $parameters[$this->targetFunctions[$functionNameLc]]; |
|
83 | - |
|
84 | - $stringToken = $phpcsFile->findNext(Tokens::$stringTokens, $optionsParam['start'], $optionsParam['end'] + 1); |
|
85 | - if ($stringToken === false) { |
|
86 | - // No string token found in the options parameter, so skip it (e.g. variable passed in). |
|
87 | - return; |
|
88 | - } |
|
89 | - |
|
90 | - $options = ''; |
|
91 | - |
|
92 | - /* |
|
30 | + /** |
|
31 | + * Functions to check for. |
|
32 | + * |
|
33 | + * Key is the function name, value the parameter position of the options parameter. |
|
34 | + * |
|
35 | + * @var array |
|
36 | + */ |
|
37 | + protected $targetFunctions = array( |
|
38 | + 'mb_ereg_replace' => 4, |
|
39 | + 'mb_eregi_replace' => 4, |
|
40 | + 'mb_regex_set_options' => 1, |
|
41 | + 'mbereg_replace' => 4, // Undocumented, but valid function alias. |
|
42 | + 'mberegi_replace' => 4, // Undocumented, but valid function alias. |
|
43 | + ); |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * Do a version check to determine if this sniff needs to run at all. |
|
48 | + * |
|
49 | + * @return bool |
|
50 | + */ |
|
51 | + protected function bowOutEarly() |
|
52 | + { |
|
53 | + // Version used here should be the highest version from the `$newModifiers` array, |
|
54 | + // i.e. the last PHP version in which a new modifier was introduced. |
|
55 | + return ($this->supportsAbove('7.1') === false); |
|
56 | + } |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * Process the parameters of a matched function. |
|
61 | + * |
|
62 | + * This method has to be made concrete in child classes. |
|
63 | + * |
|
64 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
65 | + * @param int $stackPtr The position of the current token in the stack. |
|
66 | + * @param string $functionName The token content (function name) which was matched. |
|
67 | + * @param array $parameters Array with information about the parameters. |
|
68 | + * |
|
69 | + * @return int|void Integer stack pointer to skip forward or void to continue |
|
70 | + * normal file processing. |
|
71 | + */ |
|
72 | + public function processParameters(File $phpcsFile, $stackPtr, $functionName, $parameters) |
|
73 | + { |
|
74 | + $tokens = $phpcsFile->getTokens(); |
|
75 | + $functionNameLc = strtolower($functionName); |
|
76 | + |
|
77 | + // Check whether the options parameter in the function call is passed. |
|
78 | + if (isset($parameters[$this->targetFunctions[$functionNameLc]]) === false) { |
|
79 | + return; |
|
80 | + } |
|
81 | + |
|
82 | + $optionsParam = $parameters[$this->targetFunctions[$functionNameLc]]; |
|
83 | + |
|
84 | + $stringToken = $phpcsFile->findNext(Tokens::$stringTokens, $optionsParam['start'], $optionsParam['end'] + 1); |
|
85 | + if ($stringToken === false) { |
|
86 | + // No string token found in the options parameter, so skip it (e.g. variable passed in). |
|
87 | + return; |
|
88 | + } |
|
89 | + |
|
90 | + $options = ''; |
|
91 | + |
|
92 | + /* |
|
93 | 93 | * Get the content of any string tokens in the options parameter and remove the quotes and variables. |
94 | 94 | */ |
95 | - for ($i = $stringToken; $i <= $optionsParam['end']; $i++) { |
|
96 | - if (isset(Tokens::$stringTokens[$tokens[$i]['code']]) === false) { |
|
97 | - continue; |
|
98 | - } |
|
99 | - |
|
100 | - $content = $this->stripQuotes($tokens[$i]['content']); |
|
101 | - if ($tokens[$i]['code'] === \T_DOUBLE_QUOTED_STRING) { |
|
102 | - $content = $this->stripVariables($content); |
|
103 | - } |
|
104 | - $content = trim($content); |
|
105 | - |
|
106 | - if (empty($content) === false) { |
|
107 | - $options .= $content; |
|
108 | - } |
|
109 | - } |
|
110 | - |
|
111 | - if (strpos($options, 'e') !== false) { |
|
112 | - $error = 'The Mbstring regex "e" modifier is deprecated since PHP 7.1.'; |
|
113 | - |
|
114 | - // The alternative mb_ereg_replace_callback() function is only available since 5.4.1. |
|
115 | - if ($this->supportsBelow('5.4.1') === false) { |
|
116 | - $error .= ' Use mb_ereg_replace_callback() instead (PHP 5.4.1+).'; |
|
117 | - } |
|
118 | - |
|
119 | - $phpcsFile->addWarning($error, $stackPtr, 'Deprecated'); |
|
120 | - } |
|
121 | - } |
|
95 | + for ($i = $stringToken; $i <= $optionsParam['end']; $i++) { |
|
96 | + if (isset(Tokens::$stringTokens[$tokens[$i]['code']]) === false) { |
|
97 | + continue; |
|
98 | + } |
|
99 | + |
|
100 | + $content = $this->stripQuotes($tokens[$i]['content']); |
|
101 | + if ($tokens[$i]['code'] === \T_DOUBLE_QUOTED_STRING) { |
|
102 | + $content = $this->stripVariables($content); |
|
103 | + } |
|
104 | + $content = trim($content); |
|
105 | + |
|
106 | + if (empty($content) === false) { |
|
107 | + $options .= $content; |
|
108 | + } |
|
109 | + } |
|
110 | + |
|
111 | + if (strpos($options, 'e') !== false) { |
|
112 | + $error = 'The Mbstring regex "e" modifier is deprecated since PHP 7.1.'; |
|
113 | + |
|
114 | + // The alternative mb_ereg_replace_callback() function is only available since 5.4.1. |
|
115 | + if ($this->supportsBelow('5.4.1') === false) { |
|
116 | + $error .= ' Use mb_ereg_replace_callback() instead (PHP 5.4.1+).'; |
|
117 | + } |
|
118 | + |
|
119 | + $phpcsFile->addWarning($error, $stackPtr, 'Deprecated'); |
|
120 | + } |
|
121 | + } |
|
122 | 122 | } |
@@ -29,52 +29,52 @@ |
||
29 | 29 | class ForbiddenGetClassNullSniff extends AbstractFunctionCallParameterSniff |
30 | 30 | { |
31 | 31 | |
32 | - /** |
|
33 | - * Functions to check for. |
|
34 | - * |
|
35 | - * @var array |
|
36 | - */ |
|
37 | - protected $targetFunctions = array( |
|
38 | - 'get_class' => true, |
|
39 | - ); |
|
32 | + /** |
|
33 | + * Functions to check for. |
|
34 | + * |
|
35 | + * @var array |
|
36 | + */ |
|
37 | + protected $targetFunctions = array( |
|
38 | + 'get_class' => true, |
|
39 | + ); |
|
40 | 40 | |
41 | 41 | |
42 | - /** |
|
43 | - * Do a version check to determine if this sniff needs to run at all. |
|
44 | - * |
|
45 | - * @return bool |
|
46 | - */ |
|
47 | - protected function bowOutEarly() |
|
48 | - { |
|
49 | - return ($this->supportsAbove('7.2') === false); |
|
50 | - } |
|
42 | + /** |
|
43 | + * Do a version check to determine if this sniff needs to run at all. |
|
44 | + * |
|
45 | + * @return bool |
|
46 | + */ |
|
47 | + protected function bowOutEarly() |
|
48 | + { |
|
49 | + return ($this->supportsAbove('7.2') === false); |
|
50 | + } |
|
51 | 51 | |
52 | 52 | |
53 | - /** |
|
54 | - * Process the parameters of a matched function. |
|
55 | - * |
|
56 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
57 | - * @param int $stackPtr The position of the current token in the stack. |
|
58 | - * @param string $functionName The token content (function name) which was matched. |
|
59 | - * @param array $parameters Array with information about the parameters. |
|
60 | - * |
|
61 | - * @return int|void Integer stack pointer to skip forward or void to continue |
|
62 | - * normal file processing. |
|
63 | - */ |
|
64 | - public function processParameters(File $phpcsFile, $stackPtr, $functionName, $parameters) |
|
65 | - { |
|
66 | - if (isset($parameters[1]) === false) { |
|
67 | - return; |
|
68 | - } |
|
53 | + /** |
|
54 | + * Process the parameters of a matched function. |
|
55 | + * |
|
56 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
57 | + * @param int $stackPtr The position of the current token in the stack. |
|
58 | + * @param string $functionName The token content (function name) which was matched. |
|
59 | + * @param array $parameters Array with information about the parameters. |
|
60 | + * |
|
61 | + * @return int|void Integer stack pointer to skip forward or void to continue |
|
62 | + * normal file processing. |
|
63 | + */ |
|
64 | + public function processParameters(File $phpcsFile, $stackPtr, $functionName, $parameters) |
|
65 | + { |
|
66 | + if (isset($parameters[1]) === false) { |
|
67 | + return; |
|
68 | + } |
|
69 | 69 | |
70 | - if ($parameters[1]['raw'] !== 'null') { |
|
71 | - return; |
|
72 | - } |
|
70 | + if ($parameters[1]['raw'] !== 'null') { |
|
71 | + return; |
|
72 | + } |
|
73 | 73 | |
74 | - $phpcsFile->addError( |
|
75 | - 'Passing "null" as the $object to get_class() is not allowed since PHP 7.2.', |
|
76 | - $parameters[1]['start'], |
|
77 | - 'Found' |
|
78 | - ); |
|
79 | - } |
|
74 | + $phpcsFile->addError( |
|
75 | + 'Passing "null" as the $object to get_class() is not allowed since PHP 7.2.', |
|
76 | + $parameters[1]['start'], |
|
77 | + 'Found' |
|
78 | + ); |
|
79 | + } |
|
80 | 80 | } |
@@ -32,188 +32,188 @@ |
||
32 | 32 | class RemovedPCREModifiersSniff extends AbstractFunctionCallParameterSniff |
33 | 33 | { |
34 | 34 | |
35 | - /** |
|
36 | - * Functions to check for. |
|
37 | - * |
|
38 | - * @var array |
|
39 | - */ |
|
40 | - protected $targetFunctions = array( |
|
41 | - 'preg_replace' => true, |
|
42 | - 'preg_filter' => true, |
|
43 | - ); |
|
44 | - |
|
45 | - /** |
|
46 | - * Regex bracket delimiters. |
|
47 | - * |
|
48 | - * @var array |
|
49 | - */ |
|
50 | - protected $doublesSeparators = array( |
|
51 | - '{' => '}', |
|
52 | - '[' => ']', |
|
53 | - '(' => ')', |
|
54 | - '<' => '>', |
|
55 | - ); |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * Process the parameters of a matched function. |
|
60 | - * |
|
61 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
62 | - * @param int $stackPtr The position of the current token in the stack. |
|
63 | - * @param string $functionName The token content (function name) which was matched. |
|
64 | - * @param array $parameters Array with information about the parameters. |
|
65 | - * |
|
66 | - * @return int|void Integer stack pointer to skip forward or void to continue |
|
67 | - * normal file processing. |
|
68 | - */ |
|
69 | - public function processParameters(File $phpcsFile, $stackPtr, $functionName, $parameters) |
|
70 | - { |
|
71 | - // Check the first parameter in the function call as that should contain the regex(es). |
|
72 | - if (isset($parameters[1]) === false) { |
|
73 | - return; |
|
74 | - } |
|
75 | - |
|
76 | - $tokens = $phpcsFile->getTokens(); |
|
77 | - $functionNameLc = strtolower($functionName); |
|
78 | - $firstParam = $parameters[1]; |
|
79 | - |
|
80 | - // Differentiate between an array of patterns passed and a single pattern. |
|
81 | - $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, $firstParam['start'], ($firstParam['end'] + 1), true); |
|
82 | - if ($nextNonEmpty !== false && ($tokens[$nextNonEmpty]['code'] === \T_ARRAY || $tokens[$nextNonEmpty]['code'] === \T_OPEN_SHORT_ARRAY)) { |
|
83 | - $arrayValues = $this->getFunctionCallParameters($phpcsFile, $nextNonEmpty); |
|
84 | - if ($functionNameLc === 'preg_replace_callback_array') { |
|
85 | - // For preg_replace_callback_array(), the patterns will be in the array keys. |
|
86 | - foreach ($arrayValues as $value) { |
|
87 | - $hasKey = $phpcsFile->findNext(\T_DOUBLE_ARROW, $value['start'], ($value['end'] + 1)); |
|
88 | - if ($hasKey === false) { |
|
89 | - continue; |
|
90 | - } |
|
91 | - |
|
92 | - $value['end'] = ($hasKey - 1); |
|
93 | - $value['raw'] = trim($phpcsFile->getTokensAsString($value['start'], ($hasKey - $value['start']))); |
|
94 | - $this->processRegexPattern($value, $phpcsFile, $value['end'], $functionName); |
|
95 | - } |
|
96 | - |
|
97 | - } else { |
|
98 | - // Otherwise, the patterns will be in the array values. |
|
99 | - foreach ($arrayValues as $value) { |
|
100 | - $hasKey = $phpcsFile->findNext(\T_DOUBLE_ARROW, $value['start'], ($value['end'] + 1)); |
|
101 | - if ($hasKey !== false) { |
|
102 | - $value['start'] = ($hasKey + 1); |
|
103 | - $value['raw'] = trim($phpcsFile->getTokensAsString($value['start'], (($value['end'] + 1) - $value['start']))); |
|
104 | - } |
|
105 | - |
|
106 | - $this->processRegexPattern($value, $phpcsFile, $value['end'], $functionName); |
|
107 | - } |
|
108 | - } |
|
109 | - |
|
110 | - } else { |
|
111 | - $this->processRegexPattern($firstParam, $phpcsFile, $stackPtr, $functionName); |
|
112 | - } |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * Do a version check to determine if this sniff needs to run at all. |
|
118 | - * |
|
119 | - * @return bool |
|
120 | - */ |
|
121 | - protected function bowOutEarly() |
|
122 | - { |
|
123 | - return ($this->supportsAbove('5.5') === false); |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * Analyse a potential regex pattern for usage of the /e modifier. |
|
129 | - * |
|
130 | - * @param array $pattern Array containing the start and end token |
|
131 | - * pointer of the potential regex pattern and |
|
132 | - * the raw string value of the pattern. |
|
133 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
134 | - * @param int $stackPtr The position of the current token in the |
|
135 | - * stack passed in $tokens. |
|
136 | - * @param string $functionName The function which contained the pattern. |
|
137 | - * |
|
138 | - * @return void |
|
139 | - */ |
|
140 | - protected function processRegexPattern($pattern, File $phpcsFile, $stackPtr, $functionName) |
|
141 | - { |
|
142 | - $tokens = $phpcsFile->getTokens(); |
|
143 | - |
|
144 | - /* |
|
35 | + /** |
|
36 | + * Functions to check for. |
|
37 | + * |
|
38 | + * @var array |
|
39 | + */ |
|
40 | + protected $targetFunctions = array( |
|
41 | + 'preg_replace' => true, |
|
42 | + 'preg_filter' => true, |
|
43 | + ); |
|
44 | + |
|
45 | + /** |
|
46 | + * Regex bracket delimiters. |
|
47 | + * |
|
48 | + * @var array |
|
49 | + */ |
|
50 | + protected $doublesSeparators = array( |
|
51 | + '{' => '}', |
|
52 | + '[' => ']', |
|
53 | + '(' => ')', |
|
54 | + '<' => '>', |
|
55 | + ); |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * Process the parameters of a matched function. |
|
60 | + * |
|
61 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
62 | + * @param int $stackPtr The position of the current token in the stack. |
|
63 | + * @param string $functionName The token content (function name) which was matched. |
|
64 | + * @param array $parameters Array with information about the parameters. |
|
65 | + * |
|
66 | + * @return int|void Integer stack pointer to skip forward or void to continue |
|
67 | + * normal file processing. |
|
68 | + */ |
|
69 | + public function processParameters(File $phpcsFile, $stackPtr, $functionName, $parameters) |
|
70 | + { |
|
71 | + // Check the first parameter in the function call as that should contain the regex(es). |
|
72 | + if (isset($parameters[1]) === false) { |
|
73 | + return; |
|
74 | + } |
|
75 | + |
|
76 | + $tokens = $phpcsFile->getTokens(); |
|
77 | + $functionNameLc = strtolower($functionName); |
|
78 | + $firstParam = $parameters[1]; |
|
79 | + |
|
80 | + // Differentiate between an array of patterns passed and a single pattern. |
|
81 | + $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, $firstParam['start'], ($firstParam['end'] + 1), true); |
|
82 | + if ($nextNonEmpty !== false && ($tokens[$nextNonEmpty]['code'] === \T_ARRAY || $tokens[$nextNonEmpty]['code'] === \T_OPEN_SHORT_ARRAY)) { |
|
83 | + $arrayValues = $this->getFunctionCallParameters($phpcsFile, $nextNonEmpty); |
|
84 | + if ($functionNameLc === 'preg_replace_callback_array') { |
|
85 | + // For preg_replace_callback_array(), the patterns will be in the array keys. |
|
86 | + foreach ($arrayValues as $value) { |
|
87 | + $hasKey = $phpcsFile->findNext(\T_DOUBLE_ARROW, $value['start'], ($value['end'] + 1)); |
|
88 | + if ($hasKey === false) { |
|
89 | + continue; |
|
90 | + } |
|
91 | + |
|
92 | + $value['end'] = ($hasKey - 1); |
|
93 | + $value['raw'] = trim($phpcsFile->getTokensAsString($value['start'], ($hasKey - $value['start']))); |
|
94 | + $this->processRegexPattern($value, $phpcsFile, $value['end'], $functionName); |
|
95 | + } |
|
96 | + |
|
97 | + } else { |
|
98 | + // Otherwise, the patterns will be in the array values. |
|
99 | + foreach ($arrayValues as $value) { |
|
100 | + $hasKey = $phpcsFile->findNext(\T_DOUBLE_ARROW, $value['start'], ($value['end'] + 1)); |
|
101 | + if ($hasKey !== false) { |
|
102 | + $value['start'] = ($hasKey + 1); |
|
103 | + $value['raw'] = trim($phpcsFile->getTokensAsString($value['start'], (($value['end'] + 1) - $value['start']))); |
|
104 | + } |
|
105 | + |
|
106 | + $this->processRegexPattern($value, $phpcsFile, $value['end'], $functionName); |
|
107 | + } |
|
108 | + } |
|
109 | + |
|
110 | + } else { |
|
111 | + $this->processRegexPattern($firstParam, $phpcsFile, $stackPtr, $functionName); |
|
112 | + } |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * Do a version check to determine if this sniff needs to run at all. |
|
118 | + * |
|
119 | + * @return bool |
|
120 | + */ |
|
121 | + protected function bowOutEarly() |
|
122 | + { |
|
123 | + return ($this->supportsAbove('5.5') === false); |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * Analyse a potential regex pattern for usage of the /e modifier. |
|
129 | + * |
|
130 | + * @param array $pattern Array containing the start and end token |
|
131 | + * pointer of the potential regex pattern and |
|
132 | + * the raw string value of the pattern. |
|
133 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
134 | + * @param int $stackPtr The position of the current token in the |
|
135 | + * stack passed in $tokens. |
|
136 | + * @param string $functionName The function which contained the pattern. |
|
137 | + * |
|
138 | + * @return void |
|
139 | + */ |
|
140 | + protected function processRegexPattern($pattern, File $phpcsFile, $stackPtr, $functionName) |
|
141 | + { |
|
142 | + $tokens = $phpcsFile->getTokens(); |
|
143 | + |
|
144 | + /* |
|
145 | 145 | * The pattern might be build up of a combination of strings, variables |
146 | 146 | * and function calls. We are only concerned with the strings. |
147 | 147 | */ |
148 | - $regex = ''; |
|
149 | - for ($i = $pattern['start']; $i <= $pattern['end']; $i++) { |
|
150 | - if (isset(Tokens::$stringTokens[$tokens[$i]['code']]) === true) { |
|
151 | - $content = $this->stripQuotes($tokens[$i]['content']); |
|
152 | - if ($tokens[$i]['code'] === \T_DOUBLE_QUOTED_STRING) { |
|
153 | - $content = $this->stripVariables($content); |
|
154 | - } |
|
155 | - |
|
156 | - $regex .= trim($content); |
|
157 | - } |
|
158 | - } |
|
159 | - |
|
160 | - // Deal with multi-line regexes which were broken up in several string tokens. |
|
161 | - if ($tokens[$pattern['start']]['line'] !== $tokens[$pattern['end']]['line']) { |
|
162 | - $regex = $this->stripQuotes($regex); |
|
163 | - } |
|
164 | - |
|
165 | - if ($regex === '') { |
|
166 | - // No string token found in the first parameter, so skip it (e.g. if variable passed in). |
|
167 | - return; |
|
168 | - } |
|
169 | - |
|
170 | - $regexFirstChar = substr($regex, 0, 1); |
|
171 | - |
|
172 | - // Make sure that the character identified as the delimiter is valid. |
|
173 | - // Otherwise, it is a false positive caused by the string concatenation. |
|
174 | - if (preg_match('`[a-z0-9\\\\ ]`i', $regexFirstChar) === 1) { |
|
175 | - return; |
|
176 | - } |
|
177 | - |
|
178 | - if (isset($this->doublesSeparators[$regexFirstChar])) { |
|
179 | - $regexEndPos = strrpos($regex, $this->doublesSeparators[$regexFirstChar]); |
|
180 | - } else { |
|
181 | - $regexEndPos = strrpos($regex, $regexFirstChar); |
|
182 | - } |
|
183 | - |
|
184 | - if ($regexEndPos !== false) { |
|
185 | - $modifiers = substr($regex, $regexEndPos + 1); |
|
186 | - $this->examineModifiers($phpcsFile, $stackPtr, $functionName, $modifiers); |
|
187 | - } |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - /** |
|
192 | - * Examine the regex modifier string. |
|
193 | - * |
|
194 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
195 | - * @param int $stackPtr The position of the current token in the |
|
196 | - * stack passed in $tokens. |
|
197 | - * @param string $functionName The function which contained the pattern. |
|
198 | - * @param string $modifiers The regex modifiers found. |
|
199 | - * |
|
200 | - * @return void |
|
201 | - */ |
|
202 | - protected function examineModifiers(File $phpcsFile, $stackPtr, $functionName, $modifiers) |
|
203 | - { |
|
204 | - if (strpos($modifiers, 'e') !== false) { |
|
205 | - $error = '%s() - /e modifier is deprecated since PHP 5.5'; |
|
206 | - $isError = false; |
|
207 | - $errorCode = 'Deprecated'; |
|
208 | - $data = array($functionName); |
|
209 | - |
|
210 | - if ($this->supportsAbove('7.0')) { |
|
211 | - $error .= ' and removed since PHP 7.0'; |
|
212 | - $isError = true; |
|
213 | - $errorCode = 'Removed'; |
|
214 | - } |
|
215 | - |
|
216 | - $this->addMessage($phpcsFile, $error, $stackPtr, $isError, $errorCode, $data); |
|
217 | - } |
|
218 | - } |
|
148 | + $regex = ''; |
|
149 | + for ($i = $pattern['start']; $i <= $pattern['end']; $i++) { |
|
150 | + if (isset(Tokens::$stringTokens[$tokens[$i]['code']]) === true) { |
|
151 | + $content = $this->stripQuotes($tokens[$i]['content']); |
|
152 | + if ($tokens[$i]['code'] === \T_DOUBLE_QUOTED_STRING) { |
|
153 | + $content = $this->stripVariables($content); |
|
154 | + } |
|
155 | + |
|
156 | + $regex .= trim($content); |
|
157 | + } |
|
158 | + } |
|
159 | + |
|
160 | + // Deal with multi-line regexes which were broken up in several string tokens. |
|
161 | + if ($tokens[$pattern['start']]['line'] !== $tokens[$pattern['end']]['line']) { |
|
162 | + $regex = $this->stripQuotes($regex); |
|
163 | + } |
|
164 | + |
|
165 | + if ($regex === '') { |
|
166 | + // No string token found in the first parameter, so skip it (e.g. if variable passed in). |
|
167 | + return; |
|
168 | + } |
|
169 | + |
|
170 | + $regexFirstChar = substr($regex, 0, 1); |
|
171 | + |
|
172 | + // Make sure that the character identified as the delimiter is valid. |
|
173 | + // Otherwise, it is a false positive caused by the string concatenation. |
|
174 | + if (preg_match('`[a-z0-9\\\\ ]`i', $regexFirstChar) === 1) { |
|
175 | + return; |
|
176 | + } |
|
177 | + |
|
178 | + if (isset($this->doublesSeparators[$regexFirstChar])) { |
|
179 | + $regexEndPos = strrpos($regex, $this->doublesSeparators[$regexFirstChar]); |
|
180 | + } else { |
|
181 | + $regexEndPos = strrpos($regex, $regexFirstChar); |
|
182 | + } |
|
183 | + |
|
184 | + if ($regexEndPos !== false) { |
|
185 | + $modifiers = substr($regex, $regexEndPos + 1); |
|
186 | + $this->examineModifiers($phpcsFile, $stackPtr, $functionName, $modifiers); |
|
187 | + } |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + /** |
|
192 | + * Examine the regex modifier string. |
|
193 | + * |
|
194 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
195 | + * @param int $stackPtr The position of the current token in the |
|
196 | + * stack passed in $tokens. |
|
197 | + * @param string $functionName The function which contained the pattern. |
|
198 | + * @param string $modifiers The regex modifiers found. |
|
199 | + * |
|
200 | + * @return void |
|
201 | + */ |
|
202 | + protected function examineModifiers(File $phpcsFile, $stackPtr, $functionName, $modifiers) |
|
203 | + { |
|
204 | + if (strpos($modifiers, 'e') !== false) { |
|
205 | + $error = '%s() - /e modifier is deprecated since PHP 5.5'; |
|
206 | + $isError = false; |
|
207 | + $errorCode = 'Deprecated'; |
|
208 | + $data = array($functionName); |
|
209 | + |
|
210 | + if ($this->supportsAbove('7.0')) { |
|
211 | + $error .= ' and removed since PHP 7.0'; |
|
212 | + $isError = true; |
|
213 | + $errorCode = 'Removed'; |
|
214 | + } |
|
215 | + |
|
216 | + $this->addMessage($phpcsFile, $error, $stackPtr, $isError, $errorCode, $data); |
|
217 | + } |
|
218 | + } |
|
219 | 219 | } |
@@ -32,49 +32,49 @@ |
||
32 | 32 | class RemovedIconvEncodingSniff extends AbstractFunctionCallParameterSniff |
33 | 33 | { |
34 | 34 | |
35 | - /** |
|
36 | - * Functions to check for. |
|
37 | - * |
|
38 | - * @var array |
|
39 | - */ |
|
40 | - protected $targetFunctions = array( |
|
41 | - 'iconv_set_encoding' => true, |
|
42 | - ); |
|
35 | + /** |
|
36 | + * Functions to check for. |
|
37 | + * |
|
38 | + * @var array |
|
39 | + */ |
|
40 | + protected $targetFunctions = array( |
|
41 | + 'iconv_set_encoding' => true, |
|
42 | + ); |
|
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * Do a version check to determine if this sniff needs to run at all. |
|
47 | - * |
|
48 | - * @return bool |
|
49 | - */ |
|
50 | - protected function bowOutEarly() |
|
51 | - { |
|
52 | - return ($this->supportsAbove('5.6') === false); |
|
53 | - } |
|
45 | + /** |
|
46 | + * Do a version check to determine if this sniff needs to run at all. |
|
47 | + * |
|
48 | + * @return bool |
|
49 | + */ |
|
50 | + protected function bowOutEarly() |
|
51 | + { |
|
52 | + return ($this->supportsAbove('5.6') === false); |
|
53 | + } |
|
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * Process the parameters of a matched function. |
|
58 | - * |
|
59 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
60 | - * @param int $stackPtr The position of the current token in the stack. |
|
61 | - * @param string $functionName The token content (function name) which was matched. |
|
62 | - * @param array $parameters Array with information about the parameters. |
|
63 | - * |
|
64 | - * @return int|void Integer stack pointer to skip forward or void to continue |
|
65 | - * normal file processing. |
|
66 | - */ |
|
67 | - public function processParameters(File $phpcsFile, $stackPtr, $functionName, $parameters) |
|
68 | - { |
|
69 | - if (isset($parameters[1]) === false) { |
|
70 | - return; |
|
71 | - } |
|
56 | + /** |
|
57 | + * Process the parameters of a matched function. |
|
58 | + * |
|
59 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
60 | + * @param int $stackPtr The position of the current token in the stack. |
|
61 | + * @param string $functionName The token content (function name) which was matched. |
|
62 | + * @param array $parameters Array with information about the parameters. |
|
63 | + * |
|
64 | + * @return int|void Integer stack pointer to skip forward or void to continue |
|
65 | + * normal file processing. |
|
66 | + */ |
|
67 | + public function processParameters(File $phpcsFile, $stackPtr, $functionName, $parameters) |
|
68 | + { |
|
69 | + if (isset($parameters[1]) === false) { |
|
70 | + return; |
|
71 | + } |
|
72 | 72 | |
73 | - $phpcsFile->addWarning( |
|
74 | - 'All previously accepted values for the $type parameter of iconv_set_encoding() have been deprecated since PHP 5.6. Found %s', |
|
75 | - $parameters[1]['start'], |
|
76 | - 'DeprecatedValueFound', |
|
77 | - $parameters[1]['raw'] |
|
78 | - ); |
|
79 | - } |
|
73 | + $phpcsFile->addWarning( |
|
74 | + 'All previously accepted values for the $type parameter of iconv_set_encoding() have been deprecated since PHP 5.6. Found %s', |
|
75 | + $parameters[1]['start'], |
|
76 | + 'DeprecatedValueFound', |
|
77 | + $parameters[1]['raw'] |
|
78 | + ); |
|
79 | + } |
|
80 | 80 | } |
@@ -31,69 +31,69 @@ |
||
31 | 31 | class RemovedSetlocaleStringSniff extends AbstractFunctionCallParameterSniff |
32 | 32 | { |
33 | 33 | |
34 | - /** |
|
35 | - * Functions to check for. |
|
36 | - * |
|
37 | - * @var array |
|
38 | - */ |
|
39 | - protected $targetFunctions = array( |
|
40 | - 'setlocale' => true, |
|
41 | - ); |
|
34 | + /** |
|
35 | + * Functions to check for. |
|
36 | + * |
|
37 | + * @var array |
|
38 | + */ |
|
39 | + protected $targetFunctions = array( |
|
40 | + 'setlocale' => true, |
|
41 | + ); |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * Do a version check to determine if this sniff needs to run at all. |
|
46 | - * |
|
47 | - * @return bool |
|
48 | - */ |
|
49 | - protected function bowOutEarly() |
|
50 | - { |
|
51 | - return ($this->supportsAbove('4.2') === false); |
|
52 | - } |
|
44 | + /** |
|
45 | + * Do a version check to determine if this sniff needs to run at all. |
|
46 | + * |
|
47 | + * @return bool |
|
48 | + */ |
|
49 | + protected function bowOutEarly() |
|
50 | + { |
|
51 | + return ($this->supportsAbove('4.2') === false); |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * Process the parameters of a matched function. |
|
57 | - * |
|
58 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
59 | - * @param int $stackPtr The position of the current token in the stack. |
|
60 | - * @param string $functionName The token content (function name) which was matched. |
|
61 | - * @param array $parameters Array with information about the parameters. |
|
62 | - * |
|
63 | - * @return int|void Integer stack pointer to skip forward or void to continue |
|
64 | - * normal file processing. |
|
65 | - */ |
|
66 | - public function processParameters(File $phpcsFile, $stackPtr, $functionName, $parameters) |
|
67 | - { |
|
68 | - if (isset($parameters[1]) === false) { |
|
69 | - return; |
|
70 | - } |
|
55 | + /** |
|
56 | + * Process the parameters of a matched function. |
|
57 | + * |
|
58 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
59 | + * @param int $stackPtr The position of the current token in the stack. |
|
60 | + * @param string $functionName The token content (function name) which was matched. |
|
61 | + * @param array $parameters Array with information about the parameters. |
|
62 | + * |
|
63 | + * @return int|void Integer stack pointer to skip forward or void to continue |
|
64 | + * normal file processing. |
|
65 | + */ |
|
66 | + public function processParameters(File $phpcsFile, $stackPtr, $functionName, $parameters) |
|
67 | + { |
|
68 | + if (isset($parameters[1]) === false) { |
|
69 | + return; |
|
70 | + } |
|
71 | 71 | |
72 | - $tokens = $phpcsFile->getTokens(); |
|
73 | - $targetParam = $parameters[1]; |
|
72 | + $tokens = $phpcsFile->getTokens(); |
|
73 | + $targetParam = $parameters[1]; |
|
74 | 74 | |
75 | - for ($i = $targetParam['start']; $i <= $targetParam['end']; $i++) { |
|
76 | - if ($tokens[$i]['code'] !== \T_CONSTANT_ENCAPSED_STRING |
|
77 | - && $tokens[$i]['code'] !== \T_DOUBLE_QUOTED_STRING |
|
78 | - ) { |
|
79 | - continue; |
|
80 | - } |
|
75 | + for ($i = $targetParam['start']; $i <= $targetParam['end']; $i++) { |
|
76 | + if ($tokens[$i]['code'] !== \T_CONSTANT_ENCAPSED_STRING |
|
77 | + && $tokens[$i]['code'] !== \T_DOUBLE_QUOTED_STRING |
|
78 | + ) { |
|
79 | + continue; |
|
80 | + } |
|
81 | 81 | |
82 | - $message = 'Passing the $category as a string to setlocale() has been deprecated since PHP 4.2'; |
|
83 | - $isError = false; |
|
84 | - $errorCode = 'Deprecated'; |
|
85 | - $data = array($targetParam['raw']); |
|
82 | + $message = 'Passing the $category as a string to setlocale() has been deprecated since PHP 4.2'; |
|
83 | + $isError = false; |
|
84 | + $errorCode = 'Deprecated'; |
|
85 | + $data = array($targetParam['raw']); |
|
86 | 86 | |
87 | - if ($this->supportsAbove('7.0') === true) { |
|
88 | - $message .= ' and is removed since PHP 7.0'; |
|
89 | - $isError = true; |
|
90 | - $errorCode = 'Removed'; |
|
91 | - } |
|
87 | + if ($this->supportsAbove('7.0') === true) { |
|
88 | + $message .= ' and is removed since PHP 7.0'; |
|
89 | + $isError = true; |
|
90 | + $errorCode = 'Removed'; |
|
91 | + } |
|
92 | 92 | |
93 | - $message .= '; Pass one of the LC_* constants instead. Found: %s'; |
|
93 | + $message .= '; Pass one of the LC_* constants instead. Found: %s'; |
|
94 | 94 | |
95 | - $this->addMessage($phpcsFile, $message, $i, $isError, $errorCode, $data); |
|
96 | - break; |
|
97 | - } |
|
98 | - } |
|
95 | + $this->addMessage($phpcsFile, $message, $i, $isError, $errorCode, $data); |
|
96 | + break; |
|
97 | + } |
|
98 | + } |
|
99 | 99 | } |