comparison vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/ControlStructures/ControlSignatureSniff.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 4c8ae668cc8c
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
5 * @category PHP 5 * @category PHP
6 * @package PHP_CodeSniffer 6 * @package PHP_CodeSniffer
7 * @link http://pear.php.net/package/PHP_CodeSniffer 7 * @link http://pear.php.net/package/PHP_CodeSniffer
8 */ 8 */
9 9
10 namespace Drupal\Sniffs\ControlStructures;
11
12 use PHP_CodeSniffer\Files\File;
13 use PHP_CodeSniffer\Sniffs\Sniff;
14 use PHP_CodeSniffer\Util\Tokens;
15
10 /** 16 /**
11 * Verifies that control statements conform to their coding standards. 17 * Verifies that control statements conform to their coding standards.
12 * 18 *
13 * Largely copied from Squiz_Sniffs_ControlStructures_ControlSignatureSniff and 19 * Largely copied from
14 * adapted for Drupal's else on new lines. 20 * \PHP_CodeSniffer\Standards\Squiz\Sniffs\ControlStructures\ControlSignatureSniff
21 * and adapted for Drupal's else on new lines.
15 * 22 *
16 * @category PHP 23 * @category PHP
17 * @package PHP_CodeSniffer 24 * @package PHP_CodeSniffer
18 * @link http://pear.php.net/package/PHP_CodeSniffer 25 * @link http://pear.php.net/package/PHP_CodeSniffer
19 */ 26 */
20 class Drupal_Sniffs_ControlStructures_ControlSignatureSniff implements PHP_CodeSniffer_Sniff 27 class ControlSignatureSniff implements Sniff
21 { 28 {
22 29
23 /** 30 /**
24 * A list of tokenizers this sniff supports. 31 * A list of tokenizers this sniff supports.
25 * 32 *
55 62
56 63
57 /** 64 /**
58 * Processes this test, when one of its tokens is encountered. 65 * Processes this test, when one of its tokens is encountered.
59 * 66 *
60 * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. 67 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
61 * @param int $stackPtr The position of the current token in the 68 * @param int $stackPtr The position of the current token in the
62 * stack passed in $tokens. 69 * stack passed in $tokens.
63 * 70 *
64 * @return void 71 * @return void
65 */ 72 */
66 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) 73 public function process(File $phpcsFile, $stackPtr)
67 { 74 {
68 $tokens = $phpcsFile->getTokens(); 75 $tokens = $phpcsFile->getTokens();
69 76
70 if (isset($tokens[($stackPtr + 1)]) === false) { 77 if (isset($tokens[($stackPtr + 1)]) === false) {
71 return; 78 return;
153 continue; 160 continue;
154 } 161 }
155 162
156 // Skip all empty tokens on the same line as the opener. 163 // Skip all empty tokens on the same line as the opener.
157 if ($tokens[$next]['line'] === $tokens[$opener]['line'] 164 if ($tokens[$next]['line'] === $tokens[$opener]['line']
158 && (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$code]) === true 165 && (isset(Tokens::$emptyTokens[$code]) === true
159 || $code === T_CLOSE_TAG) 166 || $code === T_CLOSE_TAG)
160 ) { 167 ) {
161 continue; 168 continue;
162 } 169 }
163 170
246 }//end if 253 }//end if
247 } else if ($tokens[$stackPtr]['code'] === T_ELSE 254 } else if ($tokens[$stackPtr]['code'] === T_ELSE
248 || $tokens[$stackPtr]['code'] === T_ELSEIF 255 || $tokens[$stackPtr]['code'] === T_ELSEIF
249 || $tokens[$stackPtr]['code'] === T_CATCH 256 || $tokens[$stackPtr]['code'] === T_CATCH
250 ) { 257 ) {
251 $closer = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true); 258 $closer = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
252 if ($closer === false || $tokens[$closer]['code'] !== T_CLOSE_CURLY_BRACKET) { 259 if ($closer === false || $tokens[$closer]['code'] !== T_CLOSE_CURLY_BRACKET) {
253 return; 260 return;
254 } 261 }
255 } else { 262 } else {
256 return; 263 return;