comparison vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/WhiteSpace/EmptyLinesSniff.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 129ea1e6d783
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2 /**
3 * Drupal_Sniffs_WhiteSpace_EmptyLinesSniff.
4 *
5 * @category PHP
6 * @package PHP_CodeSniffer
7 * @link http://pear.php.net/package/PHP_CodeSniffer
8 */
9
10 /**
11 * Drupal_Sniffs_WhiteSpace_EmptyLinesSniff.
12 *
13 * Checks that there are not more than 2 empty lines following each other.
14 *
15 * @category PHP
16 * @package PHP_CodeSniffer
17 * @link http://pear.php.net/package/PHP_CodeSniffer
18 */
19 class Drupal_Sniffs_WhiteSpace_EmptyLinesSniff implements PHP_CodeSniffer_Sniff
20 {
21
22 /**
23 * A list of tokenizers this sniff supports.
24 *
25 * @var array
26 */
27 public $supportedTokenizers = array(
28 'PHP',
29 'JS',
30 'CSS',
31 );
32
33
34 /**
35 * Returns an array of tokens this test wants to listen for.
36 *
37 * @return array
38 */
39 public function register()
40 {
41 return array(T_WHITESPACE);
42
43 }//end register()
44
45
46 /**
47 * Processes this test, when one of its tokens is encountered.
48 *
49 * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
50 * @param int $stackPtr The position of the current token
51 * in the stack passed in $tokens.
52 *
53 * @return void
54 */
55 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
56 {
57 $tokens = $phpcsFile->getTokens();
58 if ($tokens[$stackPtr]['content'] === $phpcsFile->eolChar
59 && isset($tokens[($stackPtr + 1)]) === true
60 && $tokens[($stackPtr + 1)]['content'] === $phpcsFile->eolChar
61 && isset($tokens[($stackPtr + 2)]) === true
62 && $tokens[($stackPtr + 2)]['content'] === $phpcsFile->eolChar
63 && isset($tokens[($stackPtr + 3)]) === true
64 && $tokens[($stackPtr + 3)]['content'] === $phpcsFile->eolChar
65 ) {
66 $error = 'More than 2 empty lines are not allowed';
67 $phpcsFile->addError($error, ($stackPtr + 3), 'EmptyLines');
68 }
69
70 }//end process()
71
72
73 }//end class