@@ -29,134 +29,134 @@ |
||
29 | 29 | */ |
30 | 30 | class NewNullableTypesSniff extends Sniff |
31 | 31 | { |
32 | - /** |
|
33 | - * Returns an array of tokens this test wants to listen for. |
|
34 | - * |
|
35 | - * {@internal Not sniffing for T_NULLABLE which was introduced in PHPCS 2.7.2 |
|
36 | - * as in that case we can't distinguish between parameter type hints and |
|
37 | - * return type hints for the error message.}} |
|
38 | - * |
|
39 | - * @return array |
|
40 | - */ |
|
41 | - public function register() |
|
42 | - { |
|
43 | - $tokens = array( |
|
44 | - \T_FUNCTION, |
|
45 | - \T_CLOSURE, |
|
46 | - ); |
|
47 | - |
|
48 | - if (\defined('T_RETURN_TYPE')) { |
|
49 | - $tokens[] = \T_RETURN_TYPE; |
|
50 | - } |
|
51 | - |
|
52 | - return $tokens; |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * Processes this test, when one of its tokens is encountered. |
|
58 | - * |
|
59 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
60 | - * @param int $stackPtr The position of the current token |
|
61 | - * in the stack passed in $tokens. |
|
62 | - * |
|
63 | - * @return void |
|
64 | - */ |
|
65 | - public function process(File $phpcsFile, $stackPtr) |
|
66 | - { |
|
67 | - if ($this->supportsBelow('7.0') === false) { |
|
68 | - return; |
|
69 | - } |
|
70 | - |
|
71 | - $tokens = $phpcsFile->getTokens(); |
|
72 | - $tokenCode = $tokens[$stackPtr]['code']; |
|
73 | - |
|
74 | - if ($tokenCode === \T_FUNCTION || $tokenCode === \T_CLOSURE) { |
|
75 | - $this->processFunctionDeclaration($phpcsFile, $stackPtr); |
|
76 | - |
|
77 | - // Deal with older PHPCS version which don't recognize return type hints |
|
78 | - // as well as newer PHPCS versions (3.3.0+) where the tokenization has changed. |
|
79 | - $returnTypeHint = $this->getReturnTypeHintToken($phpcsFile, $stackPtr); |
|
80 | - if ($returnTypeHint !== false) { |
|
81 | - $this->processReturnType($phpcsFile, $returnTypeHint); |
|
82 | - } |
|
83 | - } else { |
|
84 | - $this->processReturnType($phpcsFile, $stackPtr); |
|
85 | - } |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * Process this test for function tokens. |
|
91 | - * |
|
92 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
93 | - * @param int $stackPtr The position of the current token |
|
94 | - * in the stack passed in $tokens. |
|
95 | - * |
|
96 | - * @return void |
|
97 | - */ |
|
98 | - protected function processFunctionDeclaration(File $phpcsFile, $stackPtr) |
|
99 | - { |
|
100 | - $params = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr); |
|
101 | - |
|
102 | - if (empty($params) === false && \is_array($params)) { |
|
103 | - foreach ($params as $param) { |
|
104 | - if ($param['nullable_type'] === true) { |
|
105 | - $phpcsFile->addError( |
|
106 | - 'Nullable type declarations are not supported in PHP 7.0 or earlier. Found: %s', |
|
107 | - $param['token'], |
|
108 | - 'typeDeclarationFound', |
|
109 | - array($param['type_hint']) |
|
110 | - ); |
|
111 | - } |
|
112 | - } |
|
113 | - } |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * Process this test for return type tokens. |
|
119 | - * |
|
120 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
121 | - * @param int $stackPtr The position of the current token |
|
122 | - * in the stack passed in $tokens. |
|
123 | - * |
|
124 | - * @return void |
|
125 | - */ |
|
126 | - protected function processReturnType(File $phpcsFile, $stackPtr) |
|
127 | - { |
|
128 | - $tokens = $phpcsFile->getTokens(); |
|
129 | - |
|
130 | - if (isset($tokens[($stackPtr - 1)]['code']) === false) { |
|
131 | - return; |
|
132 | - } |
|
133 | - |
|
134 | - $previous = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); |
|
135 | - |
|
136 | - // Deal with namespaced class names. |
|
137 | - if ($tokens[$previous]['code'] === \T_NS_SEPARATOR) { |
|
138 | - $validTokens = Tokens::$emptyTokens; |
|
139 | - $validTokens[\T_STRING] = true; |
|
140 | - $validTokens[\T_NS_SEPARATOR] = true; |
|
141 | - |
|
142 | - $stackPtr--; |
|
143 | - |
|
144 | - while (isset($validTokens[$tokens[($stackPtr - 1)]['code']]) === true) { |
|
145 | - $stackPtr--; |
|
146 | - } |
|
147 | - |
|
148 | - $previous = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); |
|
149 | - } |
|
150 | - |
|
151 | - // T_NULLABLE token was introduced in PHPCS 2.7.2. Before that it identified as T_INLINE_THEN. |
|
152 | - if ((\defined('T_NULLABLE') === true && $tokens[$previous]['type'] === 'T_NULLABLE') |
|
153 | - || (\defined('T_NULLABLE') === false && $tokens[$previous]['code'] === \T_INLINE_THEN) |
|
154 | - ) { |
|
155 | - $phpcsFile->addError( |
|
156 | - 'Nullable return types are not supported in PHP 7.0 or earlier.', |
|
157 | - $stackPtr, |
|
158 | - 'returnTypeFound' |
|
159 | - ); |
|
160 | - } |
|
161 | - } |
|
32 | + /** |
|
33 | + * Returns an array of tokens this test wants to listen for. |
|
34 | + * |
|
35 | + * {@internal Not sniffing for T_NULLABLE which was introduced in PHPCS 2.7.2 |
|
36 | + * as in that case we can't distinguish between parameter type hints and |
|
37 | + * return type hints for the error message.}} |
|
38 | + * |
|
39 | + * @return array |
|
40 | + */ |
|
41 | + public function register() |
|
42 | + { |
|
43 | + $tokens = array( |
|
44 | + \T_FUNCTION, |
|
45 | + \T_CLOSURE, |
|
46 | + ); |
|
47 | + |
|
48 | + if (\defined('T_RETURN_TYPE')) { |
|
49 | + $tokens[] = \T_RETURN_TYPE; |
|
50 | + } |
|
51 | + |
|
52 | + return $tokens; |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * Processes this test, when one of its tokens is encountered. |
|
58 | + * |
|
59 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
60 | + * @param int $stackPtr The position of the current token |
|
61 | + * in the stack passed in $tokens. |
|
62 | + * |
|
63 | + * @return void |
|
64 | + */ |
|
65 | + public function process(File $phpcsFile, $stackPtr) |
|
66 | + { |
|
67 | + if ($this->supportsBelow('7.0') === false) { |
|
68 | + return; |
|
69 | + } |
|
70 | + |
|
71 | + $tokens = $phpcsFile->getTokens(); |
|
72 | + $tokenCode = $tokens[$stackPtr]['code']; |
|
73 | + |
|
74 | + if ($tokenCode === \T_FUNCTION || $tokenCode === \T_CLOSURE) { |
|
75 | + $this->processFunctionDeclaration($phpcsFile, $stackPtr); |
|
76 | + |
|
77 | + // Deal with older PHPCS version which don't recognize return type hints |
|
78 | + // as well as newer PHPCS versions (3.3.0+) where the tokenization has changed. |
|
79 | + $returnTypeHint = $this->getReturnTypeHintToken($phpcsFile, $stackPtr); |
|
80 | + if ($returnTypeHint !== false) { |
|
81 | + $this->processReturnType($phpcsFile, $returnTypeHint); |
|
82 | + } |
|
83 | + } else { |
|
84 | + $this->processReturnType($phpcsFile, $stackPtr); |
|
85 | + } |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * Process this test for function tokens. |
|
91 | + * |
|
92 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
93 | + * @param int $stackPtr The position of the current token |
|
94 | + * in the stack passed in $tokens. |
|
95 | + * |
|
96 | + * @return void |
|
97 | + */ |
|
98 | + protected function processFunctionDeclaration(File $phpcsFile, $stackPtr) |
|
99 | + { |
|
100 | + $params = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr); |
|
101 | + |
|
102 | + if (empty($params) === false && \is_array($params)) { |
|
103 | + foreach ($params as $param) { |
|
104 | + if ($param['nullable_type'] === true) { |
|
105 | + $phpcsFile->addError( |
|
106 | + 'Nullable type declarations are not supported in PHP 7.0 or earlier. Found: %s', |
|
107 | + $param['token'], |
|
108 | + 'typeDeclarationFound', |
|
109 | + array($param['type_hint']) |
|
110 | + ); |
|
111 | + } |
|
112 | + } |
|
113 | + } |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * Process this test for return type tokens. |
|
119 | + * |
|
120 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
121 | + * @param int $stackPtr The position of the current token |
|
122 | + * in the stack passed in $tokens. |
|
123 | + * |
|
124 | + * @return void |
|
125 | + */ |
|
126 | + protected function processReturnType(File $phpcsFile, $stackPtr) |
|
127 | + { |
|
128 | + $tokens = $phpcsFile->getTokens(); |
|
129 | + |
|
130 | + if (isset($tokens[($stackPtr - 1)]['code']) === false) { |
|
131 | + return; |
|
132 | + } |
|
133 | + |
|
134 | + $previous = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); |
|
135 | + |
|
136 | + // Deal with namespaced class names. |
|
137 | + if ($tokens[$previous]['code'] === \T_NS_SEPARATOR) { |
|
138 | + $validTokens = Tokens::$emptyTokens; |
|
139 | + $validTokens[\T_STRING] = true; |
|
140 | + $validTokens[\T_NS_SEPARATOR] = true; |
|
141 | + |
|
142 | + $stackPtr--; |
|
143 | + |
|
144 | + while (isset($validTokens[$tokens[($stackPtr - 1)]['code']]) === true) { |
|
145 | + $stackPtr--; |
|
146 | + } |
|
147 | + |
|
148 | + $previous = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); |
|
149 | + } |
|
150 | + |
|
151 | + // T_NULLABLE token was introduced in PHPCS 2.7.2. Before that it identified as T_INLINE_THEN. |
|
152 | + if ((\defined('T_NULLABLE') === true && $tokens[$previous]['type'] === 'T_NULLABLE') |
|
153 | + || (\defined('T_NULLABLE') === false && $tokens[$previous]['code'] === \T_INLINE_THEN) |
|
154 | + ) { |
|
155 | + $phpcsFile->addError( |
|
156 | + 'Nullable return types are not supported in PHP 7.0 or earlier.', |
|
157 | + $stackPtr, |
|
158 | + 'returnTypeFound' |
|
159 | + ); |
|
160 | + } |
|
161 | + } |
|
162 | 162 | } |
@@ -28,151 +28,151 @@ |
||
28 | 28 | class NonStaticMagicMethodsSniff extends Sniff |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * A list of PHP magic methods and their visibility and static requirements. |
|
33 | - * |
|
34 | - * Method names in the array should be all *lowercase*. |
|
35 | - * Visibility can be either 'public', 'protected' or 'private'. |
|
36 | - * Static can be either 'true' - *must* be static, or 'false' - *must* be non-static. |
|
37 | - * When a method does not have a specific requirement for either visibility or static, |
|
38 | - * do *not* add the key. |
|
39 | - * |
|
40 | - * @var array(string) |
|
41 | - */ |
|
42 | - protected $magicMethods = array( |
|
43 | - '__get' => array( |
|
44 | - 'visibility' => 'public', |
|
45 | - 'static' => false, |
|
46 | - ), |
|
47 | - '__set' => array( |
|
48 | - 'visibility' => 'public', |
|
49 | - 'static' => false, |
|
50 | - ), |
|
51 | - '__isset' => array( |
|
52 | - 'visibility' => 'public', |
|
53 | - 'static' => false, |
|
54 | - ), |
|
55 | - '__unset' => array( |
|
56 | - 'visibility' => 'public', |
|
57 | - 'static' => false, |
|
58 | - ), |
|
59 | - '__call' => array( |
|
60 | - 'visibility' => 'public', |
|
61 | - 'static' => false, |
|
62 | - ), |
|
63 | - '__callstatic' => array( |
|
64 | - 'visibility' => 'public', |
|
65 | - 'static' => true, |
|
66 | - ), |
|
67 | - '__sleep' => array( |
|
68 | - 'visibility' => 'public', |
|
69 | - ), |
|
70 | - '__tostring' => array( |
|
71 | - 'visibility' => 'public', |
|
72 | - ), |
|
73 | - '__set_state' => array( |
|
74 | - 'static' => true, |
|
75 | - ), |
|
76 | - ); |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * Returns an array of tokens this test wants to listen for. |
|
81 | - * |
|
82 | - * @return array |
|
83 | - */ |
|
84 | - public function register() |
|
85 | - { |
|
86 | - $targets = array( |
|
87 | - \T_CLASS, |
|
88 | - \T_INTERFACE, |
|
89 | - \T_TRAIT, |
|
90 | - ); |
|
91 | - |
|
92 | - if (\defined('T_ANON_CLASS')) { |
|
93 | - $targets[] = \T_ANON_CLASS; |
|
94 | - } |
|
95 | - |
|
96 | - return $targets; |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * Processes this test, when one of its tokens is encountered. |
|
102 | - * |
|
103 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
104 | - * @param int $stackPtr The position of the current token in the |
|
105 | - * stack passed in $tokens. |
|
106 | - * |
|
107 | - * @return void |
|
108 | - */ |
|
109 | - public function process(File $phpcsFile, $stackPtr) |
|
110 | - { |
|
111 | - // Should be removed, the requirement was previously also there, 5.3 just started throwing a warning about it. |
|
112 | - if ($this->supportsAbove('5.3') === false) { |
|
113 | - return; |
|
114 | - } |
|
115 | - |
|
116 | - $tokens = $phpcsFile->getTokens(); |
|
117 | - |
|
118 | - if (isset($tokens[$stackPtr]['scope_closer']) === false) { |
|
119 | - return; |
|
120 | - } |
|
121 | - |
|
122 | - $classScopeCloser = $tokens[$stackPtr]['scope_closer']; |
|
123 | - $functionPtr = $stackPtr; |
|
124 | - |
|
125 | - // Find all the functions in this class or interface. |
|
126 | - while (($functionToken = $phpcsFile->findNext(\T_FUNCTION, $functionPtr, $classScopeCloser)) !== false) { |
|
127 | - /* |
|
31 | + /** |
|
32 | + * A list of PHP magic methods and their visibility and static requirements. |
|
33 | + * |
|
34 | + * Method names in the array should be all *lowercase*. |
|
35 | + * Visibility can be either 'public', 'protected' or 'private'. |
|
36 | + * Static can be either 'true' - *must* be static, or 'false' - *must* be non-static. |
|
37 | + * When a method does not have a specific requirement for either visibility or static, |
|
38 | + * do *not* add the key. |
|
39 | + * |
|
40 | + * @var array(string) |
|
41 | + */ |
|
42 | + protected $magicMethods = array( |
|
43 | + '__get' => array( |
|
44 | + 'visibility' => 'public', |
|
45 | + 'static' => false, |
|
46 | + ), |
|
47 | + '__set' => array( |
|
48 | + 'visibility' => 'public', |
|
49 | + 'static' => false, |
|
50 | + ), |
|
51 | + '__isset' => array( |
|
52 | + 'visibility' => 'public', |
|
53 | + 'static' => false, |
|
54 | + ), |
|
55 | + '__unset' => array( |
|
56 | + 'visibility' => 'public', |
|
57 | + 'static' => false, |
|
58 | + ), |
|
59 | + '__call' => array( |
|
60 | + 'visibility' => 'public', |
|
61 | + 'static' => false, |
|
62 | + ), |
|
63 | + '__callstatic' => array( |
|
64 | + 'visibility' => 'public', |
|
65 | + 'static' => true, |
|
66 | + ), |
|
67 | + '__sleep' => array( |
|
68 | + 'visibility' => 'public', |
|
69 | + ), |
|
70 | + '__tostring' => array( |
|
71 | + 'visibility' => 'public', |
|
72 | + ), |
|
73 | + '__set_state' => array( |
|
74 | + 'static' => true, |
|
75 | + ), |
|
76 | + ); |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * Returns an array of tokens this test wants to listen for. |
|
81 | + * |
|
82 | + * @return array |
|
83 | + */ |
|
84 | + public function register() |
|
85 | + { |
|
86 | + $targets = array( |
|
87 | + \T_CLASS, |
|
88 | + \T_INTERFACE, |
|
89 | + \T_TRAIT, |
|
90 | + ); |
|
91 | + |
|
92 | + if (\defined('T_ANON_CLASS')) { |
|
93 | + $targets[] = \T_ANON_CLASS; |
|
94 | + } |
|
95 | + |
|
96 | + return $targets; |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * Processes this test, when one of its tokens is encountered. |
|
102 | + * |
|
103 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
104 | + * @param int $stackPtr The position of the current token in the |
|
105 | + * stack passed in $tokens. |
|
106 | + * |
|
107 | + * @return void |
|
108 | + */ |
|
109 | + public function process(File $phpcsFile, $stackPtr) |
|
110 | + { |
|
111 | + // Should be removed, the requirement was previously also there, 5.3 just started throwing a warning about it. |
|
112 | + if ($this->supportsAbove('5.3') === false) { |
|
113 | + return; |
|
114 | + } |
|
115 | + |
|
116 | + $tokens = $phpcsFile->getTokens(); |
|
117 | + |
|
118 | + if (isset($tokens[$stackPtr]['scope_closer']) === false) { |
|
119 | + return; |
|
120 | + } |
|
121 | + |
|
122 | + $classScopeCloser = $tokens[$stackPtr]['scope_closer']; |
|
123 | + $functionPtr = $stackPtr; |
|
124 | + |
|
125 | + // Find all the functions in this class or interface. |
|
126 | + while (($functionToken = $phpcsFile->findNext(\T_FUNCTION, $functionPtr, $classScopeCloser)) !== false) { |
|
127 | + /* |
|
128 | 128 | * Get the scope closer for this function in order to know how |
129 | 129 | * to advance to the next function. |
130 | 130 | * If no body of function (e.g. for interfaces), there is |
131 | 131 | * no closing curly brace; advance the pointer differently. |
132 | 132 | */ |
133 | - if (isset($tokens[$functionToken]['scope_closer'])) { |
|
134 | - $scopeCloser = $tokens[$functionToken]['scope_closer']; |
|
135 | - } else { |
|
136 | - $scopeCloser = ($functionToken + 1); |
|
137 | - } |
|
138 | - |
|
139 | - $methodName = $phpcsFile->getDeclarationName($functionToken); |
|
140 | - $methodNameLc = strtolower($methodName); |
|
141 | - if (isset($this->magicMethods[$methodNameLc]) === false) { |
|
142 | - $functionPtr = $scopeCloser; |
|
143 | - continue; |
|
144 | - } |
|
145 | - |
|
146 | - $methodProperties = $phpcsFile->getMethodProperties($functionToken); |
|
147 | - $errorCodeBase = $this->stringToErrorCode($methodNameLc); |
|
148 | - |
|
149 | - if (isset($this->magicMethods[$methodNameLc]['visibility']) && $this->magicMethods[$methodNameLc]['visibility'] !== $methodProperties['scope']) { |
|
150 | - $error = 'Visibility for magic method %s must be %s. Found: %s'; |
|
151 | - $errorCode = $errorCodeBase . 'MethodVisibility'; |
|
152 | - $data = array( |
|
153 | - $methodName, |
|
154 | - $this->magicMethods[$methodNameLc]['visibility'], |
|
155 | - $methodProperties['scope'], |
|
156 | - ); |
|
157 | - |
|
158 | - $phpcsFile->addError($error, $functionToken, $errorCode, $data); |
|
159 | - } |
|
160 | - |
|
161 | - if (isset($this->magicMethods[$methodNameLc]['static']) && $this->magicMethods[$methodNameLc]['static'] !== $methodProperties['is_static']) { |
|
162 | - $error = 'Magic method %s cannot be defined as static.'; |
|
163 | - $errorCode = $errorCodeBase . 'MethodStatic'; |
|
164 | - $data = array($methodName); |
|
165 | - |
|
166 | - if ($this->magicMethods[$methodNameLc]['static'] === true) { |
|
167 | - $error = 'Magic method %s must be defined as static.'; |
|
168 | - $errorCode = $errorCodeBase . 'MethodNonStatic'; |
|
169 | - } |
|
170 | - |
|
171 | - $phpcsFile->addError($error, $functionToken, $errorCode, $data); |
|
172 | - } |
|
173 | - |
|
174 | - // Advance to next function. |
|
175 | - $functionPtr = $scopeCloser; |
|
176 | - } |
|
177 | - } |
|
133 | + if (isset($tokens[$functionToken]['scope_closer'])) { |
|
134 | + $scopeCloser = $tokens[$functionToken]['scope_closer']; |
|
135 | + } else { |
|
136 | + $scopeCloser = ($functionToken + 1); |
|
137 | + } |
|
138 | + |
|
139 | + $methodName = $phpcsFile->getDeclarationName($functionToken); |
|
140 | + $methodNameLc = strtolower($methodName); |
|
141 | + if (isset($this->magicMethods[$methodNameLc]) === false) { |
|
142 | + $functionPtr = $scopeCloser; |
|
143 | + continue; |
|
144 | + } |
|
145 | + |
|
146 | + $methodProperties = $phpcsFile->getMethodProperties($functionToken); |
|
147 | + $errorCodeBase = $this->stringToErrorCode($methodNameLc); |
|
148 | + |
|
149 | + if (isset($this->magicMethods[$methodNameLc]['visibility']) && $this->magicMethods[$methodNameLc]['visibility'] !== $methodProperties['scope']) { |
|
150 | + $error = 'Visibility for magic method %s must be %s. Found: %s'; |
|
151 | + $errorCode = $errorCodeBase . 'MethodVisibility'; |
|
152 | + $data = array( |
|
153 | + $methodName, |
|
154 | + $this->magicMethods[$methodNameLc]['visibility'], |
|
155 | + $methodProperties['scope'], |
|
156 | + ); |
|
157 | + |
|
158 | + $phpcsFile->addError($error, $functionToken, $errorCode, $data); |
|
159 | + } |
|
160 | + |
|
161 | + if (isset($this->magicMethods[$methodNameLc]['static']) && $this->magicMethods[$methodNameLc]['static'] !== $methodProperties['is_static']) { |
|
162 | + $error = 'Magic method %s cannot be defined as static.'; |
|
163 | + $errorCode = $errorCodeBase . 'MethodStatic'; |
|
164 | + $data = array($methodName); |
|
165 | + |
|
166 | + if ($this->magicMethods[$methodNameLc]['static'] === true) { |
|
167 | + $error = 'Magic method %s must be defined as static.'; |
|
168 | + $errorCode = $errorCodeBase . 'MethodNonStatic'; |
|
169 | + } |
|
170 | + |
|
171 | + $phpcsFile->addError($error, $functionToken, $errorCode, $data); |
|
172 | + } |
|
173 | + |
|
174 | + // Advance to next function. |
|
175 | + $functionPtr = $scopeCloser; |
|
176 | + } |
|
177 | + } |
|
178 | 178 | } |
@@ -26,292 +26,292 @@ |
||
26 | 26 | */ |
27 | 27 | class RemovedExtensionsSniff extends AbstractRemovedFeatureSniff |
28 | 28 | { |
29 | - /** |
|
30 | - * A list of functions to whitelist, if any. |
|
31 | - * |
|
32 | - * This is intended for projects using functions which start with the same |
|
33 | - * prefix as one of the removed extensions. |
|
34 | - * |
|
35 | - * This property can be set from the ruleset, like so: |
|
36 | - * <rule ref="PHPCompatibility.Extensions.RemovedExtensions"> |
|
37 | - * <properties> |
|
38 | - * <property name="functionWhitelist" type="array" value="mysql_to_rfc3339,mysql_another_function" /> |
|
39 | - * </properties> |
|
40 | - * </rule> |
|
41 | - * |
|
42 | - * @var array |
|
43 | - */ |
|
44 | - public $functionWhitelist; |
|
29 | + /** |
|
30 | + * A list of functions to whitelist, if any. |
|
31 | + * |
|
32 | + * This is intended for projects using functions which start with the same |
|
33 | + * prefix as one of the removed extensions. |
|
34 | + * |
|
35 | + * This property can be set from the ruleset, like so: |
|
36 | + * <rule ref="PHPCompatibility.Extensions.RemovedExtensions"> |
|
37 | + * <properties> |
|
38 | + * <property name="functionWhitelist" type="array" value="mysql_to_rfc3339,mysql_another_function" /> |
|
39 | + * </properties> |
|
40 | + * </rule> |
|
41 | + * |
|
42 | + * @var array |
|
43 | + */ |
|
44 | + public $functionWhitelist; |
|
45 | 45 | |
46 | - /** |
|
47 | - * A list of removed extensions with their alternative, if any |
|
48 | - * |
|
49 | - * The array lists : version number with false (deprecated) and true (removed). |
|
50 | - * If's sufficient to list the first version where the extension was deprecated/removed. |
|
51 | - * |
|
52 | - * @var array(string|null) |
|
53 | - */ |
|
54 | - protected $removedExtensions = array( |
|
55 | - 'activescript' => array( |
|
56 | - '5.1' => true, |
|
57 | - 'alternative' => 'pecl/activescript', |
|
58 | - ), |
|
59 | - 'cpdf' => array( |
|
60 | - '5.1' => true, |
|
61 | - 'alternative' => 'pecl/pdflib', |
|
62 | - ), |
|
63 | - 'dbase' => array( |
|
64 | - '5.3' => true, |
|
65 | - 'alternative' => null, |
|
66 | - ), |
|
67 | - 'dbx' => array( |
|
68 | - '5.1' => true, |
|
69 | - 'alternative' => 'pecl/dbx', |
|
70 | - ), |
|
71 | - 'dio' => array( |
|
72 | - '5.1' => true, |
|
73 | - 'alternative' => 'pecl/dio', |
|
74 | - ), |
|
75 | - 'ereg' => array( |
|
76 | - '5.3' => false, |
|
77 | - '7.0' => true, |
|
78 | - 'alternative' => 'pcre', |
|
79 | - ), |
|
80 | - 'fam' => array( |
|
81 | - '5.1' => true, |
|
82 | - 'alternative' => null, |
|
83 | - ), |
|
84 | - 'fbsql' => array( |
|
85 | - '5.3' => true, |
|
86 | - 'alternative' => null, |
|
87 | - ), |
|
88 | - 'fdf' => array( |
|
89 | - '5.3' => true, |
|
90 | - 'alternative' => 'pecl/fdf', |
|
91 | - ), |
|
92 | - 'filepro' => array( |
|
93 | - '5.2' => true, |
|
94 | - 'alternative' => null, |
|
95 | - ), |
|
96 | - 'hw_api' => array( |
|
97 | - '5.2' => true, |
|
98 | - 'alternative' => null, |
|
99 | - ), |
|
100 | - 'ibase' => array( |
|
101 | - '7.4' => true, |
|
102 | - 'alternative' => 'pecl/ibase', |
|
103 | - ), |
|
104 | - 'ingres' => array( |
|
105 | - '5.1' => true, |
|
106 | - 'alternative' => 'pecl/ingres', |
|
107 | - ), |
|
108 | - 'ircg' => array( |
|
109 | - '5.1' => true, |
|
110 | - 'alternative' => null, |
|
111 | - ), |
|
112 | - 'mcrypt' => array( |
|
113 | - '7.1' => false, |
|
114 | - '7.2' => true, |
|
115 | - 'alternative' => 'openssl (preferred) or pecl/mcrypt once available', |
|
116 | - ), |
|
117 | - 'mcve' => array( |
|
118 | - '5.1' => true, |
|
119 | - 'alternative' => 'pecl/mcve', |
|
120 | - ), |
|
121 | - 'ming' => array( |
|
122 | - '5.3' => true, |
|
123 | - 'alternative' => 'pecl/ming', |
|
124 | - ), |
|
125 | - 'mnogosearch' => array( |
|
126 | - '5.1' => true, |
|
127 | - 'alternative' => null, |
|
128 | - ), |
|
129 | - 'msql' => array( |
|
130 | - '5.3' => true, |
|
131 | - 'alternative' => null, |
|
132 | - ), |
|
133 | - 'mssql' => array( |
|
134 | - '7.0' => true, |
|
135 | - 'alternative' => null, |
|
136 | - ), |
|
137 | - 'mysql_' => array( |
|
138 | - '5.5' => false, |
|
139 | - '7.0' => true, |
|
140 | - 'alternative' => 'mysqli', |
|
141 | - ), |
|
142 | - 'ncurses' => array( |
|
143 | - '5.3' => true, |
|
144 | - 'alternative' => 'pecl/ncurses', |
|
145 | - ), |
|
146 | - 'oracle' => array( |
|
147 | - '5.1' => true, |
|
148 | - 'alternative' => 'oci8 or pdo_oci', |
|
149 | - ), |
|
150 | - 'ovrimos' => array( |
|
151 | - '5.1' => true, |
|
152 | - 'alternative' => null, |
|
153 | - ), |
|
154 | - 'pfpro_' => array( |
|
155 | - '5.1' => true, |
|
156 | - 'alternative' => null, |
|
157 | - ), |
|
158 | - 'sqlite' => array( |
|
159 | - '5.4' => true, |
|
160 | - 'alternative' => null, |
|
161 | - ), |
|
162 | - // Has to be before `sybase` as otherwise it will never match. |
|
163 | - 'sybase_ct' => array( |
|
164 | - '7.0' => true, |
|
165 | - 'alternative' => null, |
|
166 | - ), |
|
167 | - 'sybase' => array( |
|
168 | - '5.3' => true, |
|
169 | - 'alternative' => 'sybase_ct', |
|
170 | - ), |
|
171 | - 'w32api' => array( |
|
172 | - '5.1' => true, |
|
173 | - 'alternative' => 'pecl/ffi', |
|
174 | - ), |
|
175 | - 'wddx' => array( |
|
176 | - '7.4' => true, |
|
177 | - 'alternative' => 'pecl/wddx', |
|
178 | - ), |
|
179 | - 'yp' => array( |
|
180 | - '5.1' => true, |
|
181 | - 'alternative' => null, |
|
182 | - ), |
|
183 | - ); |
|
46 | + /** |
|
47 | + * A list of removed extensions with their alternative, if any |
|
48 | + * |
|
49 | + * The array lists : version number with false (deprecated) and true (removed). |
|
50 | + * If's sufficient to list the first version where the extension was deprecated/removed. |
|
51 | + * |
|
52 | + * @var array(string|null) |
|
53 | + */ |
|
54 | + protected $removedExtensions = array( |
|
55 | + 'activescript' => array( |
|
56 | + '5.1' => true, |
|
57 | + 'alternative' => 'pecl/activescript', |
|
58 | + ), |
|
59 | + 'cpdf' => array( |
|
60 | + '5.1' => true, |
|
61 | + 'alternative' => 'pecl/pdflib', |
|
62 | + ), |
|
63 | + 'dbase' => array( |
|
64 | + '5.3' => true, |
|
65 | + 'alternative' => null, |
|
66 | + ), |
|
67 | + 'dbx' => array( |
|
68 | + '5.1' => true, |
|
69 | + 'alternative' => 'pecl/dbx', |
|
70 | + ), |
|
71 | + 'dio' => array( |
|
72 | + '5.1' => true, |
|
73 | + 'alternative' => 'pecl/dio', |
|
74 | + ), |
|
75 | + 'ereg' => array( |
|
76 | + '5.3' => false, |
|
77 | + '7.0' => true, |
|
78 | + 'alternative' => 'pcre', |
|
79 | + ), |
|
80 | + 'fam' => array( |
|
81 | + '5.1' => true, |
|
82 | + 'alternative' => null, |
|
83 | + ), |
|
84 | + 'fbsql' => array( |
|
85 | + '5.3' => true, |
|
86 | + 'alternative' => null, |
|
87 | + ), |
|
88 | + 'fdf' => array( |
|
89 | + '5.3' => true, |
|
90 | + 'alternative' => 'pecl/fdf', |
|
91 | + ), |
|
92 | + 'filepro' => array( |
|
93 | + '5.2' => true, |
|
94 | + 'alternative' => null, |
|
95 | + ), |
|
96 | + 'hw_api' => array( |
|
97 | + '5.2' => true, |
|
98 | + 'alternative' => null, |
|
99 | + ), |
|
100 | + 'ibase' => array( |
|
101 | + '7.4' => true, |
|
102 | + 'alternative' => 'pecl/ibase', |
|
103 | + ), |
|
104 | + 'ingres' => array( |
|
105 | + '5.1' => true, |
|
106 | + 'alternative' => 'pecl/ingres', |
|
107 | + ), |
|
108 | + 'ircg' => array( |
|
109 | + '5.1' => true, |
|
110 | + 'alternative' => null, |
|
111 | + ), |
|
112 | + 'mcrypt' => array( |
|
113 | + '7.1' => false, |
|
114 | + '7.2' => true, |
|
115 | + 'alternative' => 'openssl (preferred) or pecl/mcrypt once available', |
|
116 | + ), |
|
117 | + 'mcve' => array( |
|
118 | + '5.1' => true, |
|
119 | + 'alternative' => 'pecl/mcve', |
|
120 | + ), |
|
121 | + 'ming' => array( |
|
122 | + '5.3' => true, |
|
123 | + 'alternative' => 'pecl/ming', |
|
124 | + ), |
|
125 | + 'mnogosearch' => array( |
|
126 | + '5.1' => true, |
|
127 | + 'alternative' => null, |
|
128 | + ), |
|
129 | + 'msql' => array( |
|
130 | + '5.3' => true, |
|
131 | + 'alternative' => null, |
|
132 | + ), |
|
133 | + 'mssql' => array( |
|
134 | + '7.0' => true, |
|
135 | + 'alternative' => null, |
|
136 | + ), |
|
137 | + 'mysql_' => array( |
|
138 | + '5.5' => false, |
|
139 | + '7.0' => true, |
|
140 | + 'alternative' => 'mysqli', |
|
141 | + ), |
|
142 | + 'ncurses' => array( |
|
143 | + '5.3' => true, |
|
144 | + 'alternative' => 'pecl/ncurses', |
|
145 | + ), |
|
146 | + 'oracle' => array( |
|
147 | + '5.1' => true, |
|
148 | + 'alternative' => 'oci8 or pdo_oci', |
|
149 | + ), |
|
150 | + 'ovrimos' => array( |
|
151 | + '5.1' => true, |
|
152 | + 'alternative' => null, |
|
153 | + ), |
|
154 | + 'pfpro_' => array( |
|
155 | + '5.1' => true, |
|
156 | + 'alternative' => null, |
|
157 | + ), |
|
158 | + 'sqlite' => array( |
|
159 | + '5.4' => true, |
|
160 | + 'alternative' => null, |
|
161 | + ), |
|
162 | + // Has to be before `sybase` as otherwise it will never match. |
|
163 | + 'sybase_ct' => array( |
|
164 | + '7.0' => true, |
|
165 | + 'alternative' => null, |
|
166 | + ), |
|
167 | + 'sybase' => array( |
|
168 | + '5.3' => true, |
|
169 | + 'alternative' => 'sybase_ct', |
|
170 | + ), |
|
171 | + 'w32api' => array( |
|
172 | + '5.1' => true, |
|
173 | + 'alternative' => 'pecl/ffi', |
|
174 | + ), |
|
175 | + 'wddx' => array( |
|
176 | + '7.4' => true, |
|
177 | + 'alternative' => 'pecl/wddx', |
|
178 | + ), |
|
179 | + 'yp' => array( |
|
180 | + '5.1' => true, |
|
181 | + 'alternative' => null, |
|
182 | + ), |
|
183 | + ); |
|
184 | 184 | |
185 | - /** |
|
186 | - * Returns an array of tokens this test wants to listen for. |
|
187 | - * |
|
188 | - * @return array |
|
189 | - */ |
|
190 | - public function register() |
|
191 | - { |
|
192 | - // Handle case-insensitivity of function names. |
|
193 | - $this->removedExtensions = $this->arrayKeysToLowercase($this->removedExtensions); |
|
185 | + /** |
|
186 | + * Returns an array of tokens this test wants to listen for. |
|
187 | + * |
|
188 | + * @return array |
|
189 | + */ |
|
190 | + public function register() |
|
191 | + { |
|
192 | + // Handle case-insensitivity of function names. |
|
193 | + $this->removedExtensions = $this->arrayKeysToLowercase($this->removedExtensions); |
|
194 | 194 | |
195 | - return array(\T_STRING); |
|
196 | - } |
|
195 | + return array(\T_STRING); |
|
196 | + } |
|
197 | 197 | |
198 | - /** |
|
199 | - * Processes this test, when one of its tokens is encountered. |
|
200 | - * |
|
201 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
202 | - * @param int $stackPtr The position of the current token in the |
|
203 | - * stack passed in $tokens. |
|
204 | - * |
|
205 | - * @return void |
|
206 | - */ |
|
207 | - public function process(File $phpcsFile, $stackPtr) |
|
208 | - { |
|
209 | - $tokens = $phpcsFile->getTokens(); |
|
198 | + /** |
|
199 | + * Processes this test, when one of its tokens is encountered. |
|
200 | + * |
|
201 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
202 | + * @param int $stackPtr The position of the current token in the |
|
203 | + * stack passed in $tokens. |
|
204 | + * |
|
205 | + * @return void |
|
206 | + */ |
|
207 | + public function process(File $phpcsFile, $stackPtr) |
|
208 | + { |
|
209 | + $tokens = $phpcsFile->getTokens(); |
|
210 | 210 | |
211 | - // Find the next non-empty token. |
|
212 | - $openBracket = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); |
|
211 | + // Find the next non-empty token. |
|
212 | + $openBracket = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); |
|
213 | 213 | |
214 | - if ($tokens[$openBracket]['code'] !== \T_OPEN_PARENTHESIS) { |
|
215 | - // Not a function call. |
|
216 | - return; |
|
217 | - } |
|
214 | + if ($tokens[$openBracket]['code'] !== \T_OPEN_PARENTHESIS) { |
|
215 | + // Not a function call. |
|
216 | + return; |
|
217 | + } |
|
218 | 218 | |
219 | - if (isset($tokens[$openBracket]['parenthesis_closer']) === false) { |
|
220 | - // Not a function call. |
|
221 | - return; |
|
222 | - } |
|
219 | + if (isset($tokens[$openBracket]['parenthesis_closer']) === false) { |
|
220 | + // Not a function call. |
|
221 | + return; |
|
222 | + } |
|
223 | 223 | |
224 | - // Find the previous non-empty token. |
|
225 | - $search = Tokens::$emptyTokens; |
|
226 | - $search[] = \T_BITWISE_AND; |
|
227 | - $previous = $phpcsFile->findPrevious($search, ($stackPtr - 1), null, true); |
|
228 | - if ($tokens[$previous]['code'] === \T_FUNCTION) { |
|
229 | - // It's a function definition, not a function call. |
|
230 | - return; |
|
231 | - } |
|
224 | + // Find the previous non-empty token. |
|
225 | + $search = Tokens::$emptyTokens; |
|
226 | + $search[] = \T_BITWISE_AND; |
|
227 | + $previous = $phpcsFile->findPrevious($search, ($stackPtr - 1), null, true); |
|
228 | + if ($tokens[$previous]['code'] === \T_FUNCTION) { |
|
229 | + // It's a function definition, not a function call. |
|
230 | + return; |
|
231 | + } |
|
232 | 232 | |
233 | - if ($tokens[$previous]['code'] === \T_NEW) { |
|
234 | - // We are creating an object, not calling a function. |
|
235 | - return; |
|
236 | - } |
|
233 | + if ($tokens[$previous]['code'] === \T_NEW) { |
|
234 | + // We are creating an object, not calling a function. |
|
235 | + return; |
|
236 | + } |
|
237 | 237 | |
238 | - if ($tokens[$previous]['code'] === \T_OBJECT_OPERATOR) { |
|
239 | - // We are calling a method of an object. |
|
240 | - return; |
|
241 | - } |
|
238 | + if ($tokens[$previous]['code'] === \T_OBJECT_OPERATOR) { |
|
239 | + // We are calling a method of an object. |
|
240 | + return; |
|
241 | + } |
|
242 | 242 | |
243 | - $function = $tokens[$stackPtr]['content']; |
|
244 | - $functionLc = strtolower($function); |
|
243 | + $function = $tokens[$stackPtr]['content']; |
|
244 | + $functionLc = strtolower($function); |
|
245 | 245 | |
246 | - if ($this->isWhiteListed($functionLc) === true) { |
|
247 | - // Function is whitelisted. |
|
248 | - return; |
|
249 | - } |
|
246 | + if ($this->isWhiteListed($functionLc) === true) { |
|
247 | + // Function is whitelisted. |
|
248 | + return; |
|
249 | + } |
|
250 | 250 | |
251 | - foreach ($this->removedExtensions as $extension => $versionList) { |
|
252 | - if (strpos($functionLc, $extension) === 0) { |
|
253 | - $itemInfo = array( |
|
254 | - 'name' => $extension, |
|
255 | - ); |
|
256 | - $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
257 | - break; |
|
258 | - } |
|
259 | - } |
|
260 | - } |
|
251 | + foreach ($this->removedExtensions as $extension => $versionList) { |
|
252 | + if (strpos($functionLc, $extension) === 0) { |
|
253 | + $itemInfo = array( |
|
254 | + 'name' => $extension, |
|
255 | + ); |
|
256 | + $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
257 | + break; |
|
258 | + } |
|
259 | + } |
|
260 | + } |
|
261 | 261 | |
262 | 262 | |
263 | - /** |
|
264 | - * Is the current function being checked whitelisted ? |
|
265 | - * |
|
266 | - * Parsing the list late as it may be provided as a property, but also inline. |
|
267 | - * |
|
268 | - * @param string $content Content of the current token. |
|
269 | - * |
|
270 | - * @return bool |
|
271 | - */ |
|
272 | - protected function isWhiteListed($content) |
|
273 | - { |
|
274 | - if (isset($this->functionWhitelist) === false) { |
|
275 | - return false; |
|
276 | - } |
|
263 | + /** |
|
264 | + * Is the current function being checked whitelisted ? |
|
265 | + * |
|
266 | + * Parsing the list late as it may be provided as a property, but also inline. |
|
267 | + * |
|
268 | + * @param string $content Content of the current token. |
|
269 | + * |
|
270 | + * @return bool |
|
271 | + */ |
|
272 | + protected function isWhiteListed($content) |
|
273 | + { |
|
274 | + if (isset($this->functionWhitelist) === false) { |
|
275 | + return false; |
|
276 | + } |
|
277 | 277 | |
278 | - if (\is_string($this->functionWhitelist) === true) { |
|
279 | - if (strpos($this->functionWhitelist, ',') !== false) { |
|
280 | - $this->functionWhitelist = explode(',', $this->functionWhitelist); |
|
281 | - } else { |
|
282 | - $this->functionWhitelist = (array) $this->functionWhitelist; |
|
283 | - } |
|
284 | - } |
|
278 | + if (\is_string($this->functionWhitelist) === true) { |
|
279 | + if (strpos($this->functionWhitelist, ',') !== false) { |
|
280 | + $this->functionWhitelist = explode(',', $this->functionWhitelist); |
|
281 | + } else { |
|
282 | + $this->functionWhitelist = (array) $this->functionWhitelist; |
|
283 | + } |
|
284 | + } |
|
285 | 285 | |
286 | - if (\is_array($this->functionWhitelist) === true) { |
|
287 | - $this->functionWhitelist = array_map('strtolower', $this->functionWhitelist); |
|
288 | - return \in_array($content, $this->functionWhitelist, true); |
|
289 | - } |
|
286 | + if (\is_array($this->functionWhitelist) === true) { |
|
287 | + $this->functionWhitelist = array_map('strtolower', $this->functionWhitelist); |
|
288 | + return \in_array($content, $this->functionWhitelist, true); |
|
289 | + } |
|
290 | 290 | |
291 | - return false; |
|
292 | - } |
|
291 | + return false; |
|
292 | + } |
|
293 | 293 | |
294 | 294 | |
295 | - /** |
|
296 | - * Get the relevant sub-array for a specific item from a multi-dimensional array. |
|
297 | - * |
|
298 | - * @param array $itemInfo Base information about the item. |
|
299 | - * |
|
300 | - * @return array Version and other information about the item. |
|
301 | - */ |
|
302 | - public function getItemArray(array $itemInfo) |
|
303 | - { |
|
304 | - return $this->removedExtensions[$itemInfo['name']]; |
|
305 | - } |
|
295 | + /** |
|
296 | + * Get the relevant sub-array for a specific item from a multi-dimensional array. |
|
297 | + * |
|
298 | + * @param array $itemInfo Base information about the item. |
|
299 | + * |
|
300 | + * @return array Version and other information about the item. |
|
301 | + */ |
|
302 | + public function getItemArray(array $itemInfo) |
|
303 | + { |
|
304 | + return $this->removedExtensions[$itemInfo['name']]; |
|
305 | + } |
|
306 | 306 | |
307 | 307 | |
308 | - /** |
|
309 | - * Get the error message template for this sniff. |
|
310 | - * |
|
311 | - * @return string |
|
312 | - */ |
|
313 | - protected function getErrorMsgTemplate() |
|
314 | - { |
|
315 | - return "Extension '%s' is "; |
|
316 | - } |
|
308 | + /** |
|
309 | + * Get the error message template for this sniff. |
|
310 | + * |
|
311 | + * @return string |
|
312 | + */ |
|
313 | + protected function getErrorMsgTemplate() |
|
314 | + { |
|
315 | + return "Extension '%s' is "; |
|
316 | + } |
|
317 | 317 | } |
@@ -26,80 +26,80 @@ |
||
26 | 26 | */ |
27 | 27 | class NewGroupUseDeclarationsSniff extends Sniff |
28 | 28 | { |
29 | - /** |
|
30 | - * Returns an array of tokens this test wants to listen for. |
|
31 | - * |
|
32 | - * @return array |
|
33 | - */ |
|
34 | - public function register() |
|
35 | - { |
|
36 | - if (\defined('T_OPEN_USE_GROUP')) { |
|
37 | - return array(\T_OPEN_USE_GROUP); |
|
38 | - } else { |
|
39 | - return array(\T_USE); |
|
40 | - } |
|
41 | - } |
|
29 | + /** |
|
30 | + * Returns an array of tokens this test wants to listen for. |
|
31 | + * |
|
32 | + * @return array |
|
33 | + */ |
|
34 | + public function register() |
|
35 | + { |
|
36 | + if (\defined('T_OPEN_USE_GROUP')) { |
|
37 | + return array(\T_OPEN_USE_GROUP); |
|
38 | + } else { |
|
39 | + return array(\T_USE); |
|
40 | + } |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * Processes this test, when one of its tokens is encountered. |
|
46 | - * |
|
47 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
48 | - * @param int $stackPtr The position of the current token in |
|
49 | - * the stack passed in $tokens. |
|
50 | - * |
|
51 | - * @return void |
|
52 | - */ |
|
53 | - public function process(File $phpcsFile, $stackPtr) |
|
54 | - { |
|
55 | - if ($this->supportsBelow('7.1') === false) { |
|
56 | - return; |
|
57 | - } |
|
44 | + /** |
|
45 | + * Processes this test, when one of its tokens is encountered. |
|
46 | + * |
|
47 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
48 | + * @param int $stackPtr The position of the current token in |
|
49 | + * the stack passed in $tokens. |
|
50 | + * |
|
51 | + * @return void |
|
52 | + */ |
|
53 | + public function process(File $phpcsFile, $stackPtr) |
|
54 | + { |
|
55 | + if ($this->supportsBelow('7.1') === false) { |
|
56 | + return; |
|
57 | + } |
|
58 | 58 | |
59 | - $tokens = $phpcsFile->getTokens(); |
|
60 | - $token = $tokens[$stackPtr]; |
|
59 | + $tokens = $phpcsFile->getTokens(); |
|
60 | + $token = $tokens[$stackPtr]; |
|
61 | 61 | |
62 | - // Deal with PHPCS pre-2.6.0. |
|
63 | - if ($token['code'] === \T_USE) { |
|
64 | - $hasCurlyBrace = $phpcsFile->findNext(\T_OPEN_CURLY_BRACKET, ($stackPtr + 1), null, false, null, true); |
|
65 | - if ($hasCurlyBrace === false) { |
|
66 | - return; |
|
67 | - } |
|
62 | + // Deal with PHPCS pre-2.6.0. |
|
63 | + if ($token['code'] === \T_USE) { |
|
64 | + $hasCurlyBrace = $phpcsFile->findNext(\T_OPEN_CURLY_BRACKET, ($stackPtr + 1), null, false, null, true); |
|
65 | + if ($hasCurlyBrace === false) { |
|
66 | + return; |
|
67 | + } |
|
68 | 68 | |
69 | - $prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($hasCurlyBrace - 1), null, true); |
|
70 | - if ($prevToken === false || $tokens[$prevToken]['code'] !== \T_NS_SEPARATOR) { |
|
71 | - return; |
|
72 | - } |
|
69 | + $prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($hasCurlyBrace - 1), null, true); |
|
70 | + if ($prevToken === false || $tokens[$prevToken]['code'] !== \T_NS_SEPARATOR) { |
|
71 | + return; |
|
72 | + } |
|
73 | 73 | |
74 | - $stackPtr = $hasCurlyBrace; |
|
75 | - } |
|
74 | + $stackPtr = $hasCurlyBrace; |
|
75 | + } |
|
76 | 76 | |
77 | - // Still here ? In that case, it is a group use statement. |
|
78 | - if ($this->supportsBelow('5.6') === true) { |
|
79 | - $phpcsFile->addError( |
|
80 | - 'Group use declarations are not allowed in PHP 5.6 or earlier', |
|
81 | - $stackPtr, |
|
82 | - 'Found' |
|
83 | - ); |
|
84 | - } |
|
77 | + // Still here ? In that case, it is a group use statement. |
|
78 | + if ($this->supportsBelow('5.6') === true) { |
|
79 | + $phpcsFile->addError( |
|
80 | + 'Group use declarations are not allowed in PHP 5.6 or earlier', |
|
81 | + $stackPtr, |
|
82 | + 'Found' |
|
83 | + ); |
|
84 | + } |
|
85 | 85 | |
86 | - $closers = array(\T_CLOSE_CURLY_BRACKET); |
|
87 | - if (\defined('T_CLOSE_USE_GROUP')) { |
|
88 | - $closers[] = \T_CLOSE_USE_GROUP; |
|
89 | - } |
|
86 | + $closers = array(\T_CLOSE_CURLY_BRACKET); |
|
87 | + if (\defined('T_CLOSE_USE_GROUP')) { |
|
88 | + $closers[] = \T_CLOSE_USE_GROUP; |
|
89 | + } |
|
90 | 90 | |
91 | - $closeCurly = $phpcsFile->findNext($closers, ($stackPtr + 1), null, false, null, true); |
|
92 | - if ($closeCurly === false) { |
|
93 | - return; |
|
94 | - } |
|
91 | + $closeCurly = $phpcsFile->findNext($closers, ($stackPtr + 1), null, false, null, true); |
|
92 | + if ($closeCurly === false) { |
|
93 | + return; |
|
94 | + } |
|
95 | 95 | |
96 | - $prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($closeCurly - 1), null, true); |
|
97 | - if ($tokens[$prevToken]['code'] === \T_COMMA) { |
|
98 | - $phpcsFile->addError( |
|
99 | - 'Trailing comma\'s are not allowed in group use statements in PHP 7.1 or earlier', |
|
100 | - $prevToken, |
|
101 | - 'TrailingCommaFound' |
|
102 | - ); |
|
103 | - } |
|
104 | - } |
|
96 | + $prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($closeCurly - 1), null, true); |
|
97 | + if ($tokens[$prevToken]['code'] === \T_COMMA) { |
|
98 | + $phpcsFile->addError( |
|
99 | + 'Trailing comma\'s are not allowed in group use statements in PHP 7.1 or earlier', |
|
100 | + $prevToken, |
|
101 | + 'TrailingCommaFound' |
|
102 | + ); |
|
103 | + } |
|
104 | + } |
|
105 | 105 | } |
@@ -31,72 +31,72 @@ |
||
31 | 31 | class NewUseConstFunctionSniff extends Sniff |
32 | 32 | { |
33 | 33 | |
34 | - /** |
|
35 | - * A list of keywords that can follow use statements. |
|
36 | - * |
|
37 | - * @var array(string => string) |
|
38 | - */ |
|
39 | - protected $validUseNames = array( |
|
40 | - 'const' => true, |
|
41 | - 'function' => true, |
|
42 | - ); |
|
34 | + /** |
|
35 | + * A list of keywords that can follow use statements. |
|
36 | + * |
|
37 | + * @var array(string => string) |
|
38 | + */ |
|
39 | + protected $validUseNames = array( |
|
40 | + 'const' => true, |
|
41 | + 'function' => true, |
|
42 | + ); |
|
43 | 43 | |
44 | - /** |
|
45 | - * Returns an array of tokens this test wants to listen for. |
|
46 | - * |
|
47 | - * @return array |
|
48 | - */ |
|
49 | - public function register() |
|
50 | - { |
|
51 | - return array(\T_USE); |
|
52 | - } |
|
44 | + /** |
|
45 | + * Returns an array of tokens this test wants to listen for. |
|
46 | + * |
|
47 | + * @return array |
|
48 | + */ |
|
49 | + public function register() |
|
50 | + { |
|
51 | + return array(\T_USE); |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * Processes this test, when one of its tokens is encountered. |
|
57 | - * |
|
58 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
59 | - * @param int $stackPtr The position of the current token in the |
|
60 | - * stack passed in $tokens. |
|
61 | - * |
|
62 | - * @return void |
|
63 | - */ |
|
64 | - public function process(File $phpcsFile, $stackPtr) |
|
65 | - { |
|
66 | - if ($this->supportsBelow('5.5') !== true) { |
|
67 | - return; |
|
68 | - } |
|
55 | + /** |
|
56 | + * Processes this test, when one of its tokens is encountered. |
|
57 | + * |
|
58 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
59 | + * @param int $stackPtr The position of the current token in the |
|
60 | + * stack passed in $tokens. |
|
61 | + * |
|
62 | + * @return void |
|
63 | + */ |
|
64 | + public function process(File $phpcsFile, $stackPtr) |
|
65 | + { |
|
66 | + if ($this->supportsBelow('5.5') !== true) { |
|
67 | + return; |
|
68 | + } |
|
69 | 69 | |
70 | - $tokens = $phpcsFile->getTokens(); |
|
70 | + $tokens = $phpcsFile->getTokens(); |
|
71 | 71 | |
72 | - $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); |
|
73 | - if ($nextNonEmpty === false) { |
|
74 | - // Live coding. |
|
75 | - return; |
|
76 | - } |
|
72 | + $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); |
|
73 | + if ($nextNonEmpty === false) { |
|
74 | + // Live coding. |
|
75 | + return; |
|
76 | + } |
|
77 | 77 | |
78 | - if (isset($this->validUseNames[strtolower($tokens[$nextNonEmpty]['content'])]) === false) { |
|
79 | - // Not a `use const` or `use function` statement. |
|
80 | - return; |
|
81 | - } |
|
78 | + if (isset($this->validUseNames[strtolower($tokens[$nextNonEmpty]['content'])]) === false) { |
|
79 | + // Not a `use const` or `use function` statement. |
|
80 | + return; |
|
81 | + } |
|
82 | 82 | |
83 | - // `use const` and `use function` have to be followed by the function/constant name. |
|
84 | - $functionOrConstName = $phpcsFile->findNext(Tokens::$emptyTokens, ($nextNonEmpty + 1), null, true); |
|
85 | - if ($functionOrConstName === false |
|
86 | - // Identifies as T_AS or T_STRING, this covers both. |
|
87 | - || ($tokens[$functionOrConstName]['content'] === 'as' |
|
88 | - || $tokens[$functionOrConstName]['code'] === \T_COMMA) |
|
89 | - ) { |
|
90 | - // Live coding or incorrect use of reserved keyword, but that is |
|
91 | - // covered by the ForbiddenNames sniff. |
|
92 | - return; |
|
93 | - } |
|
83 | + // `use const` and `use function` have to be followed by the function/constant name. |
|
84 | + $functionOrConstName = $phpcsFile->findNext(Tokens::$emptyTokens, ($nextNonEmpty + 1), null, true); |
|
85 | + if ($functionOrConstName === false |
|
86 | + // Identifies as T_AS or T_STRING, this covers both. |
|
87 | + || ($tokens[$functionOrConstName]['content'] === 'as' |
|
88 | + || $tokens[$functionOrConstName]['code'] === \T_COMMA) |
|
89 | + ) { |
|
90 | + // Live coding or incorrect use of reserved keyword, but that is |
|
91 | + // covered by the ForbiddenNames sniff. |
|
92 | + return; |
|
93 | + } |
|
94 | 94 | |
95 | - // Still here ? In that case we have encountered a `use const` or `use function` statement. |
|
96 | - $phpcsFile->addError( |
|
97 | - 'Importing functions and constants through a "use" statement is not supported in PHP 5.5 or lower.', |
|
98 | - $nextNonEmpty, |
|
99 | - 'Found' |
|
100 | - ); |
|
101 | - } |
|
95 | + // Still here ? In that case we have encountered a `use const` or `use function` statement. |
|
96 | + $phpcsFile->addError( |
|
97 | + 'Importing functions and constants through a "use" statement is not supported in PHP 5.5 or lower.', |
|
98 | + $nextNonEmpty, |
|
99 | + 'Found' |
|
100 | + ); |
|
101 | + } |
|
102 | 102 | } |
@@ -21,107 +21,107 @@ |
||
21 | 21 | */ |
22 | 22 | class RemovedTypeCastsSniff extends AbstractRemovedFeatureSniff |
23 | 23 | { |
24 | - /** |
|
25 | - * A list of deprecated and removed type casts with their alternatives. |
|
26 | - * |
|
27 | - * The array lists : version number with false (deprecated) or true (removed) and an alternative function. |
|
28 | - * If no alternative exists, it is NULL, i.e, the function should just not be used. |
|
29 | - * |
|
30 | - * @var array(string => array(string => bool|string|null)) |
|
31 | - */ |
|
32 | - protected $deprecatedTypeCasts = array( |
|
33 | - 'T_UNSET_CAST' => array( |
|
34 | - '7.2' => false, |
|
35 | - 'alternative' => 'unset()', |
|
36 | - 'description' => 'unset', |
|
37 | - ), |
|
38 | - ); |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * Returns an array of tokens this test wants to listen for. |
|
43 | - * |
|
44 | - * @return array |
|
45 | - */ |
|
46 | - public function register() |
|
47 | - { |
|
48 | - $tokens = array(); |
|
49 | - foreach ($this->deprecatedTypeCasts as $token => $versions) { |
|
50 | - $tokens[] = constant($token); |
|
51 | - } |
|
52 | - |
|
53 | - return $tokens; |
|
54 | - } |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * Processes this test, when one of its tokens is encountered. |
|
59 | - * |
|
60 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
61 | - * @param int $stackPtr The position of the current token in |
|
62 | - * the stack passed in $tokens. |
|
63 | - * |
|
64 | - * @return void |
|
65 | - */ |
|
66 | - public function process(File $phpcsFile, $stackPtr) |
|
67 | - { |
|
68 | - $tokens = $phpcsFile->getTokens(); |
|
69 | - $tokenType = $tokens[$stackPtr]['type']; |
|
70 | - |
|
71 | - $itemInfo = array( |
|
72 | - 'name' => $tokenType, |
|
73 | - 'description' => $this->deprecatedTypeCasts[$tokenType]['description'], |
|
74 | - ); |
|
75 | - $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * Get an array of the non-PHP-version array keys used in a sub-array. |
|
81 | - * |
|
82 | - * @return array |
|
83 | - */ |
|
84 | - protected function getNonVersionArrayKeys() |
|
85 | - { |
|
86 | - return array('description', 'alternative'); |
|
87 | - } |
|
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->deprecatedTypeCasts[$itemInfo['name']]; |
|
99 | - } |
|
100 | - |
|
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 cast is '; |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * Filter the error data before it's passed to PHPCS. |
|
115 | - * |
|
116 | - * @param array $data The error data array which was created. |
|
117 | - * @param array $itemInfo Base information about the item this error message applies to. |
|
118 | - * @param array $errorInfo Detail information about an item this error message applies to. |
|
119 | - * |
|
120 | - * @return array |
|
121 | - */ |
|
122 | - protected function filterErrorData(array $data, array $itemInfo, array $errorInfo) |
|
123 | - { |
|
124 | - $data[0] = $itemInfo['description']; |
|
125 | - return $data; |
|
126 | - } |
|
24 | + /** |
|
25 | + * A list of deprecated and removed type casts with their alternatives. |
|
26 | + * |
|
27 | + * The array lists : version number with false (deprecated) or true (removed) and an alternative function. |
|
28 | + * If no alternative exists, it is NULL, i.e, the function should just not be used. |
|
29 | + * |
|
30 | + * @var array(string => array(string => bool|string|null)) |
|
31 | + */ |
|
32 | + protected $deprecatedTypeCasts = array( |
|
33 | + 'T_UNSET_CAST' => array( |
|
34 | + '7.2' => false, |
|
35 | + 'alternative' => 'unset()', |
|
36 | + 'description' => 'unset', |
|
37 | + ), |
|
38 | + ); |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * Returns an array of tokens this test wants to listen for. |
|
43 | + * |
|
44 | + * @return array |
|
45 | + */ |
|
46 | + public function register() |
|
47 | + { |
|
48 | + $tokens = array(); |
|
49 | + foreach ($this->deprecatedTypeCasts as $token => $versions) { |
|
50 | + $tokens[] = constant($token); |
|
51 | + } |
|
52 | + |
|
53 | + return $tokens; |
|
54 | + } |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * Processes this test, when one of its tokens is encountered. |
|
59 | + * |
|
60 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
61 | + * @param int $stackPtr The position of the current token in |
|
62 | + * the stack passed in $tokens. |
|
63 | + * |
|
64 | + * @return void |
|
65 | + */ |
|
66 | + public function process(File $phpcsFile, $stackPtr) |
|
67 | + { |
|
68 | + $tokens = $phpcsFile->getTokens(); |
|
69 | + $tokenType = $tokens[$stackPtr]['type']; |
|
70 | + |
|
71 | + $itemInfo = array( |
|
72 | + 'name' => $tokenType, |
|
73 | + 'description' => $this->deprecatedTypeCasts[$tokenType]['description'], |
|
74 | + ); |
|
75 | + $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * Get an array of the non-PHP-version array keys used in a sub-array. |
|
81 | + * |
|
82 | + * @return array |
|
83 | + */ |
|
84 | + protected function getNonVersionArrayKeys() |
|
85 | + { |
|
86 | + return array('description', 'alternative'); |
|
87 | + } |
|
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->deprecatedTypeCasts[$itemInfo['name']]; |
|
99 | + } |
|
100 | + |
|
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 cast is '; |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * Filter the error data before it's passed to PHPCS. |
|
115 | + * |
|
116 | + * @param array $data The error data array which was created. |
|
117 | + * @param array $itemInfo Base information about the item this error message applies to. |
|
118 | + * @param array $errorInfo Detail information about an item this error message applies to. |
|
119 | + * |
|
120 | + * @return array |
|
121 | + */ |
|
122 | + protected function filterErrorData(array $data, array $itemInfo, array $errorInfo) |
|
123 | + { |
|
124 | + $data[0] = $itemInfo['description']; |
|
125 | + return $data; |
|
126 | + } |
|
127 | 127 | } |
@@ -23,43 +23,43 @@ discard block |
||
23 | 23 | class NewTypeCastsSniff extends AbstractNewFeatureSniff |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * A list of new type casts, not present in older versions. |
|
28 | - * |
|
29 | - * The array lists : version number with false (not present) or true (present). |
|
30 | - * If's sufficient to list the first version where the keyword appears. |
|
31 | - * |
|
32 | - * @var array(string => array(string => int|string|null)) |
|
33 | - */ |
|
34 | - protected $newTypeCasts = array( |
|
35 | - 'T_UNSET_CAST' => array( |
|
36 | - '4.4' => false, |
|
37 | - '5.0' => true, |
|
38 | - 'description' => 'The unset cast', |
|
39 | - ), |
|
40 | - 'T_BINARY_CAST' => array( |
|
41 | - '5.2.0' => false, |
|
42 | - '5.2.1' => true, |
|
43 | - 'description' => 'The binary cast', |
|
44 | - ), |
|
45 | - ); |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * Returns an array of tokens this test wants to listen for. |
|
50 | - * |
|
51 | - * @return array |
|
52 | - */ |
|
53 | - public function register() |
|
54 | - { |
|
55 | - $tokens = array(); |
|
56 | - foreach ($this->newTypeCasts as $token => $versions) { |
|
57 | - if (\defined($token)) { |
|
58 | - $tokens[] = constant($token); |
|
59 | - } |
|
60 | - } |
|
61 | - |
|
62 | - /* |
|
26 | + /** |
|
27 | + * A list of new type casts, not present in older versions. |
|
28 | + * |
|
29 | + * The array lists : version number with false (not present) or true (present). |
|
30 | + * If's sufficient to list the first version where the keyword appears. |
|
31 | + * |
|
32 | + * @var array(string => array(string => int|string|null)) |
|
33 | + */ |
|
34 | + protected $newTypeCasts = array( |
|
35 | + 'T_UNSET_CAST' => array( |
|
36 | + '4.4' => false, |
|
37 | + '5.0' => true, |
|
38 | + 'description' => 'The unset cast', |
|
39 | + ), |
|
40 | + 'T_BINARY_CAST' => array( |
|
41 | + '5.2.0' => false, |
|
42 | + '5.2.1' => true, |
|
43 | + 'description' => 'The binary cast', |
|
44 | + ), |
|
45 | + ); |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * Returns an array of tokens this test wants to listen for. |
|
50 | + * |
|
51 | + * @return array |
|
52 | + */ |
|
53 | + public function register() |
|
54 | + { |
|
55 | + $tokens = array(); |
|
56 | + foreach ($this->newTypeCasts as $token => $versions) { |
|
57 | + if (\defined($token)) { |
|
58 | + $tokens[] = constant($token); |
|
59 | + } |
|
60 | + } |
|
61 | + |
|
62 | + /* |
|
63 | 63 | * Work around tokenizer issues. |
64 | 64 | * |
65 | 65 | * - (binary) cast is incorrectly tokenized as T_STRING_CAST by PHP and PHPCS. |
@@ -68,136 +68,136 @@ discard block |
||
68 | 68 | * |
69 | 69 | * @link https://github.com/squizlabs/PHP_CodeSniffer/issues/1574 |
70 | 70 | */ |
71 | - if (version_compare(PHPCSHelper::getVersion(), '3.4.0', '<') === true) { |
|
72 | - $tokens[] = \T_STRING_CAST; |
|
73 | - $tokens[] = \T_CONSTANT_ENCAPSED_STRING; |
|
74 | - } |
|
75 | - |
|
76 | - return $tokens; |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * Processes this test, when one of its tokens is encountered. |
|
82 | - * |
|
83 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
84 | - * @param int $stackPtr The position of the current token in |
|
85 | - * the stack passed in $tokens. |
|
86 | - * |
|
87 | - * @return void |
|
88 | - */ |
|
89 | - public function process(File $phpcsFile, $stackPtr) |
|
90 | - { |
|
91 | - $tokens = $phpcsFile->getTokens(); |
|
92 | - $tokenType = $tokens[$stackPtr]['type']; |
|
93 | - |
|
94 | - // Detect incorrectly tokenized binary casts. |
|
95 | - if (isset($this->newTypeCasts[$tokenType]) === false) { |
|
96 | - $tokenContent = $tokens[$stackPtr]['content']; |
|
97 | - switch ($tokenType) { |
|
98 | - case 'T_STRING_CAST': |
|
99 | - if (preg_match('`^\(\s*binary\s*\)$`i', $tokenContent) !== 1) { |
|
100 | - return; |
|
101 | - } |
|
102 | - |
|
103 | - $tokenType = 'T_BINARY_CAST'; |
|
104 | - break; |
|
105 | - |
|
106 | - case 'T_CONSTANT_ENCAPSED_STRING': |
|
107 | - if ((strpos($tokenContent, 'b"') === 0 && substr($tokenContent, -1) === '"') |
|
108 | - || (strpos($tokenContent, "b'") === 0 && substr($tokenContent, -1) === "'") |
|
109 | - ) { |
|
110 | - $tokenType = 'T_BINARY_CAST'; |
|
111 | - } else { |
|
112 | - return; |
|
113 | - } |
|
114 | - break; |
|
115 | - |
|
116 | - } |
|
117 | - } |
|
118 | - |
|
119 | - // If the translation did not yield one of the tokens we are looking for, bow out. |
|
120 | - if (isset($this->newTypeCasts[$tokenType]) === false) { |
|
121 | - return; |
|
122 | - } |
|
123 | - |
|
124 | - $itemInfo = array( |
|
125 | - 'name' => $tokenType, |
|
126 | - 'content' => $tokens[$stackPtr]['content'], |
|
127 | - ); |
|
128 | - $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * Get the relevant sub-array for a specific item from a multi-dimensional array. |
|
134 | - * |
|
135 | - * @param array $itemInfo Base information about the item. |
|
136 | - * |
|
137 | - * @return array Version and other information about the item. |
|
138 | - */ |
|
139 | - public function getItemArray(array $itemInfo) |
|
140 | - { |
|
141 | - return $this->newTypeCasts[$itemInfo['name']]; |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * Get an array of the non-PHP-version array keys used in a sub-array. |
|
147 | - * |
|
148 | - * @return array |
|
149 | - */ |
|
150 | - protected function getNonVersionArrayKeys() |
|
151 | - { |
|
152 | - return array('description'); |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * Retrieve the relevant detail (version) information for use in an error message. |
|
158 | - * |
|
159 | - * @param array $itemArray Version and other information about the item. |
|
160 | - * @param array $itemInfo Base information about the item. |
|
161 | - * |
|
162 | - * @return array |
|
163 | - */ |
|
164 | - public function getErrorInfo(array $itemArray, array $itemInfo) |
|
165 | - { |
|
166 | - $errorInfo = parent::getErrorInfo($itemArray, $itemInfo); |
|
167 | - $errorInfo['description'] = $itemArray['description']; |
|
168 | - |
|
169 | - return $errorInfo; |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * Filter the error message before it's passed to PHPCS. |
|
175 | - * |
|
176 | - * @param string $error The error message which was created. |
|
177 | - * @param array $itemInfo Base information about the item this error message applies to. |
|
178 | - * @param array $errorInfo Detail information about an item this error message applies to. |
|
179 | - * |
|
180 | - * @return string |
|
181 | - */ |
|
182 | - protected function filterErrorMsg($error, array $itemInfo, array $errorInfo) |
|
183 | - { |
|
184 | - return $error . '. Found: %s'; |
|
185 | - } |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * Filter the error data before it's passed to PHPCS. |
|
190 | - * |
|
191 | - * @param array $data The error data array which was created. |
|
192 | - * @param array $itemInfo Base information about the item this error message applies to. |
|
193 | - * @param array $errorInfo Detail information about an item this error message applies to. |
|
194 | - * |
|
195 | - * @return array |
|
196 | - */ |
|
197 | - protected function filterErrorData(array $data, array $itemInfo, array $errorInfo) |
|
198 | - { |
|
199 | - $data[0] = $errorInfo['description']; |
|
200 | - $data[] = $itemInfo['content']; |
|
201 | - return $data; |
|
202 | - } |
|
71 | + if (version_compare(PHPCSHelper::getVersion(), '3.4.0', '<') === true) { |
|
72 | + $tokens[] = \T_STRING_CAST; |
|
73 | + $tokens[] = \T_CONSTANT_ENCAPSED_STRING; |
|
74 | + } |
|
75 | + |
|
76 | + return $tokens; |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * Processes this test, when one of its tokens is encountered. |
|
82 | + * |
|
83 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
84 | + * @param int $stackPtr The position of the current token in |
|
85 | + * the stack passed in $tokens. |
|
86 | + * |
|
87 | + * @return void |
|
88 | + */ |
|
89 | + public function process(File $phpcsFile, $stackPtr) |
|
90 | + { |
|
91 | + $tokens = $phpcsFile->getTokens(); |
|
92 | + $tokenType = $tokens[$stackPtr]['type']; |
|
93 | + |
|
94 | + // Detect incorrectly tokenized binary casts. |
|
95 | + if (isset($this->newTypeCasts[$tokenType]) === false) { |
|
96 | + $tokenContent = $tokens[$stackPtr]['content']; |
|
97 | + switch ($tokenType) { |
|
98 | + case 'T_STRING_CAST': |
|
99 | + if (preg_match('`^\(\s*binary\s*\)$`i', $tokenContent) !== 1) { |
|
100 | + return; |
|
101 | + } |
|
102 | + |
|
103 | + $tokenType = 'T_BINARY_CAST'; |
|
104 | + break; |
|
105 | + |
|
106 | + case 'T_CONSTANT_ENCAPSED_STRING': |
|
107 | + if ((strpos($tokenContent, 'b"') === 0 && substr($tokenContent, -1) === '"') |
|
108 | + || (strpos($tokenContent, "b'") === 0 && substr($tokenContent, -1) === "'") |
|
109 | + ) { |
|
110 | + $tokenType = 'T_BINARY_CAST'; |
|
111 | + } else { |
|
112 | + return; |
|
113 | + } |
|
114 | + break; |
|
115 | + |
|
116 | + } |
|
117 | + } |
|
118 | + |
|
119 | + // If the translation did not yield one of the tokens we are looking for, bow out. |
|
120 | + if (isset($this->newTypeCasts[$tokenType]) === false) { |
|
121 | + return; |
|
122 | + } |
|
123 | + |
|
124 | + $itemInfo = array( |
|
125 | + 'name' => $tokenType, |
|
126 | + 'content' => $tokens[$stackPtr]['content'], |
|
127 | + ); |
|
128 | + $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * Get the relevant sub-array for a specific item from a multi-dimensional array. |
|
134 | + * |
|
135 | + * @param array $itemInfo Base information about the item. |
|
136 | + * |
|
137 | + * @return array Version and other information about the item. |
|
138 | + */ |
|
139 | + public function getItemArray(array $itemInfo) |
|
140 | + { |
|
141 | + return $this->newTypeCasts[$itemInfo['name']]; |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * Get an array of the non-PHP-version array keys used in a sub-array. |
|
147 | + * |
|
148 | + * @return array |
|
149 | + */ |
|
150 | + protected function getNonVersionArrayKeys() |
|
151 | + { |
|
152 | + return array('description'); |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * Retrieve the relevant detail (version) information for use in an error message. |
|
158 | + * |
|
159 | + * @param array $itemArray Version and other information about the item. |
|
160 | + * @param array $itemInfo Base information about the item. |
|
161 | + * |
|
162 | + * @return array |
|
163 | + */ |
|
164 | + public function getErrorInfo(array $itemArray, array $itemInfo) |
|
165 | + { |
|
166 | + $errorInfo = parent::getErrorInfo($itemArray, $itemInfo); |
|
167 | + $errorInfo['description'] = $itemArray['description']; |
|
168 | + |
|
169 | + return $errorInfo; |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * Filter the error message before it's passed to PHPCS. |
|
175 | + * |
|
176 | + * @param string $error The error message which was created. |
|
177 | + * @param array $itemInfo Base information about the item this error message applies to. |
|
178 | + * @param array $errorInfo Detail information about an item this error message applies to. |
|
179 | + * |
|
180 | + * @return string |
|
181 | + */ |
|
182 | + protected function filterErrorMsg($error, array $itemInfo, array $errorInfo) |
|
183 | + { |
|
184 | + return $error . '. Found: %s'; |
|
185 | + } |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * Filter the error data before it's passed to PHPCS. |
|
190 | + * |
|
191 | + * @param array $data The error data array which was created. |
|
192 | + * @param array $itemInfo Base information about the item this error message applies to. |
|
193 | + * @param array $errorInfo Detail information about an item this error message applies to. |
|
194 | + * |
|
195 | + * @return array |
|
196 | + */ |
|
197 | + protected function filterErrorData(array $data, array $itemInfo, array $errorInfo) |
|
198 | + { |
|
199 | + $data[0] = $errorInfo['description']; |
|
200 | + $data[] = $itemInfo['content']; |
|
201 | + return $data; |
|
202 | + } |
|
203 | 203 | } |
@@ -25,374 +25,374 @@ |
||
25 | 25 | */ |
26 | 26 | class RemovedIniDirectivesSniff extends AbstractRemovedFeatureSniff |
27 | 27 | { |
28 | - /** |
|
29 | - * A list of deprecated INI directives. |
|
30 | - * |
|
31 | - * The array lists : version number with false (deprecated) and true (removed). |
|
32 | - * If's sufficient to list the first version where the ini directive was deprecated/removed. |
|
33 | - * |
|
34 | - * @var array(string) |
|
35 | - */ |
|
36 | - protected $deprecatedIniDirectives = array( |
|
37 | - 'fbsql.batchSize' => array( |
|
38 | - '5.1' => true, |
|
39 | - 'alternative' => 'fbsql.batchsize', |
|
40 | - ), |
|
41 | - 'pfpro.defaulthost' => array( |
|
42 | - '5.1' => true, |
|
43 | - ), |
|
44 | - 'pfpro.defaultport' => array( |
|
45 | - '5.1' => true, |
|
46 | - ), |
|
47 | - 'pfpro.defaulttimeout' => array( |
|
48 | - '5.1' => true, |
|
49 | - ), |
|
50 | - 'pfpro.proxyaddress' => array( |
|
51 | - '5.1' => true, |
|
52 | - ), |
|
53 | - 'pfpro.proxyport' => array( |
|
54 | - '5.1' => true, |
|
55 | - ), |
|
56 | - 'pfpro.proxylogon' => array( |
|
57 | - '5.1' => true, |
|
58 | - ), |
|
59 | - 'pfpro.proxypassword' => array( |
|
60 | - '5.1' => true, |
|
61 | - ), |
|
28 | + /** |
|
29 | + * A list of deprecated INI directives. |
|
30 | + * |
|
31 | + * The array lists : version number with false (deprecated) and true (removed). |
|
32 | + * If's sufficient to list the first version where the ini directive was deprecated/removed. |
|
33 | + * |
|
34 | + * @var array(string) |
|
35 | + */ |
|
36 | + protected $deprecatedIniDirectives = array( |
|
37 | + 'fbsql.batchSize' => array( |
|
38 | + '5.1' => true, |
|
39 | + 'alternative' => 'fbsql.batchsize', |
|
40 | + ), |
|
41 | + 'pfpro.defaulthost' => array( |
|
42 | + '5.1' => true, |
|
43 | + ), |
|
44 | + 'pfpro.defaultport' => array( |
|
45 | + '5.1' => true, |
|
46 | + ), |
|
47 | + 'pfpro.defaulttimeout' => array( |
|
48 | + '5.1' => true, |
|
49 | + ), |
|
50 | + 'pfpro.proxyaddress' => array( |
|
51 | + '5.1' => true, |
|
52 | + ), |
|
53 | + 'pfpro.proxyport' => array( |
|
54 | + '5.1' => true, |
|
55 | + ), |
|
56 | + 'pfpro.proxylogon' => array( |
|
57 | + '5.1' => true, |
|
58 | + ), |
|
59 | + 'pfpro.proxypassword' => array( |
|
60 | + '5.1' => true, |
|
61 | + ), |
|
62 | 62 | |
63 | - 'ifx.allow_persistent' => array( |
|
64 | - '5.2.1' => true, |
|
65 | - ), |
|
66 | - 'ifx.blobinfile' => array( |
|
67 | - '5.2.1' => true, |
|
68 | - ), |
|
69 | - 'ifx.byteasvarchar' => array( |
|
70 | - '5.2.1' => true, |
|
71 | - ), |
|
72 | - 'ifx.charasvarchar' => array( |
|
73 | - '5.2.1' => true, |
|
74 | - ), |
|
75 | - 'ifx.default_host' => array( |
|
76 | - '5.2.1' => true, |
|
77 | - ), |
|
78 | - 'ifx.default_password' => array( |
|
79 | - '5.2.1' => true, |
|
80 | - ), |
|
81 | - 'ifx.default_user' => array( |
|
82 | - '5.2.1' => true, |
|
83 | - ), |
|
84 | - 'ifx.max_links' => array( |
|
85 | - '5.2.1' => true, |
|
86 | - ), |
|
87 | - 'ifx.max_persistent' => array( |
|
88 | - '5.2.1' => true, |
|
89 | - ), |
|
90 | - 'ifx.nullformat' => array( |
|
91 | - '5.2.1' => true, |
|
92 | - ), |
|
93 | - 'ifx.textasvarchar' => array( |
|
94 | - '5.2.1' => true, |
|
95 | - ), |
|
63 | + 'ifx.allow_persistent' => array( |
|
64 | + '5.2.1' => true, |
|
65 | + ), |
|
66 | + 'ifx.blobinfile' => array( |
|
67 | + '5.2.1' => true, |
|
68 | + ), |
|
69 | + 'ifx.byteasvarchar' => array( |
|
70 | + '5.2.1' => true, |
|
71 | + ), |
|
72 | + 'ifx.charasvarchar' => array( |
|
73 | + '5.2.1' => true, |
|
74 | + ), |
|
75 | + 'ifx.default_host' => array( |
|
76 | + '5.2.1' => true, |
|
77 | + ), |
|
78 | + 'ifx.default_password' => array( |
|
79 | + '5.2.1' => true, |
|
80 | + ), |
|
81 | + 'ifx.default_user' => array( |
|
82 | + '5.2.1' => true, |
|
83 | + ), |
|
84 | + 'ifx.max_links' => array( |
|
85 | + '5.2.1' => true, |
|
86 | + ), |
|
87 | + 'ifx.max_persistent' => array( |
|
88 | + '5.2.1' => true, |
|
89 | + ), |
|
90 | + 'ifx.nullformat' => array( |
|
91 | + '5.2.1' => true, |
|
92 | + ), |
|
93 | + 'ifx.textasvarchar' => array( |
|
94 | + '5.2.1' => true, |
|
95 | + ), |
|
96 | 96 | |
97 | - 'zend.ze1_compatibility_mode' => array( |
|
98 | - '5.3' => true, |
|
99 | - ), |
|
97 | + 'zend.ze1_compatibility_mode' => array( |
|
98 | + '5.3' => true, |
|
99 | + ), |
|
100 | 100 | |
101 | - 'allow_call_time_pass_reference' => array( |
|
102 | - '5.3' => false, |
|
103 | - '5.4' => true, |
|
104 | - ), |
|
105 | - 'define_syslog_variables' => array( |
|
106 | - '5.3' => false, |
|
107 | - '5.4' => true, |
|
108 | - ), |
|
109 | - 'detect_unicode' => array( |
|
110 | - '5.4' => true, |
|
111 | - 'alternative' => 'zend.detect_unicode', |
|
112 | - ), |
|
113 | - 'highlight.bg' => array( |
|
114 | - '5.3' => false, |
|
115 | - '5.4' => true, |
|
116 | - ), |
|
117 | - 'magic_quotes_gpc' => array( |
|
118 | - '5.3' => false, |
|
119 | - '5.4' => true, |
|
120 | - ), |
|
121 | - 'magic_quotes_runtime' => array( |
|
122 | - '5.3' => false, |
|
123 | - '5.4' => true, |
|
124 | - ), |
|
125 | - 'magic_quotes_sybase' => array( |
|
126 | - '5.3' => false, |
|
127 | - '5.4' => true, |
|
128 | - ), |
|
129 | - 'mbstring.script_encoding' => array( |
|
130 | - '5.4' => true, |
|
131 | - 'alternative' => 'zend.script_encoding', |
|
132 | - ), |
|
133 | - 'register_globals' => array( |
|
134 | - '5.3' => false, |
|
135 | - '5.4' => true, |
|
136 | - ), |
|
137 | - 'register_long_arrays' => array( |
|
138 | - '5.3' => false, |
|
139 | - '5.4' => true, |
|
140 | - ), |
|
141 | - 'safe_mode' => array( |
|
142 | - '5.3' => false, |
|
143 | - '5.4' => true, |
|
144 | - ), |
|
145 | - 'safe_mode_allowed_env_vars' => array( |
|
146 | - '5.3' => false, |
|
147 | - '5.4' => true, |
|
148 | - ), |
|
149 | - 'safe_mode_exec_dir' => array( |
|
150 | - '5.3' => false, |
|
151 | - '5.4' => true, |
|
152 | - ), |
|
153 | - 'safe_mode_gid' => array( |
|
154 | - '5.3' => false, |
|
155 | - '5.4' => true, |
|
156 | - ), |
|
157 | - 'safe_mode_include_dir' => array( |
|
158 | - '5.3' => false, |
|
159 | - '5.4' => true, |
|
160 | - ), |
|
161 | - 'safe_mode_protected_env_vars' => array( |
|
162 | - '5.3' => false, |
|
163 | - '5.4' => true, |
|
164 | - ), |
|
165 | - 'session.bug_compat_42' => array( |
|
166 | - '5.3' => false, |
|
167 | - '5.4' => true, |
|
168 | - ), |
|
169 | - 'session.bug_compat_warn' => array( |
|
170 | - '5.3' => false, |
|
171 | - '5.4' => true, |
|
172 | - ), |
|
173 | - 'y2k_compliance' => array( |
|
174 | - '5.3' => false, |
|
175 | - '5.4' => true, |
|
176 | - ), |
|
101 | + 'allow_call_time_pass_reference' => array( |
|
102 | + '5.3' => false, |
|
103 | + '5.4' => true, |
|
104 | + ), |
|
105 | + 'define_syslog_variables' => array( |
|
106 | + '5.3' => false, |
|
107 | + '5.4' => true, |
|
108 | + ), |
|
109 | + 'detect_unicode' => array( |
|
110 | + '5.4' => true, |
|
111 | + 'alternative' => 'zend.detect_unicode', |
|
112 | + ), |
|
113 | + 'highlight.bg' => array( |
|
114 | + '5.3' => false, |
|
115 | + '5.4' => true, |
|
116 | + ), |
|
117 | + 'magic_quotes_gpc' => array( |
|
118 | + '5.3' => false, |
|
119 | + '5.4' => true, |
|
120 | + ), |
|
121 | + 'magic_quotes_runtime' => array( |
|
122 | + '5.3' => false, |
|
123 | + '5.4' => true, |
|
124 | + ), |
|
125 | + 'magic_quotes_sybase' => array( |
|
126 | + '5.3' => false, |
|
127 | + '5.4' => true, |
|
128 | + ), |
|
129 | + 'mbstring.script_encoding' => array( |
|
130 | + '5.4' => true, |
|
131 | + 'alternative' => 'zend.script_encoding', |
|
132 | + ), |
|
133 | + 'register_globals' => array( |
|
134 | + '5.3' => false, |
|
135 | + '5.4' => true, |
|
136 | + ), |
|
137 | + 'register_long_arrays' => array( |
|
138 | + '5.3' => false, |
|
139 | + '5.4' => true, |
|
140 | + ), |
|
141 | + 'safe_mode' => array( |
|
142 | + '5.3' => false, |
|
143 | + '5.4' => true, |
|
144 | + ), |
|
145 | + 'safe_mode_allowed_env_vars' => array( |
|
146 | + '5.3' => false, |
|
147 | + '5.4' => true, |
|
148 | + ), |
|
149 | + 'safe_mode_exec_dir' => array( |
|
150 | + '5.3' => false, |
|
151 | + '5.4' => true, |
|
152 | + ), |
|
153 | + 'safe_mode_gid' => array( |
|
154 | + '5.3' => false, |
|
155 | + '5.4' => true, |
|
156 | + ), |
|
157 | + 'safe_mode_include_dir' => array( |
|
158 | + '5.3' => false, |
|
159 | + '5.4' => true, |
|
160 | + ), |
|
161 | + 'safe_mode_protected_env_vars' => array( |
|
162 | + '5.3' => false, |
|
163 | + '5.4' => true, |
|
164 | + ), |
|
165 | + 'session.bug_compat_42' => array( |
|
166 | + '5.3' => false, |
|
167 | + '5.4' => true, |
|
168 | + ), |
|
169 | + 'session.bug_compat_warn' => array( |
|
170 | + '5.3' => false, |
|
171 | + '5.4' => true, |
|
172 | + ), |
|
173 | + 'y2k_compliance' => array( |
|
174 | + '5.3' => false, |
|
175 | + '5.4' => true, |
|
176 | + ), |
|
177 | 177 | |
178 | - 'always_populate_raw_post_data' => array( |
|
179 | - '5.6' => false, |
|
180 | - '7.0' => true, |
|
181 | - ), |
|
182 | - 'iconv.input_encoding' => array( |
|
183 | - '5.6' => false, |
|
184 | - ), |
|
185 | - 'iconv.output_encoding' => array( |
|
186 | - '5.6' => false, |
|
187 | - ), |
|
188 | - 'iconv.internal_encoding' => array( |
|
189 | - '5.6' => false, |
|
190 | - ), |
|
191 | - 'mbstring.http_input' => array( |
|
192 | - '5.6' => false, |
|
193 | - ), |
|
194 | - 'mbstring.http_output' => array( |
|
195 | - '5.6' => false, |
|
196 | - ), |
|
197 | - 'mbstring.internal_encoding' => array( |
|
198 | - '5.6' => false, |
|
199 | - ), |
|
178 | + 'always_populate_raw_post_data' => array( |
|
179 | + '5.6' => false, |
|
180 | + '7.0' => true, |
|
181 | + ), |
|
182 | + 'iconv.input_encoding' => array( |
|
183 | + '5.6' => false, |
|
184 | + ), |
|
185 | + 'iconv.output_encoding' => array( |
|
186 | + '5.6' => false, |
|
187 | + ), |
|
188 | + 'iconv.internal_encoding' => array( |
|
189 | + '5.6' => false, |
|
190 | + ), |
|
191 | + 'mbstring.http_input' => array( |
|
192 | + '5.6' => false, |
|
193 | + ), |
|
194 | + 'mbstring.http_output' => array( |
|
195 | + '5.6' => false, |
|
196 | + ), |
|
197 | + 'mbstring.internal_encoding' => array( |
|
198 | + '5.6' => false, |
|
199 | + ), |
|
200 | 200 | |
201 | - 'asp_tags' => array( |
|
202 | - '7.0' => true, |
|
203 | - ), |
|
204 | - 'xsl.security_prefs' => array( |
|
205 | - '7.0' => true, |
|
206 | - ), |
|
201 | + 'asp_tags' => array( |
|
202 | + '7.0' => true, |
|
203 | + ), |
|
204 | + 'xsl.security_prefs' => array( |
|
205 | + '7.0' => true, |
|
206 | + ), |
|
207 | 207 | |
208 | - 'mcrypt.algorithms_dir' => array( |
|
209 | - '7.1' => false, |
|
210 | - '7.2' => true, |
|
211 | - ), |
|
212 | - 'mcrypt.modes_dir' => array( |
|
213 | - '7.1' => false, |
|
214 | - '7.2' => true, |
|
215 | - ), |
|
216 | - 'session.entropy_file' => array( |
|
217 | - '7.1' => true, |
|
218 | - ), |
|
219 | - 'session.entropy_length' => array( |
|
220 | - '7.1' => true, |
|
221 | - ), |
|
222 | - 'session.hash_function' => array( |
|
223 | - '7.1' => true, |
|
224 | - ), |
|
225 | - 'session.hash_bits_per_character' => array( |
|
226 | - '7.1' => true, |
|
227 | - ), |
|
208 | + 'mcrypt.algorithms_dir' => array( |
|
209 | + '7.1' => false, |
|
210 | + '7.2' => true, |
|
211 | + ), |
|
212 | + 'mcrypt.modes_dir' => array( |
|
213 | + '7.1' => false, |
|
214 | + '7.2' => true, |
|
215 | + ), |
|
216 | + 'session.entropy_file' => array( |
|
217 | + '7.1' => true, |
|
218 | + ), |
|
219 | + 'session.entropy_length' => array( |
|
220 | + '7.1' => true, |
|
221 | + ), |
|
222 | + 'session.hash_function' => array( |
|
223 | + '7.1' => true, |
|
224 | + ), |
|
225 | + 'session.hash_bits_per_character' => array( |
|
226 | + '7.1' => true, |
|
227 | + ), |
|
228 | 228 | |
229 | - 'mbstring.func_overload' => array( |
|
230 | - '7.2' => false, |
|
231 | - ), |
|
232 | - 'sql.safe_mode' => array( |
|
233 | - '7.2' => true, |
|
234 | - ), |
|
235 | - 'track_errors' => array( |
|
236 | - '7.2' => false, |
|
237 | - ), |
|
238 | - 'opcache.fast_shutdown' => array( |
|
239 | - '7.2' => true, |
|
240 | - ), |
|
229 | + 'mbstring.func_overload' => array( |
|
230 | + '7.2' => false, |
|
231 | + ), |
|
232 | + 'sql.safe_mode' => array( |
|
233 | + '7.2' => true, |
|
234 | + ), |
|
235 | + 'track_errors' => array( |
|
236 | + '7.2' => false, |
|
237 | + ), |
|
238 | + 'opcache.fast_shutdown' => array( |
|
239 | + '7.2' => true, |
|
240 | + ), |
|
241 | 241 | |
242 | - 'birdstep.max_links' => array( |
|
243 | - '7.3' => true, |
|
244 | - ), |
|
245 | - 'opcache.inherited_hack' => array( |
|
246 | - '5.3' => false, // Soft deprecated, i.e. ignored. |
|
247 | - '7.3' => true, |
|
248 | - ), |
|
249 | - 'pdo_odbc.db2_instance_name' => array( |
|
250 | - '7.3' => false, // Has been marked as deprecated in the manual from before this time. Now hard-deprecated. |
|
251 | - ), |
|
242 | + 'birdstep.max_links' => array( |
|
243 | + '7.3' => true, |
|
244 | + ), |
|
245 | + 'opcache.inherited_hack' => array( |
|
246 | + '5.3' => false, // Soft deprecated, i.e. ignored. |
|
247 | + '7.3' => true, |
|
248 | + ), |
|
249 | + 'pdo_odbc.db2_instance_name' => array( |
|
250 | + '7.3' => false, // Has been marked as deprecated in the manual from before this time. Now hard-deprecated. |
|
251 | + ), |
|
252 | 252 | |
253 | - 'ibase.allow_persistent' => array( |
|
254 | - '7.4' => true, |
|
255 | - ), |
|
256 | - 'ibase.max_persistent' => array( |
|
257 | - '7.4' => true, |
|
258 | - ), |
|
259 | - 'ibase.max_links' => array( |
|
260 | - '7.4' => true, |
|
261 | - ), |
|
262 | - 'ibase.default_db' => array( |
|
263 | - '7.4' => true, |
|
264 | - ), |
|
265 | - 'ibase.default_user' => array( |
|
266 | - '7.4' => true, |
|
267 | - ), |
|
268 | - 'ibase.default_password' => array( |
|
269 | - '7.4' => true, |
|
270 | - ), |
|
271 | - 'ibase.default_charset' => array( |
|
272 | - '7.4' => true, |
|
273 | - ), |
|
274 | - 'ibase.timestampformat' => array( |
|
275 | - '7.4' => true, |
|
276 | - ), |
|
277 | - 'ibase.dateformat' => array( |
|
278 | - '7.4' => true, |
|
279 | - ), |
|
280 | - 'ibase.timeformat' => array( |
|
281 | - '7.4' => true, |
|
282 | - ), |
|
283 | - ); |
|
253 | + 'ibase.allow_persistent' => array( |
|
254 | + '7.4' => true, |
|
255 | + ), |
|
256 | + 'ibase.max_persistent' => array( |
|
257 | + '7.4' => true, |
|
258 | + ), |
|
259 | + 'ibase.max_links' => array( |
|
260 | + '7.4' => true, |
|
261 | + ), |
|
262 | + 'ibase.default_db' => array( |
|
263 | + '7.4' => true, |
|
264 | + ), |
|
265 | + 'ibase.default_user' => array( |
|
266 | + '7.4' => true, |
|
267 | + ), |
|
268 | + 'ibase.default_password' => array( |
|
269 | + '7.4' => true, |
|
270 | + ), |
|
271 | + 'ibase.default_charset' => array( |
|
272 | + '7.4' => true, |
|
273 | + ), |
|
274 | + 'ibase.timestampformat' => array( |
|
275 | + '7.4' => true, |
|
276 | + ), |
|
277 | + 'ibase.dateformat' => array( |
|
278 | + '7.4' => true, |
|
279 | + ), |
|
280 | + 'ibase.timeformat' => array( |
|
281 | + '7.4' => true, |
|
282 | + ), |
|
283 | + ); |
|
284 | 284 | |
285 | - /** |
|
286 | - * Returns an array of tokens this test wants to listen for. |
|
287 | - * |
|
288 | - * @return array |
|
289 | - */ |
|
290 | - public function register() |
|
291 | - { |
|
292 | - return array(\T_STRING); |
|
293 | - } |
|
285 | + /** |
|
286 | + * Returns an array of tokens this test wants to listen for. |
|
287 | + * |
|
288 | + * @return array |
|
289 | + */ |
|
290 | + public function register() |
|
291 | + { |
|
292 | + return array(\T_STRING); |
|
293 | + } |
|
294 | 294 | |
295 | - /** |
|
296 | - * Processes this test, when one of its tokens is encountered. |
|
297 | - * |
|
298 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
299 | - * @param int $stackPtr The position of the current token in the |
|
300 | - * stack passed in $tokens. |
|
301 | - * |
|
302 | - * @return void |
|
303 | - */ |
|
304 | - public function process(File $phpcsFile, $stackPtr) |
|
305 | - { |
|
306 | - $tokens = $phpcsFile->getTokens(); |
|
295 | + /** |
|
296 | + * Processes this test, when one of its tokens is encountered. |
|
297 | + * |
|
298 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
299 | + * @param int $stackPtr The position of the current token in the |
|
300 | + * stack passed in $tokens. |
|
301 | + * |
|
302 | + * @return void |
|
303 | + */ |
|
304 | + public function process(File $phpcsFile, $stackPtr) |
|
305 | + { |
|
306 | + $tokens = $phpcsFile->getTokens(); |
|
307 | 307 | |
308 | - $ignore = array( |
|
309 | - \T_DOUBLE_COLON => true, |
|
310 | - \T_OBJECT_OPERATOR => true, |
|
311 | - \T_FUNCTION => true, |
|
312 | - \T_CONST => true, |
|
313 | - ); |
|
308 | + $ignore = array( |
|
309 | + \T_DOUBLE_COLON => true, |
|
310 | + \T_OBJECT_OPERATOR => true, |
|
311 | + \T_FUNCTION => true, |
|
312 | + \T_CONST => true, |
|
313 | + ); |
|
314 | 314 | |
315 | - $prevToken = $phpcsFile->findPrevious(\T_WHITESPACE, ($stackPtr - 1), null, true); |
|
316 | - if (isset($ignore[$tokens[$prevToken]['code']]) === true) { |
|
317 | - // Not a call to a PHP function. |
|
318 | - return; |
|
319 | - } |
|
315 | + $prevToken = $phpcsFile->findPrevious(\T_WHITESPACE, ($stackPtr - 1), null, true); |
|
316 | + if (isset($ignore[$tokens[$prevToken]['code']]) === true) { |
|
317 | + // Not a call to a PHP function. |
|
318 | + return; |
|
319 | + } |
|
320 | 320 | |
321 | - $functionLc = strtolower($tokens[$stackPtr]['content']); |
|
322 | - if (isset($this->iniFunctions[$functionLc]) === false) { |
|
323 | - return; |
|
324 | - } |
|
321 | + $functionLc = strtolower($tokens[$stackPtr]['content']); |
|
322 | + if (isset($this->iniFunctions[$functionLc]) === false) { |
|
323 | + return; |
|
324 | + } |
|
325 | 325 | |
326 | - $iniToken = $this->getFunctionCallParameter($phpcsFile, $stackPtr, $this->iniFunctions[$functionLc]); |
|
327 | - if ($iniToken === false) { |
|
328 | - return; |
|
329 | - } |
|
326 | + $iniToken = $this->getFunctionCallParameter($phpcsFile, $stackPtr, $this->iniFunctions[$functionLc]); |
|
327 | + if ($iniToken === false) { |
|
328 | + return; |
|
329 | + } |
|
330 | 330 | |
331 | - $filteredToken = $this->stripQuotes($iniToken['raw']); |
|
332 | - if (isset($this->deprecatedIniDirectives[$filteredToken]) === false) { |
|
333 | - return; |
|
334 | - } |
|
331 | + $filteredToken = $this->stripQuotes($iniToken['raw']); |
|
332 | + if (isset($this->deprecatedIniDirectives[$filteredToken]) === false) { |
|
333 | + return; |
|
334 | + } |
|
335 | 335 | |
336 | - $itemInfo = array( |
|
337 | - 'name' => $filteredToken, |
|
338 | - 'functionLc' => $functionLc, |
|
339 | - ); |
|
340 | - $this->handleFeature($phpcsFile, $iniToken['end'], $itemInfo); |
|
341 | - } |
|
336 | + $itemInfo = array( |
|
337 | + 'name' => $filteredToken, |
|
338 | + 'functionLc' => $functionLc, |
|
339 | + ); |
|
340 | + $this->handleFeature($phpcsFile, $iniToken['end'], $itemInfo); |
|
341 | + } |
|
342 | 342 | |
343 | 343 | |
344 | - /** |
|
345 | - * Get the relevant sub-array for a specific item from a multi-dimensional array. |
|
346 | - * |
|
347 | - * @param array $itemInfo Base information about the item. |
|
348 | - * |
|
349 | - * @return array Version and other information about the item. |
|
350 | - */ |
|
351 | - public function getItemArray(array $itemInfo) |
|
352 | - { |
|
353 | - return $this->deprecatedIniDirectives[$itemInfo['name']]; |
|
354 | - } |
|
344 | + /** |
|
345 | + * Get the relevant sub-array for a specific item from a multi-dimensional array. |
|
346 | + * |
|
347 | + * @param array $itemInfo Base information about the item. |
|
348 | + * |
|
349 | + * @return array Version and other information about the item. |
|
350 | + */ |
|
351 | + public function getItemArray(array $itemInfo) |
|
352 | + { |
|
353 | + return $this->deprecatedIniDirectives[$itemInfo['name']]; |
|
354 | + } |
|
355 | 355 | |
356 | 356 | |
357 | - /** |
|
358 | - * Retrieve the relevant detail (version) information for use in an error message. |
|
359 | - * |
|
360 | - * @param array $itemArray Version and other information about the item. |
|
361 | - * @param array $itemInfo Base information about the item. |
|
362 | - * |
|
363 | - * @return array |
|
364 | - */ |
|
365 | - public function getErrorInfo(array $itemArray, array $itemInfo) |
|
366 | - { |
|
367 | - $errorInfo = parent::getErrorInfo($itemArray, $itemInfo); |
|
357 | + /** |
|
358 | + * Retrieve the relevant detail (version) information for use in an error message. |
|
359 | + * |
|
360 | + * @param array $itemArray Version and other information about the item. |
|
361 | + * @param array $itemInfo Base information about the item. |
|
362 | + * |
|
363 | + * @return array |
|
364 | + */ |
|
365 | + public function getErrorInfo(array $itemArray, array $itemInfo) |
|
366 | + { |
|
367 | + $errorInfo = parent::getErrorInfo($itemArray, $itemInfo); |
|
368 | 368 | |
369 | - // Lower error level to warning if the function used was ini_get. |
|
370 | - if ($errorInfo['error'] === true && $itemInfo['functionLc'] === 'ini_get') { |
|
371 | - $errorInfo['error'] = false; |
|
372 | - } |
|
369 | + // Lower error level to warning if the function used was ini_get. |
|
370 | + if ($errorInfo['error'] === true && $itemInfo['functionLc'] === 'ini_get') { |
|
371 | + $errorInfo['error'] = false; |
|
372 | + } |
|
373 | 373 | |
374 | - return $errorInfo; |
|
375 | - } |
|
374 | + return $errorInfo; |
|
375 | + } |
|
376 | 376 | |
377 | 377 | |
378 | - /** |
|
379 | - * Get the error message template for this sniff. |
|
380 | - * |
|
381 | - * @return string |
|
382 | - */ |
|
383 | - protected function getErrorMsgTemplate() |
|
384 | - { |
|
385 | - return "INI directive '%s' is "; |
|
386 | - } |
|
378 | + /** |
|
379 | + * Get the error message template for this sniff. |
|
380 | + * |
|
381 | + * @return string |
|
382 | + */ |
|
383 | + protected function getErrorMsgTemplate() |
|
384 | + { |
|
385 | + return "INI directive '%s' is "; |
|
386 | + } |
|
387 | 387 | |
388 | 388 | |
389 | - /** |
|
390 | - * Get the error message template for suggesting an alternative for a specific sniff. |
|
391 | - * |
|
392 | - * @return string |
|
393 | - */ |
|
394 | - protected function getAlternativeOptionTemplate() |
|
395 | - { |
|
396 | - return str_replace("%s", "'%s'", parent::getAlternativeOptionTemplate()); |
|
397 | - } |
|
389 | + /** |
|
390 | + * Get the error message template for suggesting an alternative for a specific sniff. |
|
391 | + * |
|
392 | + * @return string |
|
393 | + */ |
|
394 | + protected function getAlternativeOptionTemplate() |
|
395 | + { |
|
396 | + return str_replace("%s", "'%s'", parent::getAlternativeOptionTemplate()); |
|
397 | + } |
|
398 | 398 | } |
@@ -25,639 +25,639 @@ |
||
25 | 25 | */ |
26 | 26 | class NewIniDirectivesSniff extends AbstractNewFeatureSniff |
27 | 27 | { |
28 | - /** |
|
29 | - * A list of new INI directives |
|
30 | - * |
|
31 | - * The array lists : version number with false (not present) or true (present). |
|
32 | - * If's sufficient to list the first version where the ini directive appears. |
|
33 | - * |
|
34 | - * @var array(string) |
|
35 | - */ |
|
36 | - protected $newIniDirectives = array( |
|
37 | - 'auto_globals_jit' => array( |
|
38 | - '4.4' => false, |
|
39 | - '5.0' => true, |
|
40 | - ), |
|
41 | - 'com.code_page' => array( |
|
42 | - '4.4' => false, |
|
43 | - '5.0' => true, |
|
44 | - ), |
|
45 | - 'date.default_latitude' => array( |
|
46 | - '4.4' => false, |
|
47 | - '5.0' => true, |
|
48 | - ), |
|
49 | - 'date.default_longitude' => array( |
|
50 | - '4.4' => false, |
|
51 | - '5.0' => true, |
|
52 | - ), |
|
53 | - 'date.sunrise_zenith' => array( |
|
54 | - '4.4' => false, |
|
55 | - '5.0' => true, |
|
56 | - ), |
|
57 | - 'date.sunset_zenith' => array( |
|
58 | - '4.4' => false, |
|
59 | - '5.0' => true, |
|
60 | - ), |
|
61 | - 'ibase.default_charset' => array( |
|
62 | - '4.4' => false, |
|
63 | - '5.0' => true, |
|
64 | - ), |
|
65 | - 'ibase.default_db' => array( |
|
66 | - '4.4' => false, |
|
67 | - '5.0' => true, |
|
68 | - ), |
|
69 | - 'mail.force_extra_parameters' => array( |
|
70 | - '4.4' => false, |
|
71 | - '5.0' => true, |
|
72 | - ), |
|
73 | - 'mime_magic.debug' => array( |
|
74 | - '4.4' => false, |
|
75 | - '5.0' => true, |
|
76 | - ), |
|
77 | - 'mysqli.max_links' => array( |
|
78 | - '4.4' => false, |
|
79 | - '5.0' => true, |
|
80 | - ), |
|
81 | - 'mysqli.default_port' => array( |
|
82 | - '4.4' => false, |
|
83 | - '5.0' => true, |
|
84 | - ), |
|
85 | - 'mysqli.default_socket' => array( |
|
86 | - '4.4' => false, |
|
87 | - '5.0' => true, |
|
88 | - ), |
|
89 | - 'mysqli.default_host' => array( |
|
90 | - '4.4' => false, |
|
91 | - '5.0' => true, |
|
92 | - ), |
|
93 | - 'mysqli.default_user' => array( |
|
94 | - '4.4' => false, |
|
95 | - '5.0' => true, |
|
96 | - ), |
|
97 | - 'mysqli.default_pw' => array( |
|
98 | - '4.4' => false, |
|
99 | - '5.0' => true, |
|
100 | - ), |
|
101 | - 'report_zend_debug' => array( |
|
102 | - '4.4' => false, |
|
103 | - '5.0' => true, |
|
104 | - ), |
|
105 | - 'session.hash_bits_per_character' => array( |
|
106 | - '4.4' => false, |
|
107 | - '5.0' => true, |
|
108 | - ), |
|
109 | - 'session.hash_function' => array( |
|
110 | - '4.4' => false, |
|
111 | - '5.0' => true, |
|
112 | - ), |
|
113 | - 'soap.wsdl_cache_dir' => array( |
|
114 | - '4.4' => false, |
|
115 | - '5.0' => true, |
|
116 | - ), |
|
117 | - 'soap.wsdl_cache_enabled' => array( |
|
118 | - '4.4' => false, |
|
119 | - '5.0' => true, |
|
120 | - ), |
|
121 | - 'soap.wsdl_cache_ttl' => array( |
|
122 | - '4.4' => false, |
|
123 | - '5.0' => true, |
|
124 | - ), |
|
125 | - 'sqlite.assoc_case' => array( |
|
126 | - '4.4' => false, |
|
127 | - '5.0' => true, |
|
128 | - ), |
|
129 | - 'tidy.clean_output' => array( |
|
130 | - '4.4' => false, |
|
131 | - '5.0' => true, |
|
132 | - ), |
|
133 | - 'tidy.default_config' => array( |
|
134 | - '4.4' => false, |
|
135 | - '5.0' => true, |
|
136 | - ), |
|
137 | - 'zend.ze1_compatibility_mode' => array( |
|
138 | - '4.4' => false, |
|
139 | - '5.0' => true, |
|
140 | - ), |
|
141 | - |
|
142 | - 'date.timezone' => array( |
|
143 | - '5.0' => false, |
|
144 | - '5.1' => true, |
|
145 | - ), |
|
146 | - 'detect_unicode' => array( |
|
147 | - '5.0' => false, |
|
148 | - '5.1' => true, |
|
149 | - ), |
|
150 | - 'fbsql.batchsize' => array( |
|
151 | - '5.0' => false, |
|
152 | - '5.1' => true, |
|
153 | - 'alternative' => 'fbsql.batchSize', |
|
154 | - ), |
|
155 | - 'realpath_cache_size' => array( |
|
156 | - '5.0' => false, |
|
157 | - '5.1' => true, |
|
158 | - ), |
|
159 | - 'realpath_cache_ttl' => array( |
|
160 | - '5.0' => false, |
|
161 | - '5.1' => true, |
|
162 | - ), |
|
163 | - |
|
164 | - 'mbstring.strict_detection' => array( |
|
165 | - '5.1.1' => false, |
|
166 | - '5.1.2' => true, |
|
167 | - ), |
|
168 | - 'mssql.charset' => array( |
|
169 | - '5.1.1' => false, |
|
170 | - '5.1.2' => true, |
|
171 | - ), |
|
172 | - |
|
173 | - 'gd.jpeg_ignore_warning' => array( |
|
174 | - '5.1.2' => false, |
|
175 | - '5.1.3' => true, |
|
176 | - ), |
|
177 | - |
|
178 | - 'fbsql.show_timestamp_decimals' => array( |
|
179 | - '5.1.4' => false, |
|
180 | - '5.1.5' => true, |
|
181 | - ), |
|
182 | - 'soap.wsdl_cache' => array( |
|
183 | - '5.1.4' => false, |
|
184 | - '5.1.5' => true, |
|
185 | - ), |
|
186 | - 'soap.wsdl_cache_limit' => array( |
|
187 | - '5.1.4' => false, |
|
188 | - '5.1.5' => true, |
|
189 | - ), |
|
190 | - |
|
191 | - 'allow_url_include' => array( |
|
192 | - '5.1' => false, |
|
193 | - '5.2' => true, |
|
194 | - ), |
|
195 | - 'filter.default' => array( |
|
196 | - '5.1' => false, |
|
197 | - '5.2' => true, |
|
198 | - ), |
|
199 | - 'filter.default_flags' => array( |
|
200 | - '5.1' => false, |
|
201 | - '5.2' => true, |
|
202 | - ), |
|
203 | - 'pcre.backtrack_limit' => array( |
|
204 | - '5.1' => false, |
|
205 | - '5.2' => true, |
|
206 | - ), |
|
207 | - 'pcre.recursion_limit' => array( |
|
208 | - '5.1' => false, |
|
209 | - '5.2' => true, |
|
210 | - ), |
|
211 | - 'session.cookie_httponly' => array( |
|
212 | - '5.1' => false, |
|
213 | - '5.2' => true, |
|
214 | - ), |
|
215 | - |
|
216 | - 'cgi.check_shebang_line' => array( |
|
217 | - '5.2.0' => false, |
|
218 | - '5.2.1' => true, |
|
219 | - ), |
|
220 | - |
|
221 | - 'max_input_nesting_level' => array( |
|
222 | - '5.2.2' => false, |
|
223 | - '5.2.3' => true, |
|
224 | - ), |
|
225 | - |
|
226 | - 'mysqli.allow_local_infile' => array( |
|
227 | - '5.2.3' => false, |
|
228 | - '5.2.4' => true, |
|
229 | - ), |
|
230 | - |
|
231 | - 'max_file_uploads' => array( |
|
232 | - '5.2.11' => false, |
|
233 | - '5.2.12' => true, |
|
234 | - ), |
|
235 | - |
|
236 | - 'cgi.discard_path' => array( |
|
237 | - '5.2' => false, |
|
238 | - '5.3' => true, |
|
239 | - ), |
|
240 | - 'exit_on_timeout' => array( |
|
241 | - '5.2' => false, |
|
242 | - '5.3' => true, |
|
243 | - ), |
|
244 | - 'intl.default_locale' => array( |
|
245 | - '5.2' => false, |
|
246 | - '5.3' => true, |
|
247 | - ), |
|
248 | - 'intl.error_level' => array( |
|
249 | - '5.2' => false, |
|
250 | - '5.3' => true, |
|
251 | - ), |
|
252 | - 'mail.add_x_header' => array( |
|
253 | - '5.2' => false, |
|
254 | - '5.3' => true, |
|
255 | - ), |
|
256 | - 'mail.log' => array( |
|
257 | - '5.2' => false, |
|
258 | - '5.3' => true, |
|
259 | - ), |
|
260 | - 'mbstring.http_output_conv_mimetype' => array( |
|
261 | - '5.2' => false, |
|
262 | - '5.3' => true, |
|
263 | - ), |
|
264 | - 'mysqli.allow_persistent' => array( |
|
265 | - '5.2' => false, |
|
266 | - '5.3' => true, |
|
267 | - ), |
|
268 | - 'mysqli.cache_size' => array( |
|
269 | - '5.2' => false, |
|
270 | - '5.3' => true, |
|
271 | - ), |
|
272 | - 'mysqli.max_persistent' => array( |
|
273 | - '5.2' => false, |
|
274 | - '5.3' => true, |
|
275 | - ), |
|
276 | - 'mysqlnd.collect_memory_statistics' => array( |
|
277 | - '5.2' => false, |
|
278 | - '5.3' => true, |
|
279 | - ), |
|
280 | - 'mysqlnd.collect_statistics' => array( |
|
281 | - '5.2' => false, |
|
282 | - '5.3' => true, |
|
283 | - ), |
|
284 | - 'mysqlnd.debug' => array( |
|
285 | - '5.2' => false, |
|
286 | - '5.3' => true, |
|
287 | - ), |
|
288 | - 'mysqlnd.net_read_buffer_size' => array( |
|
289 | - '5.2' => false, |
|
290 | - '5.3' => true, |
|
291 | - ), |
|
292 | - 'odbc.default_cursortype' => array( |
|
293 | - '5.2' => false, |
|
294 | - '5.3' => true, |
|
295 | - ), |
|
296 | - 'request_order' => array( |
|
297 | - '5.2' => false, |
|
298 | - '5.3' => true, |
|
299 | - ), |
|
300 | - 'user_ini.cache_ttl' => array( |
|
301 | - '5.2' => false, |
|
302 | - '5.3' => true, |
|
303 | - ), |
|
304 | - 'user_ini.filename' => array( |
|
305 | - '5.2' => false, |
|
306 | - '5.3' => true, |
|
307 | - ), |
|
308 | - 'zend.enable_gc' => array( |
|
309 | - '5.2' => false, |
|
310 | - '5.3' => true, |
|
311 | - ), |
|
312 | - |
|
313 | - 'curl.cainfo' => array( |
|
314 | - '5.3.6' => false, |
|
315 | - '5.3.7' => true, |
|
316 | - ), |
|
317 | - |
|
318 | - 'max_input_vars' => array( |
|
319 | - '5.3.8' => false, |
|
320 | - '5.3.9' => true, |
|
321 | - ), |
|
322 | - |
|
323 | - 'sqlite3.extension_dir' => array( |
|
324 | - '5.3.10' => false, |
|
325 | - '5.3.11' => true, |
|
326 | - ), |
|
327 | - |
|
328 | - 'cli.pager' => array( |
|
329 | - '5.3' => false, |
|
330 | - '5.4' => true, |
|
331 | - ), |
|
332 | - 'cli.prompt' => array( |
|
333 | - '5.3' => false, |
|
334 | - '5.4' => true, |
|
335 | - ), |
|
336 | - 'cli_server.color' => array( |
|
337 | - '5.3' => false, |
|
338 | - '5.4' => true, |
|
339 | - ), |
|
340 | - 'enable_post_data_reading' => array( |
|
341 | - '5.3' => false, |
|
342 | - '5.4' => true, |
|
343 | - ), |
|
344 | - 'mysqlnd.mempool_default_size' => array( |
|
345 | - '5.3' => false, |
|
346 | - '5.4' => true, |
|
347 | - ), |
|
348 | - 'mysqlnd.net_cmd_buffer_size' => array( |
|
349 | - '5.3' => false, |
|
350 | - '5.4' => true, |
|
351 | - ), |
|
352 | - 'mysqlnd.net_read_timeout' => array( |
|
353 | - '5.3' => false, |
|
354 | - '5.4' => true, |
|
355 | - ), |
|
356 | - 'phar.cache_list' => array( |
|
357 | - '5.3' => false, |
|
358 | - '5.4' => true, |
|
359 | - ), |
|
360 | - 'session.upload_progress.enabled' => array( |
|
361 | - '5.3' => false, |
|
362 | - '5.4' => true, |
|
363 | - ), |
|
364 | - 'session.upload_progress.cleanup' => array( |
|
365 | - '5.3' => false, |
|
366 | - '5.4' => true, |
|
367 | - ), |
|
368 | - 'session.upload_progress.name' => array( |
|
369 | - '5.3' => false, |
|
370 | - '5.4' => true, |
|
371 | - ), |
|
372 | - 'session.upload_progress.freq' => array( |
|
373 | - '5.3' => false, |
|
374 | - '5.4' => true, |
|
375 | - ), |
|
376 | - 'session.upload_progress.min_freq' => array( |
|
377 | - '5.3' => false, |
|
378 | - '5.4' => true, |
|
379 | - ), |
|
380 | - 'session.upload_progress.prefix' => array( |
|
381 | - '5.3' => false, |
|
382 | - '5.4' => true, |
|
383 | - ), |
|
384 | - 'windows_show_crt_warning' => array( |
|
385 | - '5.3' => false, |
|
386 | - '5.4' => true, |
|
387 | - ), |
|
388 | - 'zend.detect_unicode' => array( |
|
389 | - '5.3' => false, |
|
390 | - '5.4' => true, |
|
391 | - 'alternative' => 'detect_unicode', |
|
392 | - ), |
|
393 | - 'zend.multibyte' => array( |
|
394 | - '5.3' => false, |
|
395 | - '5.4' => true, |
|
396 | - ), |
|
397 | - 'zend.script_encoding' => array( |
|
398 | - '5.3' => false, |
|
399 | - '5.4' => true, |
|
400 | - ), |
|
401 | - 'zend.signal_check' => array( |
|
402 | - '5.3' => false, |
|
403 | - '5.4' => true, |
|
404 | - ), |
|
405 | - 'mysqlnd.log_mask' => array( |
|
406 | - '5.3' => false, |
|
407 | - '5.4' => true, |
|
408 | - ), |
|
409 | - |
|
410 | - 'intl.use_exceptions' => array( |
|
411 | - '5.4' => false, |
|
412 | - '5.5' => true, |
|
413 | - ), |
|
414 | - 'mysqlnd.sha256_server_public_key' => array( |
|
415 | - '5.4' => false, |
|
416 | - '5.5' => true, |
|
417 | - ), |
|
418 | - 'mysqlnd.trace_alloc' => array( |
|
419 | - '5.4' => false, |
|
420 | - '5.5' => true, |
|
421 | - ), |
|
422 | - 'sys_temp_dir' => array( |
|
423 | - '5.4' => false, |
|
424 | - '5.5' => true, |
|
425 | - ), |
|
426 | - 'xsl.security_prefs' => array( |
|
427 | - '5.4' => false, |
|
428 | - '5.5' => true, |
|
429 | - ), |
|
430 | - |
|
431 | - 'session.use_strict_mode' => array( |
|
432 | - '5.5.1' => false, |
|
433 | - '5.5.2' => true, |
|
434 | - ), |
|
435 | - |
|
436 | - 'mysqli.rollback_on_cached_plink' => array( |
|
437 | - '5.5' => false, |
|
438 | - '5.6' => true, |
|
439 | - ), |
|
440 | - |
|
441 | - 'assert.exception' => array( |
|
442 | - '5.6' => false, |
|
443 | - '7.0' => true, |
|
444 | - ), |
|
445 | - 'pcre.jit' => array( |
|
446 | - '5.6' => false, |
|
447 | - '7.0' => true, |
|
448 | - ), |
|
449 | - 'session.lazy_write' => array( |
|
450 | - '5.6' => false, |
|
451 | - '7.0' => true, |
|
452 | - ), |
|
453 | - 'zend.assertions' => array( |
|
454 | - '5.6' => false, |
|
455 | - '7.0' => true, |
|
456 | - ), |
|
457 | - |
|
458 | - 'hard_timeout' => array( |
|
459 | - '7.0' => false, |
|
460 | - '7.1' => true, |
|
461 | - ), |
|
462 | - 'session.sid_length' => array( |
|
463 | - '7.0' => false, |
|
464 | - '7.1' => true, |
|
465 | - ), |
|
466 | - 'session.sid_bits_per_character' => array( |
|
467 | - '7.0' => false, |
|
468 | - '7.1' => true, |
|
469 | - ), |
|
470 | - 'session.trans_sid_hosts' => array( |
|
471 | - '7.0' => false, |
|
472 | - '7.1' => true, |
|
473 | - ), |
|
474 | - 'session.trans_sid_tags' => array( |
|
475 | - '7.0' => false, |
|
476 | - '7.1' => true, |
|
477 | - ), |
|
478 | - 'url_rewriter.hosts' => array( |
|
479 | - '7.0' => false, |
|
480 | - '7.1' => true, |
|
481 | - ), |
|
482 | - |
|
483 | - // Introduced in PHP 7.1.25, 7.2.13, 7.3.0. |
|
484 | - 'imap.enable_insecure_rsh' => array( |
|
485 | - '7.1.24' => false, |
|
486 | - '7.1.25' => true, |
|
487 | - ), |
|
488 | - |
|
489 | - 'syslog.facility' => array( |
|
490 | - '7.2' => false, |
|
491 | - '7.3' => true, |
|
492 | - ), |
|
493 | - 'syslog.filter' => array( |
|
494 | - '7.2' => false, |
|
495 | - '7.3' => true, |
|
496 | - ), |
|
497 | - 'syslog.ident' => array( |
|
498 | - '7.2' => false, |
|
499 | - '7.3' => true, |
|
500 | - ), |
|
501 | - 'session.cookie_samesite' => array( |
|
502 | - '7.2' => false, |
|
503 | - '7.3' => true, |
|
504 | - ), |
|
505 | - ); |
|
506 | - |
|
507 | - /** |
|
508 | - * Returns an array of tokens this test wants to listen for. |
|
509 | - * |
|
510 | - * @return array |
|
511 | - */ |
|
512 | - public function register() |
|
513 | - { |
|
514 | - return array(\T_STRING); |
|
515 | - } |
|
516 | - |
|
517 | - /** |
|
518 | - * Processes this test, when one of its tokens is encountered. |
|
519 | - * |
|
520 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
521 | - * @param int $stackPtr The position of the current token in the |
|
522 | - * stack passed in $tokens. |
|
523 | - * |
|
524 | - * @return void |
|
525 | - */ |
|
526 | - public function process(File $phpcsFile, $stackPtr) |
|
527 | - { |
|
528 | - $tokens = $phpcsFile->getTokens(); |
|
529 | - |
|
530 | - $ignore = array( |
|
531 | - \T_DOUBLE_COLON => true, |
|
532 | - \T_OBJECT_OPERATOR => true, |
|
533 | - \T_FUNCTION => true, |
|
534 | - \T_CONST => true, |
|
535 | - ); |
|
536 | - |
|
537 | - $prevToken = $phpcsFile->findPrevious(\T_WHITESPACE, ($stackPtr - 1), null, true); |
|
538 | - if (isset($ignore[$tokens[$prevToken]['code']]) === true) { |
|
539 | - // Not a call to a PHP function. |
|
540 | - return; |
|
541 | - } |
|
542 | - |
|
543 | - $functionLc = strtolower($tokens[$stackPtr]['content']); |
|
544 | - if (isset($this->iniFunctions[$functionLc]) === false) { |
|
545 | - return; |
|
546 | - } |
|
547 | - |
|
548 | - $iniToken = $this->getFunctionCallParameter($phpcsFile, $stackPtr, $this->iniFunctions[$functionLc]); |
|
549 | - if ($iniToken === false) { |
|
550 | - return; |
|
551 | - } |
|
552 | - |
|
553 | - $filteredToken = $this->stripQuotes($iniToken['raw']); |
|
554 | - if (isset($this->newIniDirectives[$filteredToken]) === false) { |
|
555 | - return; |
|
556 | - } |
|
557 | - |
|
558 | - $itemInfo = array( |
|
559 | - 'name' => $filteredToken, |
|
560 | - 'functionLc' => $functionLc, |
|
561 | - ); |
|
562 | - $this->handleFeature($phpcsFile, $iniToken['end'], $itemInfo); |
|
563 | - } |
|
564 | - |
|
565 | - |
|
566 | - /** |
|
567 | - * Get the relevant sub-array for a specific item from a multi-dimensional array. |
|
568 | - * |
|
569 | - * @param array $itemInfo Base information about the item. |
|
570 | - * |
|
571 | - * @return array Version and other information about the item. |
|
572 | - */ |
|
573 | - public function getItemArray(array $itemInfo) |
|
574 | - { |
|
575 | - return $this->newIniDirectives[$itemInfo['name']]; |
|
576 | - } |
|
577 | - |
|
578 | - |
|
579 | - /** |
|
580 | - * Get an array of the non-PHP-version array keys used in a sub-array. |
|
581 | - * |
|
582 | - * @return array |
|
583 | - */ |
|
584 | - protected function getNonVersionArrayKeys() |
|
585 | - { |
|
586 | - return array('alternative'); |
|
587 | - } |
|
588 | - |
|
589 | - |
|
590 | - /** |
|
591 | - * Retrieve the relevant detail (version) information for use in an error message. |
|
592 | - * |
|
593 | - * @param array $itemArray Version and other information about the item. |
|
594 | - * @param array $itemInfo Base information about the item. |
|
595 | - * |
|
596 | - * @return array |
|
597 | - */ |
|
598 | - public function getErrorInfo(array $itemArray, array $itemInfo) |
|
599 | - { |
|
600 | - $errorInfo = parent::getErrorInfo($itemArray, $itemInfo); |
|
601 | - $errorInfo['alternative'] = ''; |
|
602 | - |
|
603 | - if (isset($itemArray['alternative']) === true) { |
|
604 | - $errorInfo['alternative'] = $itemArray['alternative']; |
|
605 | - } |
|
606 | - |
|
607 | - // Lower error level to warning if the function used was ini_get. |
|
608 | - if ($errorInfo['error'] === true && $itemInfo['functionLc'] === 'ini_get') { |
|
609 | - $errorInfo['error'] = false; |
|
610 | - } |
|
611 | - |
|
612 | - return $errorInfo; |
|
613 | - } |
|
614 | - |
|
615 | - |
|
616 | - /** |
|
617 | - * Get the error message template for this sniff. |
|
618 | - * |
|
619 | - * @return string |
|
620 | - */ |
|
621 | - protected function getErrorMsgTemplate() |
|
622 | - { |
|
623 | - return "INI directive '%s' is not present in PHP version %s or earlier"; |
|
624 | - } |
|
625 | - |
|
626 | - |
|
627 | - /** |
|
628 | - * Allow for concrete child classes to filter the error message before it's passed to PHPCS. |
|
629 | - * |
|
630 | - * @param string $error The error message which was created. |
|
631 | - * @param array $itemInfo Base information about the item this error message applies to. |
|
632 | - * @param array $errorInfo Detail information about an item this error message applies to. |
|
633 | - * |
|
634 | - * @return string |
|
635 | - */ |
|
636 | - protected function filterErrorMsg($error, array $itemInfo, array $errorInfo) |
|
637 | - { |
|
638 | - if ($errorInfo['alternative'] !== '') { |
|
639 | - $error .= ". This directive was previously called '%s'."; |
|
640 | - } |
|
641 | - |
|
642 | - return $error; |
|
643 | - } |
|
644 | - |
|
645 | - |
|
646 | - /** |
|
647 | - * Allow for concrete child classes to filter the error data before it's passed to PHPCS. |
|
648 | - * |
|
649 | - * @param array $data The error data array which was created. |
|
650 | - * @param array $itemInfo Base information about the item this error message applies to. |
|
651 | - * @param array $errorInfo Detail information about an item this error message applies to. |
|
652 | - * |
|
653 | - * @return array |
|
654 | - */ |
|
655 | - protected function filterErrorData(array $data, array $itemInfo, array $errorInfo) |
|
656 | - { |
|
657 | - if ($errorInfo['alternative'] !== '') { |
|
658 | - $data[] = $errorInfo['alternative']; |
|
659 | - } |
|
660 | - |
|
661 | - return $data; |
|
662 | - } |
|
28 | + /** |
|
29 | + * A list of new INI directives |
|
30 | + * |
|
31 | + * The array lists : version number with false (not present) or true (present). |
|
32 | + * If's sufficient to list the first version where the ini directive appears. |
|
33 | + * |
|
34 | + * @var array(string) |
|
35 | + */ |
|
36 | + protected $newIniDirectives = array( |
|
37 | + 'auto_globals_jit' => array( |
|
38 | + '4.4' => false, |
|
39 | + '5.0' => true, |
|
40 | + ), |
|
41 | + 'com.code_page' => array( |
|
42 | + '4.4' => false, |
|
43 | + '5.0' => true, |
|
44 | + ), |
|
45 | + 'date.default_latitude' => array( |
|
46 | + '4.4' => false, |
|
47 | + '5.0' => true, |
|
48 | + ), |
|
49 | + 'date.default_longitude' => array( |
|
50 | + '4.4' => false, |
|
51 | + '5.0' => true, |
|
52 | + ), |
|
53 | + 'date.sunrise_zenith' => array( |
|
54 | + '4.4' => false, |
|
55 | + '5.0' => true, |
|
56 | + ), |
|
57 | + 'date.sunset_zenith' => array( |
|
58 | + '4.4' => false, |
|
59 | + '5.0' => true, |
|
60 | + ), |
|
61 | + 'ibase.default_charset' => array( |
|
62 | + '4.4' => false, |
|
63 | + '5.0' => true, |
|
64 | + ), |
|
65 | + 'ibase.default_db' => array( |
|
66 | + '4.4' => false, |
|
67 | + '5.0' => true, |
|
68 | + ), |
|
69 | + 'mail.force_extra_parameters' => array( |
|
70 | + '4.4' => false, |
|
71 | + '5.0' => true, |
|
72 | + ), |
|
73 | + 'mime_magic.debug' => array( |
|
74 | + '4.4' => false, |
|
75 | + '5.0' => true, |
|
76 | + ), |
|
77 | + 'mysqli.max_links' => array( |
|
78 | + '4.4' => false, |
|
79 | + '5.0' => true, |
|
80 | + ), |
|
81 | + 'mysqli.default_port' => array( |
|
82 | + '4.4' => false, |
|
83 | + '5.0' => true, |
|
84 | + ), |
|
85 | + 'mysqli.default_socket' => array( |
|
86 | + '4.4' => false, |
|
87 | + '5.0' => true, |
|
88 | + ), |
|
89 | + 'mysqli.default_host' => array( |
|
90 | + '4.4' => false, |
|
91 | + '5.0' => true, |
|
92 | + ), |
|
93 | + 'mysqli.default_user' => array( |
|
94 | + '4.4' => false, |
|
95 | + '5.0' => true, |
|
96 | + ), |
|
97 | + 'mysqli.default_pw' => array( |
|
98 | + '4.4' => false, |
|
99 | + '5.0' => true, |
|
100 | + ), |
|
101 | + 'report_zend_debug' => array( |
|
102 | + '4.4' => false, |
|
103 | + '5.0' => true, |
|
104 | + ), |
|
105 | + 'session.hash_bits_per_character' => array( |
|
106 | + '4.4' => false, |
|
107 | + '5.0' => true, |
|
108 | + ), |
|
109 | + 'session.hash_function' => array( |
|
110 | + '4.4' => false, |
|
111 | + '5.0' => true, |
|
112 | + ), |
|
113 | + 'soap.wsdl_cache_dir' => array( |
|
114 | + '4.4' => false, |
|
115 | + '5.0' => true, |
|
116 | + ), |
|
117 | + 'soap.wsdl_cache_enabled' => array( |
|
118 | + '4.4' => false, |
|
119 | + '5.0' => true, |
|
120 | + ), |
|
121 | + 'soap.wsdl_cache_ttl' => array( |
|
122 | + '4.4' => false, |
|
123 | + '5.0' => true, |
|
124 | + ), |
|
125 | + 'sqlite.assoc_case' => array( |
|
126 | + '4.4' => false, |
|
127 | + '5.0' => true, |
|
128 | + ), |
|
129 | + 'tidy.clean_output' => array( |
|
130 | + '4.4' => false, |
|
131 | + '5.0' => true, |
|
132 | + ), |
|
133 | + 'tidy.default_config' => array( |
|
134 | + '4.4' => false, |
|
135 | + '5.0' => true, |
|
136 | + ), |
|
137 | + 'zend.ze1_compatibility_mode' => array( |
|
138 | + '4.4' => false, |
|
139 | + '5.0' => true, |
|
140 | + ), |
|
141 | + |
|
142 | + 'date.timezone' => array( |
|
143 | + '5.0' => false, |
|
144 | + '5.1' => true, |
|
145 | + ), |
|
146 | + 'detect_unicode' => array( |
|
147 | + '5.0' => false, |
|
148 | + '5.1' => true, |
|
149 | + ), |
|
150 | + 'fbsql.batchsize' => array( |
|
151 | + '5.0' => false, |
|
152 | + '5.1' => true, |
|
153 | + 'alternative' => 'fbsql.batchSize', |
|
154 | + ), |
|
155 | + 'realpath_cache_size' => array( |
|
156 | + '5.0' => false, |
|
157 | + '5.1' => true, |
|
158 | + ), |
|
159 | + 'realpath_cache_ttl' => array( |
|
160 | + '5.0' => false, |
|
161 | + '5.1' => true, |
|
162 | + ), |
|
163 | + |
|
164 | + 'mbstring.strict_detection' => array( |
|
165 | + '5.1.1' => false, |
|
166 | + '5.1.2' => true, |
|
167 | + ), |
|
168 | + 'mssql.charset' => array( |
|
169 | + '5.1.1' => false, |
|
170 | + '5.1.2' => true, |
|
171 | + ), |
|
172 | + |
|
173 | + 'gd.jpeg_ignore_warning' => array( |
|
174 | + '5.1.2' => false, |
|
175 | + '5.1.3' => true, |
|
176 | + ), |
|
177 | + |
|
178 | + 'fbsql.show_timestamp_decimals' => array( |
|
179 | + '5.1.4' => false, |
|
180 | + '5.1.5' => true, |
|
181 | + ), |
|
182 | + 'soap.wsdl_cache' => array( |
|
183 | + '5.1.4' => false, |
|
184 | + '5.1.5' => true, |
|
185 | + ), |
|
186 | + 'soap.wsdl_cache_limit' => array( |
|
187 | + '5.1.4' => false, |
|
188 | + '5.1.5' => true, |
|
189 | + ), |
|
190 | + |
|
191 | + 'allow_url_include' => array( |
|
192 | + '5.1' => false, |
|
193 | + '5.2' => true, |
|
194 | + ), |
|
195 | + 'filter.default' => array( |
|
196 | + '5.1' => false, |
|
197 | + '5.2' => true, |
|
198 | + ), |
|
199 | + 'filter.default_flags' => array( |
|
200 | + '5.1' => false, |
|
201 | + '5.2' => true, |
|
202 | + ), |
|
203 | + 'pcre.backtrack_limit' => array( |
|
204 | + '5.1' => false, |
|
205 | + '5.2' => true, |
|
206 | + ), |
|
207 | + 'pcre.recursion_limit' => array( |
|
208 | + '5.1' => false, |
|
209 | + '5.2' => true, |
|
210 | + ), |
|
211 | + 'session.cookie_httponly' => array( |
|
212 | + '5.1' => false, |
|
213 | + '5.2' => true, |
|
214 | + ), |
|
215 | + |
|
216 | + 'cgi.check_shebang_line' => array( |
|
217 | + '5.2.0' => false, |
|
218 | + '5.2.1' => true, |
|
219 | + ), |
|
220 | + |
|
221 | + 'max_input_nesting_level' => array( |
|
222 | + '5.2.2' => false, |
|
223 | + '5.2.3' => true, |
|
224 | + ), |
|
225 | + |
|
226 | + 'mysqli.allow_local_infile' => array( |
|
227 | + '5.2.3' => false, |
|
228 | + '5.2.4' => true, |
|
229 | + ), |
|
230 | + |
|
231 | + 'max_file_uploads' => array( |
|
232 | + '5.2.11' => false, |
|
233 | + '5.2.12' => true, |
|
234 | + ), |
|
235 | + |
|
236 | + 'cgi.discard_path' => array( |
|
237 | + '5.2' => false, |
|
238 | + '5.3' => true, |
|
239 | + ), |
|
240 | + 'exit_on_timeout' => array( |
|
241 | + '5.2' => false, |
|
242 | + '5.3' => true, |
|
243 | + ), |
|
244 | + 'intl.default_locale' => array( |
|
245 | + '5.2' => false, |
|
246 | + '5.3' => true, |
|
247 | + ), |
|
248 | + 'intl.error_level' => array( |
|
249 | + '5.2' => false, |
|
250 | + '5.3' => true, |
|
251 | + ), |
|
252 | + 'mail.add_x_header' => array( |
|
253 | + '5.2' => false, |
|
254 | + '5.3' => true, |
|
255 | + ), |
|
256 | + 'mail.log' => array( |
|
257 | + '5.2' => false, |
|
258 | + '5.3' => true, |
|
259 | + ), |
|
260 | + 'mbstring.http_output_conv_mimetype' => array( |
|
261 | + '5.2' => false, |
|
262 | + '5.3' => true, |
|
263 | + ), |
|
264 | + 'mysqli.allow_persistent' => array( |
|
265 | + '5.2' => false, |
|
266 | + '5.3' => true, |
|
267 | + ), |
|
268 | + 'mysqli.cache_size' => array( |
|
269 | + '5.2' => false, |
|
270 | + '5.3' => true, |
|
271 | + ), |
|
272 | + 'mysqli.max_persistent' => array( |
|
273 | + '5.2' => false, |
|
274 | + '5.3' => true, |
|
275 | + ), |
|
276 | + 'mysqlnd.collect_memory_statistics' => array( |
|
277 | + '5.2' => false, |
|
278 | + '5.3' => true, |
|
279 | + ), |
|
280 | + 'mysqlnd.collect_statistics' => array( |
|
281 | + '5.2' => false, |
|
282 | + '5.3' => true, |
|
283 | + ), |
|
284 | + 'mysqlnd.debug' => array( |
|
285 | + '5.2' => false, |
|
286 | + '5.3' => true, |
|
287 | + ), |
|
288 | + 'mysqlnd.net_read_buffer_size' => array( |
|
289 | + '5.2' => false, |
|
290 | + '5.3' => true, |
|
291 | + ), |
|
292 | + 'odbc.default_cursortype' => array( |
|
293 | + '5.2' => false, |
|
294 | + '5.3' => true, |
|
295 | + ), |
|
296 | + 'request_order' => array( |
|
297 | + '5.2' => false, |
|
298 | + '5.3' => true, |
|
299 | + ), |
|
300 | + 'user_ini.cache_ttl' => array( |
|
301 | + '5.2' => false, |
|
302 | + '5.3' => true, |
|
303 | + ), |
|
304 | + 'user_ini.filename' => array( |
|
305 | + '5.2' => false, |
|
306 | + '5.3' => true, |
|
307 | + ), |
|
308 | + 'zend.enable_gc' => array( |
|
309 | + '5.2' => false, |
|
310 | + '5.3' => true, |
|
311 | + ), |
|
312 | + |
|
313 | + 'curl.cainfo' => array( |
|
314 | + '5.3.6' => false, |
|
315 | + '5.3.7' => true, |
|
316 | + ), |
|
317 | + |
|
318 | + 'max_input_vars' => array( |
|
319 | + '5.3.8' => false, |
|
320 | + '5.3.9' => true, |
|
321 | + ), |
|
322 | + |
|
323 | + 'sqlite3.extension_dir' => array( |
|
324 | + '5.3.10' => false, |
|
325 | + '5.3.11' => true, |
|
326 | + ), |
|
327 | + |
|
328 | + 'cli.pager' => array( |
|
329 | + '5.3' => false, |
|
330 | + '5.4' => true, |
|
331 | + ), |
|
332 | + 'cli.prompt' => array( |
|
333 | + '5.3' => false, |
|
334 | + '5.4' => true, |
|
335 | + ), |
|
336 | + 'cli_server.color' => array( |
|
337 | + '5.3' => false, |
|
338 | + '5.4' => true, |
|
339 | + ), |
|
340 | + 'enable_post_data_reading' => array( |
|
341 | + '5.3' => false, |
|
342 | + '5.4' => true, |
|
343 | + ), |
|
344 | + 'mysqlnd.mempool_default_size' => array( |
|
345 | + '5.3' => false, |
|
346 | + '5.4' => true, |
|
347 | + ), |
|
348 | + 'mysqlnd.net_cmd_buffer_size' => array( |
|
349 | + '5.3' => false, |
|
350 | + '5.4' => true, |
|
351 | + ), |
|
352 | + 'mysqlnd.net_read_timeout' => array( |
|
353 | + '5.3' => false, |
|
354 | + '5.4' => true, |
|
355 | + ), |
|
356 | + 'phar.cache_list' => array( |
|
357 | + '5.3' => false, |
|
358 | + '5.4' => true, |
|
359 | + ), |
|
360 | + 'session.upload_progress.enabled' => array( |
|
361 | + '5.3' => false, |
|
362 | + '5.4' => true, |
|
363 | + ), |
|
364 | + 'session.upload_progress.cleanup' => array( |
|
365 | + '5.3' => false, |
|
366 | + '5.4' => true, |
|
367 | + ), |
|
368 | + 'session.upload_progress.name' => array( |
|
369 | + '5.3' => false, |
|
370 | + '5.4' => true, |
|
371 | + ), |
|
372 | + 'session.upload_progress.freq' => array( |
|
373 | + '5.3' => false, |
|
374 | + '5.4' => true, |
|
375 | + ), |
|
376 | + 'session.upload_progress.min_freq' => array( |
|
377 | + '5.3' => false, |
|
378 | + '5.4' => true, |
|
379 | + ), |
|
380 | + 'session.upload_progress.prefix' => array( |
|
381 | + '5.3' => false, |
|
382 | + '5.4' => true, |
|
383 | + ), |
|
384 | + 'windows_show_crt_warning' => array( |
|
385 | + '5.3' => false, |
|
386 | + '5.4' => true, |
|
387 | + ), |
|
388 | + 'zend.detect_unicode' => array( |
|
389 | + '5.3' => false, |
|
390 | + '5.4' => true, |
|
391 | + 'alternative' => 'detect_unicode', |
|
392 | + ), |
|
393 | + 'zend.multibyte' => array( |
|
394 | + '5.3' => false, |
|
395 | + '5.4' => true, |
|
396 | + ), |
|
397 | + 'zend.script_encoding' => array( |
|
398 | + '5.3' => false, |
|
399 | + '5.4' => true, |
|
400 | + ), |
|
401 | + 'zend.signal_check' => array( |
|
402 | + '5.3' => false, |
|
403 | + '5.4' => true, |
|
404 | + ), |
|
405 | + 'mysqlnd.log_mask' => array( |
|
406 | + '5.3' => false, |
|
407 | + '5.4' => true, |
|
408 | + ), |
|
409 | + |
|
410 | + 'intl.use_exceptions' => array( |
|
411 | + '5.4' => false, |
|
412 | + '5.5' => true, |
|
413 | + ), |
|
414 | + 'mysqlnd.sha256_server_public_key' => array( |
|
415 | + '5.4' => false, |
|
416 | + '5.5' => true, |
|
417 | + ), |
|
418 | + 'mysqlnd.trace_alloc' => array( |
|
419 | + '5.4' => false, |
|
420 | + '5.5' => true, |
|
421 | + ), |
|
422 | + 'sys_temp_dir' => array( |
|
423 | + '5.4' => false, |
|
424 | + '5.5' => true, |
|
425 | + ), |
|
426 | + 'xsl.security_prefs' => array( |
|
427 | + '5.4' => false, |
|
428 | + '5.5' => true, |
|
429 | + ), |
|
430 | + |
|
431 | + 'session.use_strict_mode' => array( |
|
432 | + '5.5.1' => false, |
|
433 | + '5.5.2' => true, |
|
434 | + ), |
|
435 | + |
|
436 | + 'mysqli.rollback_on_cached_plink' => array( |
|
437 | + '5.5' => false, |
|
438 | + '5.6' => true, |
|
439 | + ), |
|
440 | + |
|
441 | + 'assert.exception' => array( |
|
442 | + '5.6' => false, |
|
443 | + '7.0' => true, |
|
444 | + ), |
|
445 | + 'pcre.jit' => array( |
|
446 | + '5.6' => false, |
|
447 | + '7.0' => true, |
|
448 | + ), |
|
449 | + 'session.lazy_write' => array( |
|
450 | + '5.6' => false, |
|
451 | + '7.0' => true, |
|
452 | + ), |
|
453 | + 'zend.assertions' => array( |
|
454 | + '5.6' => false, |
|
455 | + '7.0' => true, |
|
456 | + ), |
|
457 | + |
|
458 | + 'hard_timeout' => array( |
|
459 | + '7.0' => false, |
|
460 | + '7.1' => true, |
|
461 | + ), |
|
462 | + 'session.sid_length' => array( |
|
463 | + '7.0' => false, |
|
464 | + '7.1' => true, |
|
465 | + ), |
|
466 | + 'session.sid_bits_per_character' => array( |
|
467 | + '7.0' => false, |
|
468 | + '7.1' => true, |
|
469 | + ), |
|
470 | + 'session.trans_sid_hosts' => array( |
|
471 | + '7.0' => false, |
|
472 | + '7.1' => true, |
|
473 | + ), |
|
474 | + 'session.trans_sid_tags' => array( |
|
475 | + '7.0' => false, |
|
476 | + '7.1' => true, |
|
477 | + ), |
|
478 | + 'url_rewriter.hosts' => array( |
|
479 | + '7.0' => false, |
|
480 | + '7.1' => true, |
|
481 | + ), |
|
482 | + |
|
483 | + // Introduced in PHP 7.1.25, 7.2.13, 7.3.0. |
|
484 | + 'imap.enable_insecure_rsh' => array( |
|
485 | + '7.1.24' => false, |
|
486 | + '7.1.25' => true, |
|
487 | + ), |
|
488 | + |
|
489 | + 'syslog.facility' => array( |
|
490 | + '7.2' => false, |
|
491 | + '7.3' => true, |
|
492 | + ), |
|
493 | + 'syslog.filter' => array( |
|
494 | + '7.2' => false, |
|
495 | + '7.3' => true, |
|
496 | + ), |
|
497 | + 'syslog.ident' => array( |
|
498 | + '7.2' => false, |
|
499 | + '7.3' => true, |
|
500 | + ), |
|
501 | + 'session.cookie_samesite' => array( |
|
502 | + '7.2' => false, |
|
503 | + '7.3' => true, |
|
504 | + ), |
|
505 | + ); |
|
506 | + |
|
507 | + /** |
|
508 | + * Returns an array of tokens this test wants to listen for. |
|
509 | + * |
|
510 | + * @return array |
|
511 | + */ |
|
512 | + public function register() |
|
513 | + { |
|
514 | + return array(\T_STRING); |
|
515 | + } |
|
516 | + |
|
517 | + /** |
|
518 | + * Processes this test, when one of its tokens is encountered. |
|
519 | + * |
|
520 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
521 | + * @param int $stackPtr The position of the current token in the |
|
522 | + * stack passed in $tokens. |
|
523 | + * |
|
524 | + * @return void |
|
525 | + */ |
|
526 | + public function process(File $phpcsFile, $stackPtr) |
|
527 | + { |
|
528 | + $tokens = $phpcsFile->getTokens(); |
|
529 | + |
|
530 | + $ignore = array( |
|
531 | + \T_DOUBLE_COLON => true, |
|
532 | + \T_OBJECT_OPERATOR => true, |
|
533 | + \T_FUNCTION => true, |
|
534 | + \T_CONST => true, |
|
535 | + ); |
|
536 | + |
|
537 | + $prevToken = $phpcsFile->findPrevious(\T_WHITESPACE, ($stackPtr - 1), null, true); |
|
538 | + if (isset($ignore[$tokens[$prevToken]['code']]) === true) { |
|
539 | + // Not a call to a PHP function. |
|
540 | + return; |
|
541 | + } |
|
542 | + |
|
543 | + $functionLc = strtolower($tokens[$stackPtr]['content']); |
|
544 | + if (isset($this->iniFunctions[$functionLc]) === false) { |
|
545 | + return; |
|
546 | + } |
|
547 | + |
|
548 | + $iniToken = $this->getFunctionCallParameter($phpcsFile, $stackPtr, $this->iniFunctions[$functionLc]); |
|
549 | + if ($iniToken === false) { |
|
550 | + return; |
|
551 | + } |
|
552 | + |
|
553 | + $filteredToken = $this->stripQuotes($iniToken['raw']); |
|
554 | + if (isset($this->newIniDirectives[$filteredToken]) === false) { |
|
555 | + return; |
|
556 | + } |
|
557 | + |
|
558 | + $itemInfo = array( |
|
559 | + 'name' => $filteredToken, |
|
560 | + 'functionLc' => $functionLc, |
|
561 | + ); |
|
562 | + $this->handleFeature($phpcsFile, $iniToken['end'], $itemInfo); |
|
563 | + } |
|
564 | + |
|
565 | + |
|
566 | + /** |
|
567 | + * Get the relevant sub-array for a specific item from a multi-dimensional array. |
|
568 | + * |
|
569 | + * @param array $itemInfo Base information about the item. |
|
570 | + * |
|
571 | + * @return array Version and other information about the item. |
|
572 | + */ |
|
573 | + public function getItemArray(array $itemInfo) |
|
574 | + { |
|
575 | + return $this->newIniDirectives[$itemInfo['name']]; |
|
576 | + } |
|
577 | + |
|
578 | + |
|
579 | + /** |
|
580 | + * Get an array of the non-PHP-version array keys used in a sub-array. |
|
581 | + * |
|
582 | + * @return array |
|
583 | + */ |
|
584 | + protected function getNonVersionArrayKeys() |
|
585 | + { |
|
586 | + return array('alternative'); |
|
587 | + } |
|
588 | + |
|
589 | + |
|
590 | + /** |
|
591 | + * Retrieve the relevant detail (version) information for use in an error message. |
|
592 | + * |
|
593 | + * @param array $itemArray Version and other information about the item. |
|
594 | + * @param array $itemInfo Base information about the item. |
|
595 | + * |
|
596 | + * @return array |
|
597 | + */ |
|
598 | + public function getErrorInfo(array $itemArray, array $itemInfo) |
|
599 | + { |
|
600 | + $errorInfo = parent::getErrorInfo($itemArray, $itemInfo); |
|
601 | + $errorInfo['alternative'] = ''; |
|
602 | + |
|
603 | + if (isset($itemArray['alternative']) === true) { |
|
604 | + $errorInfo['alternative'] = $itemArray['alternative']; |
|
605 | + } |
|
606 | + |
|
607 | + // Lower error level to warning if the function used was ini_get. |
|
608 | + if ($errorInfo['error'] === true && $itemInfo['functionLc'] === 'ini_get') { |
|
609 | + $errorInfo['error'] = false; |
|
610 | + } |
|
611 | + |
|
612 | + return $errorInfo; |
|
613 | + } |
|
614 | + |
|
615 | + |
|
616 | + /** |
|
617 | + * Get the error message template for this sniff. |
|
618 | + * |
|
619 | + * @return string |
|
620 | + */ |
|
621 | + protected function getErrorMsgTemplate() |
|
622 | + { |
|
623 | + return "INI directive '%s' is not present in PHP version %s or earlier"; |
|
624 | + } |
|
625 | + |
|
626 | + |
|
627 | + /** |
|
628 | + * Allow for concrete child classes to filter the error message before it's passed to PHPCS. |
|
629 | + * |
|
630 | + * @param string $error The error message which was created. |
|
631 | + * @param array $itemInfo Base information about the item this error message applies to. |
|
632 | + * @param array $errorInfo Detail information about an item this error message applies to. |
|
633 | + * |
|
634 | + * @return string |
|
635 | + */ |
|
636 | + protected function filterErrorMsg($error, array $itemInfo, array $errorInfo) |
|
637 | + { |
|
638 | + if ($errorInfo['alternative'] !== '') { |
|
639 | + $error .= ". This directive was previously called '%s'."; |
|
640 | + } |
|
641 | + |
|
642 | + return $error; |
|
643 | + } |
|
644 | + |
|
645 | + |
|
646 | + /** |
|
647 | + * Allow for concrete child classes to filter the error data before it's passed to PHPCS. |
|
648 | + * |
|
649 | + * @param array $data The error data array which was created. |
|
650 | + * @param array $itemInfo Base information about the item this error message applies to. |
|
651 | + * @param array $errorInfo Detail information about an item this error message applies to. |
|
652 | + * |
|
653 | + * @return array |
|
654 | + */ |
|
655 | + protected function filterErrorData(array $data, array $itemInfo, array $errorInfo) |
|
656 | + { |
|
657 | + if ($errorInfo['alternative'] !== '') { |
|
658 | + $data[] = $errorInfo['alternative']; |
|
659 | + } |
|
660 | + |
|
661 | + return $data; |
|
662 | + } |
|
663 | 663 | } |