comparison vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/CSS/ClassDefinitionNameSpacingSniff.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
1 <?php 1 <?php
2 /** 2 /**
3 * Drupal_Sniffs_CSS_ClassDefinitionNameSpacingSniff. 3 * \Drupal\Sniffs\CSS\ClassDefinitionNameSpacingSniff.
4 * 4 *
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\CSS;
11
12 use PHP_CodeSniffer\Files\File;
13 use PHP_CodeSniffer\Sniffs\Sniff;
14 use PHP_CodeSniffer\Util\Tokens;
15
10 /** 16 /**
11 * Ensure there are no blank lines between the names of classes/IDs. Copied from 17 * Ensure there are no blank lines between the names of classes/IDs. Copied from
12 * Squiz_Sniffs_CSS_ClassDefinitionNameSpacingSniff because we also check for comma 18 * \PHP_CodeSniffer\Standards\Squiz\Sniffs\CSS\ClassDefinitionNameSpacingSniff
13 * separated selectors on their own line. 19 * because we also check for comma separated selectors on their own line.
14 * 20 *
15 * @category PHP 21 * @category PHP
16 * @package PHP_CodeSniffer 22 * @package PHP_CodeSniffer
17 * @link http://pear.php.net/package/PHP_CodeSniffer 23 * @link http://pear.php.net/package/PHP_CodeSniffer
18 */ 24 */
19 class Drupal_Sniffs_CSS_ClassDefinitionNameSpacingSniff implements PHP_CodeSniffer_Sniff 25 class ClassDefinitionNameSpacingSniff implements Sniff
20 { 26 {
21 27
22 /** 28 /**
23 * A list of tokenizers this sniff supports. 29 * A list of tokenizers this sniff supports.
24 * 30 *
40 46
41 47
42 /** 48 /**
43 * Processes the tokens that this sniff is interested in. 49 * Processes the tokens that this sniff is interested in.
44 * 50 *
45 * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. 51 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where the token was found.
46 * @param int $stackPtr The position in the stack where 52 * @param int $stackPtr The position in the stack where
47 * the token was found. 53 * the token was found.
48 * 54 *
49 * @return void 55 * @return void
50 */ 56 */
51 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) 57 public function process(File $phpcsFile, $stackPtr)
52 { 58 {
53 $tokens = $phpcsFile->getTokens(); 59 $tokens = $phpcsFile->getTokens();
54 60
55 // Do not check nested style definitions as, for example, in @media style rules. 61 // Do not check nested style definitions as, for example, in @media style rules.
56 $nested = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, ($stackPtr + 1), $tokens[$stackPtr]['bracket_closer']); 62 $nested = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, ($stackPtr + 1), $tokens[$stackPtr]['bracket_closer']);
63 $endTokens = array( 69 $endTokens = array(
64 T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET, 70 T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET,
65 T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, 71 T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET,
66 T_OPEN_TAG => T_OPEN_TAG, 72 T_OPEN_TAG => T_OPEN_TAG,
67 ); 73 );
68 $endTokens += PHP_CodeSniffer_Tokens::$commentTokens; 74 $endTokens += Tokens::$commentTokens;
69 75
70 $foundContent = false; 76 $foundContent = false;
71 $currentLine = $tokens[$stackPtr]['line']; 77 $currentLine = $tokens[$stackPtr]['line'];
72 for ($i = ($stackPtr - 1); $i >= 0; $i--) { 78 for ($i = ($stackPtr - 1); $i >= 0; $i--) {
73 if (isset($endTokens[$tokens[$i]['code']]) === true) { 79 if (isset($endTokens[$tokens[$i]['code']]) === true) {