comparison vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/WhiteSpace/NamespaceSniff.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_NamespaceSniff.
4 *
5 * @category PHP
6 * @package PHP_CodeSniffer
7 * @link http://pear.php.net/package/PHP_CodeSniffer
8 */
9
10 /**
11 * Checks that there is exactly one space after the namespace keyword.
12 *
13 * @category PHP
14 * @package PHP_CodeSniffer
15 * @link http://pear.php.net/package/PHP_CodeSniffer
16 */
17 class Drupal_Sniffs_WhiteSpace_NamespaceSniff implements PHP_CodeSniffer_Sniff
18 {
19
20
21 /**
22 * Returns an array of tokens this test wants to listen for.
23 *
24 * @return array
25 */
26 public function register()
27 {
28 return array(T_NAMESPACE);
29
30 }//end register()
31
32
33 /**
34 * Processes this test, when one of its tokens is encountered.
35 *
36 * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
37 * @param int $stackPtr The position of the current token
38 * in the stack passed in $tokens.
39 *
40 * @return void
41 */
42 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
43 {
44 $tokens = $phpcsFile->getTokens();
45
46 if ($tokens[($stackPtr + 1)]['content'] !== ' ') {
47 $error = 'There must be exactly one space after the namepace keyword';
48 $fix = $phpcsFile->addFixableError($error, ($stackPtr + 1), 'OneSpace');
49 if ($fix === true) {
50 $phpcsFile->fixer->replaceToken(($stackPtr + 1), ' ');
51 }
52 }
53
54 }//end process()
55
56
57 }//end class