@@ -29,51 +29,51 @@ |
||
29 | 29 | { |
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * Returns an array of tokens this test wants to listen for. |
|
34 | - * |
|
35 | - * @return array |
|
36 | - */ |
|
37 | - public function register() |
|
38 | - { |
|
39 | - return array(T_STRING); |
|
32 | + /** |
|
33 | + * Returns an array of tokens this test wants to listen for. |
|
34 | + * |
|
35 | + * @return array |
|
36 | + */ |
|
37 | + public function register() |
|
38 | + { |
|
39 | + return array(T_STRING); |
|
40 | 40 | |
41 | - }//end register() |
|
41 | + }//end register() |
|
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(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
54 | - { |
|
55 | - $tokens = $phpcsFile->getTokens(); |
|
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(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
54 | + { |
|
55 | + $tokens = $phpcsFile->getTokens(); |
|
56 | 56 | |
57 | - $ignore = array( |
|
58 | - T_DOUBLE_COLON => true, |
|
59 | - T_OBJECT_OPERATOR => true, |
|
60 | - T_FUNCTION => true, |
|
61 | - T_CONST => true, |
|
62 | - ); |
|
57 | + $ignore = array( |
|
58 | + T_DOUBLE_COLON => true, |
|
59 | + T_OBJECT_OPERATOR => true, |
|
60 | + T_FUNCTION => true, |
|
61 | + T_CONST => true, |
|
62 | + ); |
|
63 | 63 | |
64 | - $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); |
|
65 | - if (isset($ignore[$tokens[$prevToken]['code']]) === true) { |
|
66 | - // Not a call to a PHP function. |
|
67 | - return; |
|
68 | - } |
|
64 | + $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); |
|
65 | + if (isset($ignore[$tokens[$prevToken]['code']]) === true) { |
|
66 | + // Not a call to a PHP function. |
|
67 | + return; |
|
68 | + } |
|
69 | 69 | |
70 | - $function = strtolower($tokens[$stackPtr]['content']); |
|
71 | - if ($function === 'php_sapi_name') { |
|
72 | - $error = 'Use the PHP_SAPI constant instead of calling php_sapi_name()'; |
|
73 | - $phpcsFile->addError($error, $stackPtr, 'FunctionFound'); |
|
74 | - } |
|
70 | + $function = strtolower($tokens[$stackPtr]['content']); |
|
71 | + if ($function === 'php_sapi_name') { |
|
72 | + $error = 'Use the PHP_SAPI constant instead of calling php_sapi_name()'; |
|
73 | + $phpcsFile->addError($error, $stackPtr, 'FunctionFound'); |
|
74 | + } |
|
75 | 75 | |
76 | - }//end process() |
|
76 | + }//end process() |
|
77 | 77 | |
78 | 78 | |
79 | 79 | }//end class |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function register() |
38 | 38 | { |
39 | - return array(T_STRING); |
|
39 | + return array( T_STRING ); |
|
40 | 40 | |
41 | 41 | }//end register() |
42 | 42 | |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @return void |
52 | 52 | */ |
53 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
53 | + public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) |
|
54 | 54 | { |
55 | 55 | $tokens = $phpcsFile->getTokens(); |
56 | 56 | |
@@ -61,16 +61,16 @@ discard block |
||
61 | 61 | T_CONST => true, |
62 | 62 | ); |
63 | 63 | |
64 | - $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); |
|
65 | - if (isset($ignore[$tokens[$prevToken]['code']]) === true) { |
|
64 | + $prevToken = $phpcsFile->findPrevious( T_WHITESPACE, ( $stackPtr - 1 ), null, true ); |
|
65 | + if ( isset( $ignore[ $tokens[ $prevToken ][ 'code' ] ] ) === true ) { |
|
66 | 66 | // Not a call to a PHP function. |
67 | 67 | return; |
68 | 68 | } |
69 | 69 | |
70 | - $function = strtolower($tokens[$stackPtr]['content']); |
|
71 | - if ($function === 'php_sapi_name') { |
|
70 | + $function = strtolower( $tokens[ $stackPtr ][ 'content' ] ); |
|
71 | + if ( $function === 'php_sapi_name' ) { |
|
72 | 72 | $error = 'Use the PHP_SAPI constant instead of calling php_sapi_name()'; |
73 | - $phpcsFile->addError($error, $stackPtr, 'FunctionFound'); |
|
73 | + $phpcsFile->addError( $error, $stackPtr, 'FunctionFound' ); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | }//end process() |
@@ -25,8 +25,7 @@ discard block |
||
25 | 25 | * @version Release: @package_version@ |
26 | 26 | * @link http://pear.php.net/package/PHP_CodeSniffer |
27 | 27 | */ |
28 | -class Generic_Sniffs_PHP_SAPIUsageSniff implements PHP_CodeSniffer_Sniff |
|
29 | -{ |
|
28 | +class Generic_Sniffs_PHP_SAPIUsageSniff implements PHP_CodeSniffer_Sniff { |
|
30 | 29 | |
31 | 30 | |
32 | 31 | /** |
@@ -34,8 +33,7 @@ discard block |
||
34 | 33 | * |
35 | 34 | * @return array |
36 | 35 | */ |
37 | - public function register() |
|
38 | - { |
|
36 | + public function register() { |
|
39 | 37 | return array(T_STRING); |
40 | 38 | |
41 | 39 | }//end register() |
@@ -50,8 +48,7 @@ discard block |
||
50 | 48 | * |
51 | 49 | * @return void |
52 | 50 | */ |
53 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
54 | - { |
|
51 | + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { |
|
55 | 52 | $tokens = $phpcsFile->getTokens(); |
56 | 53 | |
57 | 54 | $ignore = array( |
@@ -27,48 +27,48 @@ |
||
27 | 27 | { |
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * Returns an array of tokens this test wants to listen for. |
|
32 | - * |
|
33 | - * @return array |
|
34 | - */ |
|
35 | - public function register() |
|
36 | - { |
|
37 | - return array(T_OPEN_TAG); |
|
30 | + /** |
|
31 | + * Returns an array of tokens this test wants to listen for. |
|
32 | + * |
|
33 | + * @return array |
|
34 | + */ |
|
35 | + public function register() |
|
36 | + { |
|
37 | + return array(T_OPEN_TAG); |
|
38 | 38 | |
39 | - }//end register() |
|
39 | + }//end register() |
|
40 | 40 | |
41 | 41 | |
42 | - /** |
|
43 | - * Processes this sniff, when one of its tokens is encountered. |
|
44 | - * |
|
45 | - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
46 | - * @param int $stackPtr The position of the current token in |
|
47 | - * the stack passed in $tokens. |
|
48 | - * |
|
49 | - * @return void |
|
50 | - */ |
|
51 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
52 | - { |
|
53 | - $expected = 0; |
|
54 | - if ($stackPtr > 0) { |
|
55 | - // Allow a shebang line. |
|
56 | - $tokens = $phpcsFile->getTokens(); |
|
57 | - if (substr($tokens[0]['content'], 0, 2) === '#!') { |
|
58 | - $expected = 1; |
|
59 | - } |
|
60 | - } |
|
42 | + /** |
|
43 | + * Processes this sniff, when one of its tokens is encountered. |
|
44 | + * |
|
45 | + * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
46 | + * @param int $stackPtr The position of the current token in |
|
47 | + * the stack passed in $tokens. |
|
48 | + * |
|
49 | + * @return void |
|
50 | + */ |
|
51 | + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
52 | + { |
|
53 | + $expected = 0; |
|
54 | + if ($stackPtr > 0) { |
|
55 | + // Allow a shebang line. |
|
56 | + $tokens = $phpcsFile->getTokens(); |
|
57 | + if (substr($tokens[0]['content'], 0, 2) === '#!') { |
|
58 | + $expected = 1; |
|
59 | + } |
|
60 | + } |
|
61 | 61 | |
62 | - if ($stackPtr !== $expected) { |
|
63 | - $error = 'The opening PHP tag must be the first content in the file'; |
|
64 | - $phpcsFile->addError($error, $stackPtr, 'Found'); |
|
65 | - } |
|
62 | + if ($stackPtr !== $expected) { |
|
63 | + $error = 'The opening PHP tag must be the first content in the file'; |
|
64 | + $phpcsFile->addError($error, $stackPtr, 'Found'); |
|
65 | + } |
|
66 | 66 | |
67 | - // Skip the rest of the file so we don't pick up additional |
|
68 | - // open tags, typically embedded in HTML. |
|
69 | - return $phpcsFile->numTokens; |
|
67 | + // Skip the rest of the file so we don't pick up additional |
|
68 | + // open tags, typically embedded in HTML. |
|
69 | + return $phpcsFile->numTokens; |
|
70 | 70 | |
71 | - }//end process() |
|
71 | + }//end process() |
|
72 | 72 | |
73 | 73 | |
74 | 74 | }//end class |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public function register() |
36 | 36 | { |
37 | - return array(T_OPEN_TAG); |
|
37 | + return array( T_OPEN_TAG ); |
|
38 | 38 | |
39 | 39 | }//end register() |
40 | 40 | |
@@ -48,20 +48,20 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @return void |
50 | 50 | */ |
51 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
51 | + public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) |
|
52 | 52 | { |
53 | 53 | $expected = 0; |
54 | - if ($stackPtr > 0) { |
|
54 | + if ( $stackPtr > 0 ) { |
|
55 | 55 | // Allow a shebang line. |
56 | 56 | $tokens = $phpcsFile->getTokens(); |
57 | - if (substr($tokens[0]['content'], 0, 2) === '#!') { |
|
57 | + if ( substr( $tokens[ 0 ][ 'content' ], 0, 2 ) === '#!' ) { |
|
58 | 58 | $expected = 1; |
59 | 59 | } |
60 | 60 | } |
61 | 61 | |
62 | - if ($stackPtr !== $expected) { |
|
62 | + if ( $stackPtr !== $expected ) { |
|
63 | 63 | $error = 'The opening PHP tag must be the first content in the file'; |
64 | - $phpcsFile->addError($error, $stackPtr, 'Found'); |
|
64 | + $phpcsFile->addError( $error, $stackPtr, 'Found' ); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | // Skip the rest of the file so we don't pick up additional |
@@ -23,8 +23,7 @@ discard block |
||
23 | 23 | * @version Release: @package_version@ |
24 | 24 | * @link http://pear.php.net/package/PHP_CodeSniffer |
25 | 25 | */ |
26 | -class Generic_Sniffs_PHP_CharacterBeforePHPOpeningTagSniff implements PHP_CodeSniffer_Sniff |
|
27 | -{ |
|
26 | +class Generic_Sniffs_PHP_CharacterBeforePHPOpeningTagSniff implements PHP_CodeSniffer_Sniff { |
|
28 | 27 | |
29 | 28 | |
30 | 29 | /** |
@@ -32,8 +31,7 @@ discard block |
||
32 | 31 | * |
33 | 32 | * @return array |
34 | 33 | */ |
35 | - public function register() |
|
36 | - { |
|
34 | + public function register() { |
|
37 | 35 | return array(T_OPEN_TAG); |
38 | 36 | |
39 | 37 | }//end register() |
@@ -48,8 +46,7 @@ discard block |
||
48 | 46 | * |
49 | 47 | * @return void |
50 | 48 | */ |
51 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
52 | - { |
|
49 | + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { |
|
53 | 50 | $expected = 0; |
54 | 51 | if ($stackPtr > 0) { |
55 | 52 | // Allow a shebang line. |
@@ -29,110 +29,110 @@ |
||
29 | 29 | class Generic_Sniffs_Strings_UnnecessaryStringConcatSniff implements PHP_CodeSniffer_Sniff |
30 | 30 | { |
31 | 31 | |
32 | - /** |
|
33 | - * A list of tokenizers this sniff supports. |
|
34 | - * |
|
35 | - * @var array |
|
36 | - */ |
|
37 | - public $supportedTokenizers = array( |
|
38 | - 'PHP', |
|
39 | - 'JS', |
|
40 | - ); |
|
41 | - |
|
42 | - /** |
|
43 | - * If true, an error will be thrown; otherwise a warning. |
|
44 | - * |
|
45 | - * @var bool |
|
46 | - */ |
|
47 | - public $error = true; |
|
48 | - |
|
49 | - /** |
|
50 | - * If true, strings concatenated over multiple lines are allowed. |
|
51 | - * |
|
52 | - * Useful if you break strings over multiple lines to work |
|
53 | - * within a max line length. |
|
54 | - * |
|
55 | - * @var bool |
|
56 | - */ |
|
57 | - public $allowMultiline = false; |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * Returns an array of tokens this test wants to listen for. |
|
62 | - * |
|
63 | - * @return array |
|
64 | - */ |
|
65 | - public function register() |
|
66 | - { |
|
67 | - return array( |
|
68 | - T_STRING_CONCAT, |
|
69 | - T_PLUS, |
|
70 | - ); |
|
71 | - |
|
72 | - }//end register() |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * Processes this sniff, when one of its tokens is encountered. |
|
77 | - * |
|
78 | - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
79 | - * @param int $stackPtr The position of the current token |
|
80 | - * in the stack passed in $tokens. |
|
81 | - * |
|
82 | - * @return void |
|
83 | - */ |
|
84 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
85 | - { |
|
86 | - // Work out which type of file this is for. |
|
87 | - $tokens = $phpcsFile->getTokens(); |
|
88 | - if ($tokens[$stackPtr]['code'] === T_STRING_CONCAT) { |
|
89 | - if ($phpcsFile->tokenizerType === 'JS') { |
|
90 | - return; |
|
91 | - } |
|
92 | - } else { |
|
93 | - if ($phpcsFile->tokenizerType === 'PHP') { |
|
94 | - return; |
|
95 | - } |
|
96 | - } |
|
97 | - |
|
98 | - $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); |
|
99 | - $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); |
|
100 | - if ($prev === false || $next === false) { |
|
101 | - return; |
|
102 | - } |
|
103 | - |
|
104 | - if (isset(PHP_CodeSniffer_Tokens::$stringTokens[$tokens[$prev]['code']]) === true |
|
105 | - && isset(PHP_CodeSniffer_Tokens::$stringTokens[$tokens[$next]['code']]) === true |
|
106 | - ) { |
|
107 | - if ($tokens[$prev]['content'][0] === $tokens[$next]['content'][0]) { |
|
108 | - // Before we throw an error for PHP, allow strings to be |
|
109 | - // combined if they would have < and ? next to each other because |
|
110 | - // this trick is sometimes required in PHP strings. |
|
111 | - if ($phpcsFile->tokenizerType === 'PHP') { |
|
112 | - $prevChar = substr($tokens[$prev]['content'], -2, 1); |
|
113 | - $nextChar = $tokens[$next]['content'][1]; |
|
114 | - $combined = $prevChar.$nextChar; |
|
115 | - if ($combined === '?'.'>' || $combined === '<'.'?') { |
|
116 | - return; |
|
117 | - } |
|
118 | - } |
|
119 | - |
|
120 | - if ($this->allowMultiline === true |
|
121 | - && $tokens[$prev]['line'] !== $tokens[$next]['line'] |
|
122 | - ) { |
|
123 | - return; |
|
124 | - } |
|
125 | - |
|
126 | - $error = 'String concat is not required here; use a single string instead'; |
|
127 | - if ($this->error === true) { |
|
128 | - $phpcsFile->addError($error, $stackPtr, 'Found'); |
|
129 | - } else { |
|
130 | - $phpcsFile->addWarning($error, $stackPtr, 'Found'); |
|
131 | - } |
|
132 | - }//end if |
|
133 | - }//end if |
|
134 | - |
|
135 | - }//end process() |
|
32 | + /** |
|
33 | + * A list of tokenizers this sniff supports. |
|
34 | + * |
|
35 | + * @var array |
|
36 | + */ |
|
37 | + public $supportedTokenizers = array( |
|
38 | + 'PHP', |
|
39 | + 'JS', |
|
40 | + ); |
|
41 | + |
|
42 | + /** |
|
43 | + * If true, an error will be thrown; otherwise a warning. |
|
44 | + * |
|
45 | + * @var bool |
|
46 | + */ |
|
47 | + public $error = true; |
|
48 | + |
|
49 | + /** |
|
50 | + * If true, strings concatenated over multiple lines are allowed. |
|
51 | + * |
|
52 | + * Useful if you break strings over multiple lines to work |
|
53 | + * within a max line length. |
|
54 | + * |
|
55 | + * @var bool |
|
56 | + */ |
|
57 | + public $allowMultiline = false; |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * Returns an array of tokens this test wants to listen for. |
|
62 | + * |
|
63 | + * @return array |
|
64 | + */ |
|
65 | + public function register() |
|
66 | + { |
|
67 | + return array( |
|
68 | + T_STRING_CONCAT, |
|
69 | + T_PLUS, |
|
70 | + ); |
|
71 | + |
|
72 | + }//end register() |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * Processes this sniff, when one of its tokens is encountered. |
|
77 | + * |
|
78 | + * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
79 | + * @param int $stackPtr The position of the current token |
|
80 | + * in the stack passed in $tokens. |
|
81 | + * |
|
82 | + * @return void |
|
83 | + */ |
|
84 | + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
85 | + { |
|
86 | + // Work out which type of file this is for. |
|
87 | + $tokens = $phpcsFile->getTokens(); |
|
88 | + if ($tokens[$stackPtr]['code'] === T_STRING_CONCAT) { |
|
89 | + if ($phpcsFile->tokenizerType === 'JS') { |
|
90 | + return; |
|
91 | + } |
|
92 | + } else { |
|
93 | + if ($phpcsFile->tokenizerType === 'PHP') { |
|
94 | + return; |
|
95 | + } |
|
96 | + } |
|
97 | + |
|
98 | + $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); |
|
99 | + $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); |
|
100 | + if ($prev === false || $next === false) { |
|
101 | + return; |
|
102 | + } |
|
103 | + |
|
104 | + if (isset(PHP_CodeSniffer_Tokens::$stringTokens[$tokens[$prev]['code']]) === true |
|
105 | + && isset(PHP_CodeSniffer_Tokens::$stringTokens[$tokens[$next]['code']]) === true |
|
106 | + ) { |
|
107 | + if ($tokens[$prev]['content'][0] === $tokens[$next]['content'][0]) { |
|
108 | + // Before we throw an error for PHP, allow strings to be |
|
109 | + // combined if they would have < and ? next to each other because |
|
110 | + // this trick is sometimes required in PHP strings. |
|
111 | + if ($phpcsFile->tokenizerType === 'PHP') { |
|
112 | + $prevChar = substr($tokens[$prev]['content'], -2, 1); |
|
113 | + $nextChar = $tokens[$next]['content'][1]; |
|
114 | + $combined = $prevChar.$nextChar; |
|
115 | + if ($combined === '?'.'>' || $combined === '<'.'?') { |
|
116 | + return; |
|
117 | + } |
|
118 | + } |
|
119 | + |
|
120 | + if ($this->allowMultiline === true |
|
121 | + && $tokens[$prev]['line'] !== $tokens[$next]['line'] |
|
122 | + ) { |
|
123 | + return; |
|
124 | + } |
|
125 | + |
|
126 | + $error = 'String concat is not required here; use a single string instead'; |
|
127 | + if ($this->error === true) { |
|
128 | + $phpcsFile->addError($error, $stackPtr, 'Found'); |
|
129 | + } else { |
|
130 | + $phpcsFile->addWarning($error, $stackPtr, 'Found'); |
|
131 | + } |
|
132 | + }//end if |
|
133 | + }//end if |
|
134 | + |
|
135 | + }//end process() |
|
136 | 136 | |
137 | 137 | |
138 | 138 | }//end class |
@@ -81,53 +81,53 @@ |
||
81 | 81 | * |
82 | 82 | * @return void |
83 | 83 | */ |
84 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
84 | + public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) |
|
85 | 85 | { |
86 | 86 | // Work out which type of file this is for. |
87 | 87 | $tokens = $phpcsFile->getTokens(); |
88 | - if ($tokens[$stackPtr]['code'] === T_STRING_CONCAT) { |
|
89 | - if ($phpcsFile->tokenizerType === 'JS') { |
|
88 | + if ( $tokens[ $stackPtr ][ 'code' ] === T_STRING_CONCAT ) { |
|
89 | + if ( $phpcsFile->tokenizerType === 'JS' ) { |
|
90 | 90 | return; |
91 | 91 | } |
92 | 92 | } else { |
93 | - if ($phpcsFile->tokenizerType === 'PHP') { |
|
93 | + if ( $phpcsFile->tokenizerType === 'PHP' ) { |
|
94 | 94 | return; |
95 | 95 | } |
96 | 96 | } |
97 | 97 | |
98 | - $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); |
|
99 | - $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); |
|
100 | - if ($prev === false || $next === false) { |
|
98 | + $prev = $phpcsFile->findPrevious( T_WHITESPACE, ( $stackPtr - 1 ), null, true ); |
|
99 | + $next = $phpcsFile->findNext( T_WHITESPACE, ( $stackPtr + 1 ), null, true ); |
|
100 | + if ( $prev === false || $next === false ) { |
|
101 | 101 | return; |
102 | 102 | } |
103 | 103 | |
104 | - if (isset(PHP_CodeSniffer_Tokens::$stringTokens[$tokens[$prev]['code']]) === true |
|
105 | - && isset(PHP_CodeSniffer_Tokens::$stringTokens[$tokens[$next]['code']]) === true |
|
104 | + if ( isset( PHP_CodeSniffer_Tokens::$stringTokens[ $tokens[ $prev ][ 'code' ] ] ) === true |
|
105 | + && isset( PHP_CodeSniffer_Tokens::$stringTokens[ $tokens[ $next ][ 'code' ] ] ) === true |
|
106 | 106 | ) { |
107 | - if ($tokens[$prev]['content'][0] === $tokens[$next]['content'][0]) { |
|
107 | + if ( $tokens[ $prev ][ 'content' ][ 0 ] === $tokens[ $next ][ 'content' ][ 0 ] ) { |
|
108 | 108 | // Before we throw an error for PHP, allow strings to be |
109 | 109 | // combined if they would have < and ? next to each other because |
110 | 110 | // this trick is sometimes required in PHP strings. |
111 | - if ($phpcsFile->tokenizerType === 'PHP') { |
|
112 | - $prevChar = substr($tokens[$prev]['content'], -2, 1); |
|
113 | - $nextChar = $tokens[$next]['content'][1]; |
|
114 | - $combined = $prevChar.$nextChar; |
|
115 | - if ($combined === '?'.'>' || $combined === '<'.'?') { |
|
111 | + if ( $phpcsFile->tokenizerType === 'PHP' ) { |
|
112 | + $prevChar = substr( $tokens[ $prev ][ 'content' ], -2, 1 ); |
|
113 | + $nextChar = $tokens[ $next ][ 'content' ][ 1 ]; |
|
114 | + $combined = $prevChar . $nextChar; |
|
115 | + if ( $combined === '?' . '>' || $combined === '<' . '?' ) { |
|
116 | 116 | return; |
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
120 | - if ($this->allowMultiline === true |
|
121 | - && $tokens[$prev]['line'] !== $tokens[$next]['line'] |
|
120 | + if ( $this->allowMultiline === true |
|
121 | + && $tokens[ $prev ][ 'line' ] !== $tokens[ $next ][ 'line' ] |
|
122 | 122 | ) { |
123 | 123 | return; |
124 | 124 | } |
125 | 125 | |
126 | 126 | $error = 'String concat is not required here; use a single string instead'; |
127 | - if ($this->error === true) { |
|
128 | - $phpcsFile->addError($error, $stackPtr, 'Found'); |
|
127 | + if ( $this->error === true ) { |
|
128 | + $phpcsFile->addError( $error, $stackPtr, 'Found' ); |
|
129 | 129 | } else { |
130 | - $phpcsFile->addWarning($error, $stackPtr, 'Found'); |
|
130 | + $phpcsFile->addWarning( $error, $stackPtr, 'Found' ); |
|
131 | 131 | } |
132 | 132 | }//end if |
133 | 133 | }//end if |
@@ -26,8 +26,7 @@ discard block |
||
26 | 26 | * @version Release: @package_version@ |
27 | 27 | * @link http://pear.php.net/package/PHP_CodeSniffer |
28 | 28 | */ |
29 | -class Generic_Sniffs_Strings_UnnecessaryStringConcatSniff implements PHP_CodeSniffer_Sniff |
|
30 | -{ |
|
29 | +class Generic_Sniffs_Strings_UnnecessaryStringConcatSniff implements PHP_CodeSniffer_Sniff { |
|
31 | 30 | |
32 | 31 | /** |
33 | 32 | * A list of tokenizers this sniff supports. |
@@ -62,8 +61,7 @@ discard block |
||
62 | 61 | * |
63 | 62 | * @return array |
64 | 63 | */ |
65 | - public function register() |
|
66 | - { |
|
64 | + public function register() { |
|
67 | 65 | return array( |
68 | 66 | T_STRING_CONCAT, |
69 | 67 | T_PLUS, |
@@ -81,8 +79,7 @@ discard block |
||
81 | 79 | * |
82 | 80 | * @return void |
83 | 81 | */ |
84 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
85 | - { |
|
82 | + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { |
|
86 | 83 | // Work out which type of file this is for. |
87 | 84 | $tokens = $phpcsFile->getTokens(); |
88 | 85 | if ($tokens[$stackPtr]['code'] === T_STRING_CONCAT) { |
@@ -27,53 +27,53 @@ |
||
27 | 27 | { |
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * Registers the tokens that this sniff wants to listen for. |
|
32 | - * |
|
33 | - * @return int[] |
|
34 | - */ |
|
35 | - public function register() |
|
36 | - { |
|
37 | - return array(T_ARRAY); |
|
30 | + /** |
|
31 | + * Registers the tokens that this sniff wants to listen for. |
|
32 | + * |
|
33 | + * @return int[] |
|
34 | + */ |
|
35 | + public function register() |
|
36 | + { |
|
37 | + return array(T_ARRAY); |
|
38 | 38 | |
39 | - }//end register() |
|
39 | + }//end register() |
|
40 | 40 | |
41 | 41 | |
42 | - /** |
|
43 | - * Processes this test, when one of its tokens is encountered. |
|
44 | - * |
|
45 | - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
46 | - * @param int $stackPtr The position of the current token |
|
47 | - * in the stack passed in $tokens. |
|
48 | - * |
|
49 | - * @return void |
|
50 | - */ |
|
51 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
52 | - { |
|
53 | - $phpcsFile->recordMetric($stackPtr, 'Short array syntax used', 'no'); |
|
42 | + /** |
|
43 | + * Processes this test, when one of its tokens is encountered. |
|
44 | + * |
|
45 | + * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
46 | + * @param int $stackPtr The position of the current token |
|
47 | + * in the stack passed in $tokens. |
|
48 | + * |
|
49 | + * @return void |
|
50 | + */ |
|
51 | + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
52 | + { |
|
53 | + $phpcsFile->recordMetric($stackPtr, 'Short array syntax used', 'no'); |
|
54 | 54 | |
55 | - $error = 'Short array syntax must be used to define arrays'; |
|
56 | - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found'); |
|
55 | + $error = 'Short array syntax must be used to define arrays'; |
|
56 | + $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found'); |
|
57 | 57 | |
58 | - if ($fix === true) { |
|
59 | - $tokens = $phpcsFile->getTokens(); |
|
60 | - $opener = $tokens[$stackPtr]['parenthesis_opener']; |
|
61 | - $closer = $tokens[$stackPtr]['parenthesis_closer']; |
|
58 | + if ($fix === true) { |
|
59 | + $tokens = $phpcsFile->getTokens(); |
|
60 | + $opener = $tokens[$stackPtr]['parenthesis_opener']; |
|
61 | + $closer = $tokens[$stackPtr]['parenthesis_closer']; |
|
62 | 62 | |
63 | - $phpcsFile->fixer->beginChangeset(); |
|
63 | + $phpcsFile->fixer->beginChangeset(); |
|
64 | 64 | |
65 | - if ($opener === null) { |
|
66 | - $phpcsFile->fixer->replaceToken($stackPtr, '[]'); |
|
67 | - } else { |
|
68 | - $phpcsFile->fixer->replaceToken($stackPtr, ''); |
|
69 | - $phpcsFile->fixer->replaceToken($opener, '['); |
|
70 | - $phpcsFile->fixer->replaceToken($closer, ']'); |
|
71 | - } |
|
65 | + if ($opener === null) { |
|
66 | + $phpcsFile->fixer->replaceToken($stackPtr, '[]'); |
|
67 | + } else { |
|
68 | + $phpcsFile->fixer->replaceToken($stackPtr, ''); |
|
69 | + $phpcsFile->fixer->replaceToken($opener, '['); |
|
70 | + $phpcsFile->fixer->replaceToken($closer, ']'); |
|
71 | + } |
|
72 | 72 | |
73 | - $phpcsFile->fixer->endChangeset(); |
|
74 | - } |
|
73 | + $phpcsFile->fixer->endChangeset(); |
|
74 | + } |
|
75 | 75 | |
76 | - }//end process() |
|
76 | + }//end process() |
|
77 | 77 | |
78 | 78 | |
79 | 79 | }//end class |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public function register() |
36 | 36 | { |
37 | - return array(T_ARRAY); |
|
37 | + return array( T_ARRAY ); |
|
38 | 38 | |
39 | 39 | }//end register() |
40 | 40 | |
@@ -48,26 +48,26 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @return void |
50 | 50 | */ |
51 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
51 | + public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) |
|
52 | 52 | { |
53 | - $phpcsFile->recordMetric($stackPtr, 'Short array syntax used', 'no'); |
|
53 | + $phpcsFile->recordMetric( $stackPtr, 'Short array syntax used', 'no' ); |
|
54 | 54 | |
55 | 55 | $error = 'Short array syntax must be used to define arrays'; |
56 | - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found'); |
|
56 | + $fix = $phpcsFile->addFixableError( $error, $stackPtr, 'Found' ); |
|
57 | 57 | |
58 | - if ($fix === true) { |
|
58 | + if ( $fix === true ) { |
|
59 | 59 | $tokens = $phpcsFile->getTokens(); |
60 | - $opener = $tokens[$stackPtr]['parenthesis_opener']; |
|
61 | - $closer = $tokens[$stackPtr]['parenthesis_closer']; |
|
60 | + $opener = $tokens[ $stackPtr ][ 'parenthesis_opener' ]; |
|
61 | + $closer = $tokens[ $stackPtr ][ 'parenthesis_closer' ]; |
|
62 | 62 | |
63 | 63 | $phpcsFile->fixer->beginChangeset(); |
64 | 64 | |
65 | - if ($opener === null) { |
|
66 | - $phpcsFile->fixer->replaceToken($stackPtr, '[]'); |
|
65 | + if ( $opener === null ) { |
|
66 | + $phpcsFile->fixer->replaceToken( $stackPtr, '[]' ); |
|
67 | 67 | } else { |
68 | - $phpcsFile->fixer->replaceToken($stackPtr, ''); |
|
69 | - $phpcsFile->fixer->replaceToken($opener, '['); |
|
70 | - $phpcsFile->fixer->replaceToken($closer, ']'); |
|
68 | + $phpcsFile->fixer->replaceToken( $stackPtr, '' ); |
|
69 | + $phpcsFile->fixer->replaceToken( $opener, '[' ); |
|
70 | + $phpcsFile->fixer->replaceToken( $closer, ']' ); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | $phpcsFile->fixer->endChangeset(); |
@@ -23,8 +23,7 @@ discard block |
||
23 | 23 | * @version Release: @package_version@ |
24 | 24 | * @link http://pear.php.net/package/PHP_CodeSniffer |
25 | 25 | */ |
26 | -class Generic_Sniffs_Arrays_DisallowLongArraySyntaxSniff implements PHP_CodeSniffer_Sniff |
|
27 | -{ |
|
26 | +class Generic_Sniffs_Arrays_DisallowLongArraySyntaxSniff implements PHP_CodeSniffer_Sniff { |
|
28 | 27 | |
29 | 28 | |
30 | 29 | /** |
@@ -32,8 +31,7 @@ discard block |
||
32 | 31 | * |
33 | 32 | * @return int[] |
34 | 33 | */ |
35 | - public function register() |
|
36 | - { |
|
34 | + public function register() { |
|
37 | 35 | return array(T_ARRAY); |
38 | 36 | |
39 | 37 | }//end register() |
@@ -48,8 +46,7 @@ discard block |
||
48 | 46 | * |
49 | 47 | * @return void |
50 | 48 | */ |
51 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
52 | - { |
|
49 | + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { |
|
53 | 50 | $phpcsFile->recordMetric($stackPtr, 'Short array syntax used', 'no'); |
54 | 51 | |
55 | 52 | $error = 'Short array syntax must be used to define arrays'; |
@@ -27,46 +27,46 @@ |
||
27 | 27 | { |
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * Registers the tokens that this sniff wants to listen for. |
|
32 | - * |
|
33 | - * @return int[] |
|
34 | - */ |
|
35 | - public function register() |
|
36 | - { |
|
37 | - return array(T_OPEN_SHORT_ARRAY); |
|
30 | + /** |
|
31 | + * Registers the tokens that this sniff wants to listen for. |
|
32 | + * |
|
33 | + * @return int[] |
|
34 | + */ |
|
35 | + public function register() |
|
36 | + { |
|
37 | + return array(T_OPEN_SHORT_ARRAY); |
|
38 | 38 | |
39 | - }//end register() |
|
39 | + }//end register() |
|
40 | 40 | |
41 | 41 | |
42 | - /** |
|
43 | - * Processes this test, when one of its tokens is encountered. |
|
44 | - * |
|
45 | - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
46 | - * @param int $stackPtr The position of the current token |
|
47 | - * in the stack passed in $tokens. |
|
48 | - * |
|
49 | - * @return void |
|
50 | - */ |
|
51 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
52 | - { |
|
53 | - $phpcsFile->recordMetric($stackPtr, 'Short array syntax used', 'yes'); |
|
42 | + /** |
|
43 | + * Processes this test, when one of its tokens is encountered. |
|
44 | + * |
|
45 | + * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
46 | + * @param int $stackPtr The position of the current token |
|
47 | + * in the stack passed in $tokens. |
|
48 | + * |
|
49 | + * @return void |
|
50 | + */ |
|
51 | + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
52 | + { |
|
53 | + $phpcsFile->recordMetric($stackPtr, 'Short array syntax used', 'yes'); |
|
54 | 54 | |
55 | - $error = 'Short array syntax is not allowed'; |
|
56 | - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found'); |
|
55 | + $error = 'Short array syntax is not allowed'; |
|
56 | + $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found'); |
|
57 | 57 | |
58 | - if ($fix === true) { |
|
59 | - $tokens = $phpcsFile->getTokens(); |
|
60 | - $opener = $tokens[$stackPtr]['bracket_opener']; |
|
61 | - $closer = $tokens[$stackPtr]['bracket_closer']; |
|
58 | + if ($fix === true) { |
|
59 | + $tokens = $phpcsFile->getTokens(); |
|
60 | + $opener = $tokens[$stackPtr]['bracket_opener']; |
|
61 | + $closer = $tokens[$stackPtr]['bracket_closer']; |
|
62 | 62 | |
63 | - $phpcsFile->fixer->beginChangeset(); |
|
64 | - $phpcsFile->fixer->replaceToken($opener, 'array('); |
|
65 | - $phpcsFile->fixer->replaceToken($closer, ')'); |
|
66 | - $phpcsFile->fixer->endChangeset(); |
|
67 | - } |
|
63 | + $phpcsFile->fixer->beginChangeset(); |
|
64 | + $phpcsFile->fixer->replaceToken($opener, 'array('); |
|
65 | + $phpcsFile->fixer->replaceToken($closer, ')'); |
|
66 | + $phpcsFile->fixer->endChangeset(); |
|
67 | + } |
|
68 | 68 | |
69 | - }//end process() |
|
69 | + }//end process() |
|
70 | 70 | |
71 | 71 | |
72 | 72 | }//end class |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public function register() |
36 | 36 | { |
37 | - return array(T_OPEN_SHORT_ARRAY); |
|
37 | + return array( T_OPEN_SHORT_ARRAY ); |
|
38 | 38 | |
39 | 39 | }//end register() |
40 | 40 | |
@@ -48,21 +48,21 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @return void |
50 | 50 | */ |
51 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
51 | + public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) |
|
52 | 52 | { |
53 | - $phpcsFile->recordMetric($stackPtr, 'Short array syntax used', 'yes'); |
|
53 | + $phpcsFile->recordMetric( $stackPtr, 'Short array syntax used', 'yes' ); |
|
54 | 54 | |
55 | 55 | $error = 'Short array syntax is not allowed'; |
56 | - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found'); |
|
56 | + $fix = $phpcsFile->addFixableError( $error, $stackPtr, 'Found' ); |
|
57 | 57 | |
58 | - if ($fix === true) { |
|
58 | + if ( $fix === true ) { |
|
59 | 59 | $tokens = $phpcsFile->getTokens(); |
60 | - $opener = $tokens[$stackPtr]['bracket_opener']; |
|
61 | - $closer = $tokens[$stackPtr]['bracket_closer']; |
|
60 | + $opener = $tokens[ $stackPtr ][ 'bracket_opener' ]; |
|
61 | + $closer = $tokens[ $stackPtr ][ 'bracket_closer' ]; |
|
62 | 62 | |
63 | 63 | $phpcsFile->fixer->beginChangeset(); |
64 | - $phpcsFile->fixer->replaceToken($opener, 'array('); |
|
65 | - $phpcsFile->fixer->replaceToken($closer, ')'); |
|
64 | + $phpcsFile->fixer->replaceToken( $opener, 'array(' ); |
|
65 | + $phpcsFile->fixer->replaceToken( $closer, ')' ); |
|
66 | 66 | $phpcsFile->fixer->endChangeset(); |
67 | 67 | } |
68 | 68 |
@@ -23,8 +23,7 @@ discard block |
||
23 | 23 | * @version Release: @package_version@ |
24 | 24 | * @link http://pear.php.net/package/PHP_CodeSniffer |
25 | 25 | */ |
26 | -class Generic_Sniffs_Arrays_DisallowShortArraySyntaxSniff implements PHP_CodeSniffer_Sniff |
|
27 | -{ |
|
26 | +class Generic_Sniffs_Arrays_DisallowShortArraySyntaxSniff implements PHP_CodeSniffer_Sniff { |
|
28 | 27 | |
29 | 28 | |
30 | 29 | /** |
@@ -32,8 +31,7 @@ discard block |
||
32 | 31 | * |
33 | 32 | * @return int[] |
34 | 33 | */ |
35 | - public function register() |
|
36 | - { |
|
34 | + public function register() { |
|
37 | 35 | return array(T_OPEN_SHORT_ARRAY); |
38 | 36 | |
39 | 37 | }//end register() |
@@ -48,8 +46,7 @@ discard block |
||
48 | 46 | * |
49 | 47 | * @return void |
50 | 48 | */ |
51 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
52 | - { |
|
49 | + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { |
|
53 | 50 | $phpcsFile->recordMetric($stackPtr, 'Short array syntax used', 'yes'); |
54 | 51 | |
55 | 52 | $error = 'Short array syntax is not allowed'; |
@@ -28,80 +28,80 @@ |
||
28 | 28 | class Generic_Sniffs_Debug_CSSLintSniff implements PHP_CodeSniffer_Sniff |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * A list of tokenizers this sniff supports. |
|
33 | - * |
|
34 | - * @var array |
|
35 | - */ |
|
36 | - public $supportedTokenizers = array('CSS'); |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * Returns the token types that this sniff is interested in. |
|
41 | - * |
|
42 | - * @return int[] |
|
43 | - */ |
|
44 | - public function register() |
|
45 | - { |
|
46 | - return array(T_OPEN_TAG); |
|
47 | - |
|
48 | - }//end register() |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * Processes the tokens that this sniff is interested in. |
|
53 | - * |
|
54 | - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. |
|
55 | - * @param int $stackPtr The position in the stack where |
|
56 | - * the token was found. |
|
57 | - * |
|
58 | - * @return void |
|
59 | - */ |
|
60 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
61 | - { |
|
62 | - $fileName = $phpcsFile->getFilename(); |
|
63 | - |
|
64 | - $csslintPath = PHP_CodeSniffer::getConfigData('csslint_path'); |
|
65 | - if ($csslintPath === null) { |
|
66 | - return; |
|
67 | - } |
|
68 | - |
|
69 | - $cmd = $csslintPath.' '.escapeshellarg($fileName); |
|
70 | - exec($cmd, $output, $retval); |
|
71 | - |
|
72 | - if (is_array($output) === false) { |
|
73 | - return; |
|
74 | - } |
|
75 | - |
|
76 | - $count = count($output); |
|
77 | - |
|
78 | - for ($i = 0; $i < $count; $i++) { |
|
79 | - $matches = array(); |
|
80 | - $numMatches = preg_match( |
|
81 | - '/(error|warning) at line (\d+)/', |
|
82 | - $output[$i], |
|
83 | - $matches |
|
84 | - ); |
|
85 | - |
|
86 | - if ($numMatches === 0) { |
|
87 | - continue; |
|
88 | - } |
|
89 | - |
|
90 | - $line = (int) $matches[2]; |
|
91 | - $message = 'csslint says: '.$output[($i + 1)]; |
|
92 | - // First line is message with error line and error code. |
|
93 | - // Second is error message. |
|
94 | - // Third is wrong line in file. |
|
95 | - // Fourth is empty line. |
|
96 | - $i += 4; |
|
97 | - |
|
98 | - $phpcsFile->addWarningOnLine($message, $line, 'ExternalTool'); |
|
99 | - }//end for |
|
100 | - |
|
101 | - // Ignore the rest of the file. |
|
102 | - return ($phpcsFile->numTokens + 1); |
|
103 | - |
|
104 | - }//end process() |
|
31 | + /** |
|
32 | + * A list of tokenizers this sniff supports. |
|
33 | + * |
|
34 | + * @var array |
|
35 | + */ |
|
36 | + public $supportedTokenizers = array('CSS'); |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * Returns the token types that this sniff is interested in. |
|
41 | + * |
|
42 | + * @return int[] |
|
43 | + */ |
|
44 | + public function register() |
|
45 | + { |
|
46 | + return array(T_OPEN_TAG); |
|
47 | + |
|
48 | + }//end register() |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * Processes the tokens that this sniff is interested in. |
|
53 | + * |
|
54 | + * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. |
|
55 | + * @param int $stackPtr The position in the stack where |
|
56 | + * the token was found. |
|
57 | + * |
|
58 | + * @return void |
|
59 | + */ |
|
60 | + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
61 | + { |
|
62 | + $fileName = $phpcsFile->getFilename(); |
|
63 | + |
|
64 | + $csslintPath = PHP_CodeSniffer::getConfigData('csslint_path'); |
|
65 | + if ($csslintPath === null) { |
|
66 | + return; |
|
67 | + } |
|
68 | + |
|
69 | + $cmd = $csslintPath.' '.escapeshellarg($fileName); |
|
70 | + exec($cmd, $output, $retval); |
|
71 | + |
|
72 | + if (is_array($output) === false) { |
|
73 | + return; |
|
74 | + } |
|
75 | + |
|
76 | + $count = count($output); |
|
77 | + |
|
78 | + for ($i = 0; $i < $count; $i++) { |
|
79 | + $matches = array(); |
|
80 | + $numMatches = preg_match( |
|
81 | + '/(error|warning) at line (\d+)/', |
|
82 | + $output[$i], |
|
83 | + $matches |
|
84 | + ); |
|
85 | + |
|
86 | + if ($numMatches === 0) { |
|
87 | + continue; |
|
88 | + } |
|
89 | + |
|
90 | + $line = (int) $matches[2]; |
|
91 | + $message = 'csslint says: '.$output[($i + 1)]; |
|
92 | + // First line is message with error line and error code. |
|
93 | + // Second is error message. |
|
94 | + // Third is wrong line in file. |
|
95 | + // Fourth is empty line. |
|
96 | + $i += 4; |
|
97 | + |
|
98 | + $phpcsFile->addWarningOnLine($message, $line, 'ExternalTool'); |
|
99 | + }//end for |
|
100 | + |
|
101 | + // Ignore the rest of the file. |
|
102 | + return ($phpcsFile->numTokens + 1); |
|
103 | + |
|
104 | + }//end process() |
|
105 | 105 | |
106 | 106 | |
107 | 107 | }//end class |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * |
34 | 34 | * @var array |
35 | 35 | */ |
36 | - public $supportedTokenizers = array('CSS'); |
|
36 | + public $supportedTokenizers = array( 'CSS' ); |
|
37 | 37 | |
38 | 38 | |
39 | 39 | /** |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function register() |
45 | 45 | { |
46 | - return array(T_OPEN_TAG); |
|
46 | + return array( T_OPEN_TAG ); |
|
47 | 47 | |
48 | 48 | }//end register() |
49 | 49 | |
@@ -57,49 +57,49 @@ discard block |
||
57 | 57 | * |
58 | 58 | * @return void |
59 | 59 | */ |
60 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
60 | + public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) |
|
61 | 61 | { |
62 | 62 | $fileName = $phpcsFile->getFilename(); |
63 | 63 | |
64 | - $csslintPath = PHP_CodeSniffer::getConfigData('csslint_path'); |
|
65 | - if ($csslintPath === null) { |
|
64 | + $csslintPath = PHP_CodeSniffer::getConfigData( 'csslint_path' ); |
|
65 | + if ( $csslintPath === null ) { |
|
66 | 66 | return; |
67 | 67 | } |
68 | 68 | |
69 | - $cmd = $csslintPath.' '.escapeshellarg($fileName); |
|
70 | - exec($cmd, $output, $retval); |
|
69 | + $cmd = $csslintPath . ' ' . escapeshellarg( $fileName ); |
|
70 | + exec( $cmd, $output, $retval ); |
|
71 | 71 | |
72 | - if (is_array($output) === false) { |
|
72 | + if ( is_array( $output ) === false ) { |
|
73 | 73 | return; |
74 | 74 | } |
75 | 75 | |
76 | - $count = count($output); |
|
76 | + $count = count( $output ); |
|
77 | 77 | |
78 | - for ($i = 0; $i < $count; $i++) { |
|
78 | + for ( $i = 0; $i < $count; $i++ ) { |
|
79 | 79 | $matches = array(); |
80 | 80 | $numMatches = preg_match( |
81 | 81 | '/(error|warning) at line (\d+)/', |
82 | - $output[$i], |
|
82 | + $output[ $i ], |
|
83 | 83 | $matches |
84 | 84 | ); |
85 | 85 | |
86 | - if ($numMatches === 0) { |
|
86 | + if ( $numMatches === 0 ) { |
|
87 | 87 | continue; |
88 | 88 | } |
89 | 89 | |
90 | - $line = (int) $matches[2]; |
|
91 | - $message = 'csslint says: '.$output[($i + 1)]; |
|
90 | + $line = (int) $matches[ 2 ]; |
|
91 | + $message = 'csslint says: ' . $output[ ( $i + 1 ) ]; |
|
92 | 92 | // First line is message with error line and error code. |
93 | 93 | // Second is error message. |
94 | 94 | // Third is wrong line in file. |
95 | 95 | // Fourth is empty line. |
96 | 96 | $i += 4; |
97 | 97 | |
98 | - $phpcsFile->addWarningOnLine($message, $line, 'ExternalTool'); |
|
98 | + $phpcsFile->addWarningOnLine( $message, $line, 'ExternalTool' ); |
|
99 | 99 | }//end for |
100 | 100 | |
101 | 101 | // Ignore the rest of the file. |
102 | - return ($phpcsFile->numTokens + 1); |
|
102 | + return ( $phpcsFile->numTokens + 1 ); |
|
103 | 103 | |
104 | 104 | }//end process() |
105 | 105 |
@@ -25,8 +25,7 @@ discard block |
||
25 | 25 | * @version Release: @package_version@ |
26 | 26 | * @link http://pear.php.net/package/PHP_CodeSniffer |
27 | 27 | */ |
28 | -class Generic_Sniffs_Debug_CSSLintSniff implements PHP_CodeSniffer_Sniff |
|
29 | -{ |
|
28 | +class Generic_Sniffs_Debug_CSSLintSniff implements PHP_CodeSniffer_Sniff { |
|
30 | 29 | |
31 | 30 | /** |
32 | 31 | * A list of tokenizers this sniff supports. |
@@ -41,8 +40,7 @@ discard block |
||
41 | 40 | * |
42 | 41 | * @return int[] |
43 | 42 | */ |
44 | - public function register() |
|
45 | - { |
|
43 | + public function register() { |
|
46 | 44 | return array(T_OPEN_TAG); |
47 | 45 | |
48 | 46 | }//end register() |
@@ -57,8 +55,7 @@ discard block |
||
57 | 55 | * |
58 | 56 | * @return void |
59 | 57 | */ |
60 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
61 | - { |
|
58 | + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { |
|
62 | 59 | $fileName = $phpcsFile->getFilename(); |
63 | 60 | |
64 | 61 | $csslintPath = PHP_CodeSniffer::getConfigData('csslint_path'); |
@@ -30,120 +30,120 @@ |
||
30 | 30 | class Generic_Sniffs_WhiteSpace_DisallowTabIndentSniff implements PHP_CodeSniffer_Sniff |
31 | 31 | { |
32 | 32 | |
33 | - /** |
|
34 | - * A list of tokenizers this sniff supports. |
|
35 | - * |
|
36 | - * @var array |
|
37 | - */ |
|
38 | - public $supportedTokenizers = array( |
|
39 | - 'PHP', |
|
40 | - 'JS', |
|
41 | - 'CSS', |
|
42 | - ); |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * Returns an array of tokens this test wants to listen for. |
|
47 | - * |
|
48 | - * @return array |
|
49 | - */ |
|
50 | - public function register() |
|
51 | - { |
|
52 | - return array(T_OPEN_TAG); |
|
53 | - |
|
54 | - }//end register() |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * Processes this test, when one of its tokens is encountered. |
|
59 | - * |
|
60 | - * @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document. |
|
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(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
67 | - { |
|
68 | - $tokens = $phpcsFile->getTokens(); |
|
69 | - $error = 'Spaces must be used to indent lines; tabs are not allowed'; |
|
70 | - $errorCode = 'TabsUsed'; |
|
71 | - |
|
72 | - $checkTokens = array( |
|
73 | - T_WHITESPACE => true, |
|
74 | - T_INLINE_HTML => true, |
|
75 | - T_DOC_COMMENT_WHITESPACE => true, |
|
76 | - T_DOC_COMMENT_STRING => true, |
|
77 | - ); |
|
78 | - |
|
79 | - for ($i = ($stackPtr + 1); $i < $phpcsFile->numTokens; $i++) { |
|
80 | - if (isset($checkTokens[$tokens[$i]['code']]) === false) { |
|
81 | - continue; |
|
82 | - } |
|
83 | - |
|
84 | - // If tabs are being converted to spaces by PHPCS, the |
|
85 | - // original content should be checked instead of the converted content. |
|
86 | - if (isset($tokens[$i]['orig_content']) === true) { |
|
87 | - $content = $tokens[$i]['orig_content']; |
|
88 | - } else { |
|
89 | - $content = $tokens[$i]['content']; |
|
90 | - } |
|
91 | - |
|
92 | - if ($content === '') { |
|
93 | - continue; |
|
94 | - } |
|
95 | - |
|
96 | - if ($tokens[$i]['code'] === T_DOC_COMMENT_WHITESPACE && $content === ' ') { |
|
97 | - // Ignore file/class-level DocBlock, especially for recording metrics. |
|
98 | - continue; |
|
99 | - } |
|
100 | - |
|
101 | - $tabFound = false; |
|
102 | - if ($tokens[$i]['column'] === 1) { |
|
103 | - if ($content[0] === "\t") { |
|
104 | - $phpcsFile->recordMetric($i, 'Line indent', 'tabs'); |
|
105 | - $tabFound = true; |
|
106 | - } else if ($content[0] === ' ') { |
|
107 | - if (strpos($content, "\t") !== false) { |
|
108 | - $phpcsFile->recordMetric($i, 'Line indent', 'mixed'); |
|
109 | - $tabFound = true; |
|
110 | - } else { |
|
111 | - $phpcsFile->recordMetric($i, 'Line indent', 'spaces'); |
|
112 | - } |
|
113 | - } |
|
114 | - } else { |
|
115 | - // Look for tabs so we can report and replace, but don't |
|
116 | - // record any metrics about them because they aren't |
|
117 | - // line indent tokens. |
|
118 | - if (strpos($content, "\t") !== false) { |
|
119 | - $tabFound = true; |
|
120 | - $error = 'Spaces must be used for alignment; tabs are not allowed'; |
|
121 | - $errorCode = 'NonIndentTabsUsed'; |
|
122 | - } |
|
123 | - }//end if |
|
124 | - |
|
125 | - if ($tabFound === false) { |
|
126 | - continue; |
|
127 | - } |
|
128 | - |
|
129 | - $fix = $phpcsFile->addFixableError($error, $i, $errorCode); |
|
130 | - if ($fix === true) { |
|
131 | - if (isset($tokens[$i]['orig_content']) === true) { |
|
132 | - // Use the replacement that PHPCS has already done. |
|
133 | - $phpcsFile->fixer->replaceToken($i, $tokens[$i]['content']); |
|
134 | - } else { |
|
135 | - // Replace tabs with spaces, using an indent of 4 spaces. |
|
136 | - // Other sniffs can then correct the indent if they need to. |
|
137 | - $newContent = str_replace("\t", ' ', $tokens[$i]['content']); |
|
138 | - $phpcsFile->fixer->replaceToken($i, $newContent); |
|
139 | - } |
|
140 | - } |
|
141 | - }//end for |
|
142 | - |
|
143 | - // Ignore the rest of the file. |
|
144 | - return ($phpcsFile->numTokens + 1); |
|
145 | - |
|
146 | - }//end process() |
|
33 | + /** |
|
34 | + * A list of tokenizers this sniff supports. |
|
35 | + * |
|
36 | + * @var array |
|
37 | + */ |
|
38 | + public $supportedTokenizers = array( |
|
39 | + 'PHP', |
|
40 | + 'JS', |
|
41 | + 'CSS', |
|
42 | + ); |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * Returns an array of tokens this test wants to listen for. |
|
47 | + * |
|
48 | + * @return array |
|
49 | + */ |
|
50 | + public function register() |
|
51 | + { |
|
52 | + return array(T_OPEN_TAG); |
|
53 | + |
|
54 | + }//end register() |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * Processes this test, when one of its tokens is encountered. |
|
59 | + * |
|
60 | + * @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document. |
|
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(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
67 | + { |
|
68 | + $tokens = $phpcsFile->getTokens(); |
|
69 | + $error = 'Spaces must be used to indent lines; tabs are not allowed'; |
|
70 | + $errorCode = 'TabsUsed'; |
|
71 | + |
|
72 | + $checkTokens = array( |
|
73 | + T_WHITESPACE => true, |
|
74 | + T_INLINE_HTML => true, |
|
75 | + T_DOC_COMMENT_WHITESPACE => true, |
|
76 | + T_DOC_COMMENT_STRING => true, |
|
77 | + ); |
|
78 | + |
|
79 | + for ($i = ($stackPtr + 1); $i < $phpcsFile->numTokens; $i++) { |
|
80 | + if (isset($checkTokens[$tokens[$i]['code']]) === false) { |
|
81 | + continue; |
|
82 | + } |
|
83 | + |
|
84 | + // If tabs are being converted to spaces by PHPCS, the |
|
85 | + // original content should be checked instead of the converted content. |
|
86 | + if (isset($tokens[$i]['orig_content']) === true) { |
|
87 | + $content = $tokens[$i]['orig_content']; |
|
88 | + } else { |
|
89 | + $content = $tokens[$i]['content']; |
|
90 | + } |
|
91 | + |
|
92 | + if ($content === '') { |
|
93 | + continue; |
|
94 | + } |
|
95 | + |
|
96 | + if ($tokens[$i]['code'] === T_DOC_COMMENT_WHITESPACE && $content === ' ') { |
|
97 | + // Ignore file/class-level DocBlock, especially for recording metrics. |
|
98 | + continue; |
|
99 | + } |
|
100 | + |
|
101 | + $tabFound = false; |
|
102 | + if ($tokens[$i]['column'] === 1) { |
|
103 | + if ($content[0] === "\t") { |
|
104 | + $phpcsFile->recordMetric($i, 'Line indent', 'tabs'); |
|
105 | + $tabFound = true; |
|
106 | + } else if ($content[0] === ' ') { |
|
107 | + if (strpos($content, "\t") !== false) { |
|
108 | + $phpcsFile->recordMetric($i, 'Line indent', 'mixed'); |
|
109 | + $tabFound = true; |
|
110 | + } else { |
|
111 | + $phpcsFile->recordMetric($i, 'Line indent', 'spaces'); |
|
112 | + } |
|
113 | + } |
|
114 | + } else { |
|
115 | + // Look for tabs so we can report and replace, but don't |
|
116 | + // record any metrics about them because they aren't |
|
117 | + // line indent tokens. |
|
118 | + if (strpos($content, "\t") !== false) { |
|
119 | + $tabFound = true; |
|
120 | + $error = 'Spaces must be used for alignment; tabs are not allowed'; |
|
121 | + $errorCode = 'NonIndentTabsUsed'; |
|
122 | + } |
|
123 | + }//end if |
|
124 | + |
|
125 | + if ($tabFound === false) { |
|
126 | + continue; |
|
127 | + } |
|
128 | + |
|
129 | + $fix = $phpcsFile->addFixableError($error, $i, $errorCode); |
|
130 | + if ($fix === true) { |
|
131 | + if (isset($tokens[$i]['orig_content']) === true) { |
|
132 | + // Use the replacement that PHPCS has already done. |
|
133 | + $phpcsFile->fixer->replaceToken($i, $tokens[$i]['content']); |
|
134 | + } else { |
|
135 | + // Replace tabs with spaces, using an indent of 4 spaces. |
|
136 | + // Other sniffs can then correct the indent if they need to. |
|
137 | + $newContent = str_replace("\t", ' ', $tokens[$i]['content']); |
|
138 | + $phpcsFile->fixer->replaceToken($i, $newContent); |
|
139 | + } |
|
140 | + } |
|
141 | + }//end for |
|
142 | + |
|
143 | + // Ignore the rest of the file. |
|
144 | + return ($phpcsFile->numTokens + 1); |
|
145 | + |
|
146 | + }//end process() |
|
147 | 147 | |
148 | 148 | |
149 | 149 | }//end class |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public function register() |
51 | 51 | { |
52 | - return array(T_OPEN_TAG); |
|
52 | + return array( T_OPEN_TAG ); |
|
53 | 53 | |
54 | 54 | }//end register() |
55 | 55 | |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | * |
64 | 64 | * @return void |
65 | 65 | */ |
66 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
66 | + public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) |
|
67 | 67 | { |
68 | 68 | $tokens = $phpcsFile->getTokens(); |
69 | 69 | $error = 'Spaces must be used to indent lines; tabs are not allowed'; |
@@ -76,72 +76,72 @@ discard block |
||
76 | 76 | T_DOC_COMMENT_STRING => true, |
77 | 77 | ); |
78 | 78 | |
79 | - for ($i = ($stackPtr + 1); $i < $phpcsFile->numTokens; $i++) { |
|
80 | - if (isset($checkTokens[$tokens[$i]['code']]) === false) { |
|
79 | + for ( $i = ( $stackPtr + 1 ); $i < $phpcsFile->numTokens; $i++ ) { |
|
80 | + if ( isset( $checkTokens[ $tokens[ $i ][ 'code' ] ] ) === false ) { |
|
81 | 81 | continue; |
82 | 82 | } |
83 | 83 | |
84 | 84 | // If tabs are being converted to spaces by PHPCS, the |
85 | 85 | // original content should be checked instead of the converted content. |
86 | - if (isset($tokens[$i]['orig_content']) === true) { |
|
87 | - $content = $tokens[$i]['orig_content']; |
|
86 | + if ( isset( $tokens[ $i ][ 'orig_content' ] ) === true ) { |
|
87 | + $content = $tokens[ $i ][ 'orig_content' ]; |
|
88 | 88 | } else { |
89 | - $content = $tokens[$i]['content']; |
|
89 | + $content = $tokens[ $i ][ 'content' ]; |
|
90 | 90 | } |
91 | 91 | |
92 | - if ($content === '') { |
|
92 | + if ( $content === '' ) { |
|
93 | 93 | continue; |
94 | 94 | } |
95 | 95 | |
96 | - if ($tokens[$i]['code'] === T_DOC_COMMENT_WHITESPACE && $content === ' ') { |
|
96 | + if ( $tokens[ $i ][ 'code' ] === T_DOC_COMMENT_WHITESPACE && $content === ' ' ) { |
|
97 | 97 | // Ignore file/class-level DocBlock, especially for recording metrics. |
98 | 98 | continue; |
99 | 99 | } |
100 | 100 | |
101 | 101 | $tabFound = false; |
102 | - if ($tokens[$i]['column'] === 1) { |
|
103 | - if ($content[0] === "\t") { |
|
104 | - $phpcsFile->recordMetric($i, 'Line indent', 'tabs'); |
|
102 | + if ( $tokens[ $i ][ 'column' ] === 1 ) { |
|
103 | + if ( $content[ 0 ] === "\t" ) { |
|
104 | + $phpcsFile->recordMetric( $i, 'Line indent', 'tabs' ); |
|
105 | 105 | $tabFound = true; |
106 | - } else if ($content[0] === ' ') { |
|
107 | - if (strpos($content, "\t") !== false) { |
|
108 | - $phpcsFile->recordMetric($i, 'Line indent', 'mixed'); |
|
106 | + } else if ( $content[ 0 ] === ' ' ) { |
|
107 | + if ( strpos( $content, "\t" ) !== false ) { |
|
108 | + $phpcsFile->recordMetric( $i, 'Line indent', 'mixed' ); |
|
109 | 109 | $tabFound = true; |
110 | 110 | } else { |
111 | - $phpcsFile->recordMetric($i, 'Line indent', 'spaces'); |
|
111 | + $phpcsFile->recordMetric( $i, 'Line indent', 'spaces' ); |
|
112 | 112 | } |
113 | 113 | } |
114 | 114 | } else { |
115 | 115 | // Look for tabs so we can report and replace, but don't |
116 | 116 | // record any metrics about them because they aren't |
117 | 117 | // line indent tokens. |
118 | - if (strpos($content, "\t") !== false) { |
|
118 | + if ( strpos( $content, "\t" ) !== false ) { |
|
119 | 119 | $tabFound = true; |
120 | 120 | $error = 'Spaces must be used for alignment; tabs are not allowed'; |
121 | 121 | $errorCode = 'NonIndentTabsUsed'; |
122 | 122 | } |
123 | 123 | }//end if |
124 | 124 | |
125 | - if ($tabFound === false) { |
|
125 | + if ( $tabFound === false ) { |
|
126 | 126 | continue; |
127 | 127 | } |
128 | 128 | |
129 | - $fix = $phpcsFile->addFixableError($error, $i, $errorCode); |
|
130 | - if ($fix === true) { |
|
131 | - if (isset($tokens[$i]['orig_content']) === true) { |
|
129 | + $fix = $phpcsFile->addFixableError( $error, $i, $errorCode ); |
|
130 | + if ( $fix === true ) { |
|
131 | + if ( isset( $tokens[ $i ][ 'orig_content' ] ) === true ) { |
|
132 | 132 | // Use the replacement that PHPCS has already done. |
133 | - $phpcsFile->fixer->replaceToken($i, $tokens[$i]['content']); |
|
133 | + $phpcsFile->fixer->replaceToken( $i, $tokens[ $i ][ 'content' ] ); |
|
134 | 134 | } else { |
135 | 135 | // Replace tabs with spaces, using an indent of 4 spaces. |
136 | 136 | // Other sniffs can then correct the indent if they need to. |
137 | - $newContent = str_replace("\t", ' ', $tokens[$i]['content']); |
|
138 | - $phpcsFile->fixer->replaceToken($i, $newContent); |
|
137 | + $newContent = str_replace( "\t", ' ', $tokens[ $i ][ 'content' ] ); |
|
138 | + $phpcsFile->fixer->replaceToken( $i, $newContent ); |
|
139 | 139 | } |
140 | 140 | } |
141 | 141 | }//end for |
142 | 142 | |
143 | 143 | // Ignore the rest of the file. |
144 | - return ($phpcsFile->numTokens + 1); |
|
144 | + return ( $phpcsFile->numTokens + 1 ); |
|
145 | 145 | |
146 | 146 | }//end process() |
147 | 147 |
@@ -27,8 +27,7 @@ discard block |
||
27 | 27 | * @version Release: @package_version@ |
28 | 28 | * @link http://pear.php.net/package/PHP_CodeSniffer |
29 | 29 | */ |
30 | -class Generic_Sniffs_WhiteSpace_DisallowTabIndentSniff implements PHP_CodeSniffer_Sniff |
|
31 | -{ |
|
30 | +class Generic_Sniffs_WhiteSpace_DisallowTabIndentSniff implements PHP_CodeSniffer_Sniff { |
|
32 | 31 | |
33 | 32 | /** |
34 | 33 | * A list of tokenizers this sniff supports. |
@@ -47,8 +46,7 @@ discard block |
||
47 | 46 | * |
48 | 47 | * @return array |
49 | 48 | */ |
50 | - public function register() |
|
51 | - { |
|
49 | + public function register() { |
|
52 | 50 | return array(T_OPEN_TAG); |
53 | 51 | |
54 | 52 | }//end register() |
@@ -63,8 +61,7 @@ discard block |
||
63 | 61 | * |
64 | 62 | * @return void |
65 | 63 | */ |
66 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
67 | - { |
|
64 | + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { |
|
68 | 65 | $tokens = $phpcsFile->getTokens(); |
69 | 66 | $error = 'Spaces must be used to indent lines; tabs are not allowed'; |
70 | 67 | $errorCode = 'TabsUsed'; |
@@ -31,144 +31,144 @@ |
||
31 | 31 | { |
32 | 32 | |
33 | 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_STRING); |
|
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 in the |
|
51 | - * stack passed in $tokens. |
|
52 | - * |
|
53 | - * @return void |
|
54 | - */ |
|
55 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
56 | - { |
|
57 | - $tokens = $phpcsFile->getTokens(); |
|
58 | - |
|
59 | - // Skip tokens that are the names of functions or classes |
|
60 | - // within their definitions. For example: |
|
61 | - // function myFunction... |
|
62 | - // "myFunction" is T_STRING but we should skip because it is not a |
|
63 | - // function or method *call*. |
|
64 | - $functionName = $stackPtr; |
|
65 | - $ignoreTokens = PHP_CodeSniffer_Tokens::$emptyTokens; |
|
66 | - $ignoreTokens[] = T_BITWISE_AND; |
|
67 | - $functionKeyword = $phpcsFile->findPrevious($ignoreTokens, ($stackPtr - 1), null, true); |
|
68 | - if ($tokens[$functionKeyword]['code'] === T_FUNCTION || $tokens[$functionKeyword]['code'] === T_CLASS) { |
|
69 | - return; |
|
70 | - } |
|
71 | - |
|
72 | - // If the next non-whitespace token after the function or method call |
|
73 | - // is not an opening parenthesis then it cant really be a *call*. |
|
74 | - $openBracket = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($functionName + 1), null, true); |
|
75 | - if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) { |
|
76 | - return; |
|
77 | - } |
|
78 | - |
|
79 | - if (isset($tokens[$openBracket]['parenthesis_closer']) === false) { |
|
80 | - return; |
|
81 | - } |
|
82 | - |
|
83 | - $closeBracket = $tokens[$openBracket]['parenthesis_closer']; |
|
84 | - $nextSeparator = $openBracket; |
|
85 | - |
|
86 | - $find = array( |
|
87 | - T_COMMA, |
|
88 | - T_VARIABLE, |
|
89 | - T_CLOSURE, |
|
90 | - T_OPEN_SHORT_ARRAY, |
|
91 | - ); |
|
92 | - |
|
93 | - while (($nextSeparator = $phpcsFile->findNext($find, ($nextSeparator + 1), $closeBracket)) !== false) { |
|
94 | - if ($tokens[$nextSeparator]['code'] === T_CLOSURE) { |
|
95 | - // Skip closures. |
|
96 | - $nextSeparator = $tokens[$nextSeparator]['scope_closer']; |
|
97 | - continue; |
|
98 | - } else if ($tokens[$nextSeparator]['code'] === T_OPEN_SHORT_ARRAY) { |
|
99 | - // Skips arrays using short notation. |
|
100 | - $nextSeparator = $tokens[$nextSeparator]['bracket_closer']; |
|
101 | - continue; |
|
102 | - } |
|
103 | - |
|
104 | - // Make sure the comma or variable belongs directly to this function call, |
|
105 | - // and is not inside a nested function call or array. |
|
106 | - $brackets = $tokens[$nextSeparator]['nested_parenthesis']; |
|
107 | - $lastBracket = array_pop($brackets); |
|
108 | - if ($lastBracket !== $closeBracket) { |
|
109 | - continue; |
|
110 | - } |
|
111 | - |
|
112 | - if ($tokens[$nextSeparator]['code'] === T_COMMA) { |
|
113 | - if ($tokens[($nextSeparator - 1)]['code'] === T_WHITESPACE) { |
|
114 | - $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($nextSeparator - 2), null, true); |
|
115 | - if (isset(PHP_CodeSniffer_Tokens::$heredocTokens[$tokens[$prev]['code']]) === false) { |
|
116 | - $error = 'Space found before comma in function call'; |
|
117 | - $fix = $phpcsFile->addFixableError($error, $nextSeparator, 'SpaceBeforeComma'); |
|
118 | - if ($fix === true) { |
|
119 | - $phpcsFile->fixer->replaceToken(($nextSeparator - 1), ''); |
|
120 | - } |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - if ($tokens[($nextSeparator + 1)]['code'] !== T_WHITESPACE) { |
|
125 | - $error = 'No space found after comma in function call'; |
|
126 | - $fix = $phpcsFile->addFixableError($error, $nextSeparator, 'NoSpaceAfterComma'); |
|
127 | - if ($fix === true) { |
|
128 | - $phpcsFile->fixer->addContent($nextSeparator, ' '); |
|
129 | - } |
|
130 | - } else { |
|
131 | - // If there is a newline in the space, then they must be formatting |
|
132 | - // each argument on a newline, which is valid, so ignore it. |
|
133 | - $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($nextSeparator + 1), null, true); |
|
134 | - if ($tokens[$next]['line'] === $tokens[$nextSeparator]['line']) { |
|
135 | - $space = strlen($tokens[($nextSeparator + 1)]['content']); |
|
136 | - if ($space > 1) { |
|
137 | - $error = 'Expected 1 space after comma in function call; %s found'; |
|
138 | - $data = array($space); |
|
139 | - $fix = $phpcsFile->addFixableError($error, $nextSeparator, 'TooMuchSpaceAfterComma', $data); |
|
140 | - if ($fix === true) { |
|
141 | - $phpcsFile->fixer->replaceToken(($nextSeparator + 1), ' '); |
|
142 | - } |
|
143 | - } |
|
144 | - } |
|
145 | - }//end if |
|
146 | - } else { |
|
147 | - // Token is a variable. |
|
148 | - $nextToken = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($nextSeparator + 1), $closeBracket, true); |
|
149 | - if ($nextToken !== false) { |
|
150 | - if ($tokens[$nextToken]['code'] === T_EQUAL) { |
|
151 | - if (($tokens[($nextToken - 1)]['code']) !== T_WHITESPACE) { |
|
152 | - $error = 'Expected 1 space before = sign of default value'; |
|
153 | - $fix = $phpcsFile->addFixableError($error, $nextToken, 'NoSpaceBeforeEquals'); |
|
154 | - if ($fix === true) { |
|
155 | - $phpcsFile->fixer->addContentBefore($nextToken, ' '); |
|
156 | - } |
|
157 | - } |
|
158 | - |
|
159 | - if ($tokens[($nextToken + 1)]['code'] !== T_WHITESPACE) { |
|
160 | - $error = 'Expected 1 space after = sign of default value'; |
|
161 | - $fix = $phpcsFile->addFixableError($error, $nextToken, 'NoSpaceAfterEquals'); |
|
162 | - if ($fix === true) { |
|
163 | - $phpcsFile->fixer->addContent($nextToken, ' '); |
|
164 | - } |
|
165 | - } |
|
166 | - } |
|
167 | - } |
|
168 | - }//end if |
|
169 | - }//end while |
|
170 | - |
|
171 | - }//end process() |
|
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_STRING); |
|
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 in the |
|
51 | + * stack passed in $tokens. |
|
52 | + * |
|
53 | + * @return void |
|
54 | + */ |
|
55 | + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
56 | + { |
|
57 | + $tokens = $phpcsFile->getTokens(); |
|
58 | + |
|
59 | + // Skip tokens that are the names of functions or classes |
|
60 | + // within their definitions. For example: |
|
61 | + // function myFunction... |
|
62 | + // "myFunction" is T_STRING but we should skip because it is not a |
|
63 | + // function or method *call*. |
|
64 | + $functionName = $stackPtr; |
|
65 | + $ignoreTokens = PHP_CodeSniffer_Tokens::$emptyTokens; |
|
66 | + $ignoreTokens[] = T_BITWISE_AND; |
|
67 | + $functionKeyword = $phpcsFile->findPrevious($ignoreTokens, ($stackPtr - 1), null, true); |
|
68 | + if ($tokens[$functionKeyword]['code'] === T_FUNCTION || $tokens[$functionKeyword]['code'] === T_CLASS) { |
|
69 | + return; |
|
70 | + } |
|
71 | + |
|
72 | + // If the next non-whitespace token after the function or method call |
|
73 | + // is not an opening parenthesis then it cant really be a *call*. |
|
74 | + $openBracket = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($functionName + 1), null, true); |
|
75 | + if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) { |
|
76 | + return; |
|
77 | + } |
|
78 | + |
|
79 | + if (isset($tokens[$openBracket]['parenthesis_closer']) === false) { |
|
80 | + return; |
|
81 | + } |
|
82 | + |
|
83 | + $closeBracket = $tokens[$openBracket]['parenthesis_closer']; |
|
84 | + $nextSeparator = $openBracket; |
|
85 | + |
|
86 | + $find = array( |
|
87 | + T_COMMA, |
|
88 | + T_VARIABLE, |
|
89 | + T_CLOSURE, |
|
90 | + T_OPEN_SHORT_ARRAY, |
|
91 | + ); |
|
92 | + |
|
93 | + while (($nextSeparator = $phpcsFile->findNext($find, ($nextSeparator + 1), $closeBracket)) !== false) { |
|
94 | + if ($tokens[$nextSeparator]['code'] === T_CLOSURE) { |
|
95 | + // Skip closures. |
|
96 | + $nextSeparator = $tokens[$nextSeparator]['scope_closer']; |
|
97 | + continue; |
|
98 | + } else if ($tokens[$nextSeparator]['code'] === T_OPEN_SHORT_ARRAY) { |
|
99 | + // Skips arrays using short notation. |
|
100 | + $nextSeparator = $tokens[$nextSeparator]['bracket_closer']; |
|
101 | + continue; |
|
102 | + } |
|
103 | + |
|
104 | + // Make sure the comma or variable belongs directly to this function call, |
|
105 | + // and is not inside a nested function call or array. |
|
106 | + $brackets = $tokens[$nextSeparator]['nested_parenthesis']; |
|
107 | + $lastBracket = array_pop($brackets); |
|
108 | + if ($lastBracket !== $closeBracket) { |
|
109 | + continue; |
|
110 | + } |
|
111 | + |
|
112 | + if ($tokens[$nextSeparator]['code'] === T_COMMA) { |
|
113 | + if ($tokens[($nextSeparator - 1)]['code'] === T_WHITESPACE) { |
|
114 | + $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($nextSeparator - 2), null, true); |
|
115 | + if (isset(PHP_CodeSniffer_Tokens::$heredocTokens[$tokens[$prev]['code']]) === false) { |
|
116 | + $error = 'Space found before comma in function call'; |
|
117 | + $fix = $phpcsFile->addFixableError($error, $nextSeparator, 'SpaceBeforeComma'); |
|
118 | + if ($fix === true) { |
|
119 | + $phpcsFile->fixer->replaceToken(($nextSeparator - 1), ''); |
|
120 | + } |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + if ($tokens[($nextSeparator + 1)]['code'] !== T_WHITESPACE) { |
|
125 | + $error = 'No space found after comma in function call'; |
|
126 | + $fix = $phpcsFile->addFixableError($error, $nextSeparator, 'NoSpaceAfterComma'); |
|
127 | + if ($fix === true) { |
|
128 | + $phpcsFile->fixer->addContent($nextSeparator, ' '); |
|
129 | + } |
|
130 | + } else { |
|
131 | + // If there is a newline in the space, then they must be formatting |
|
132 | + // each argument on a newline, which is valid, so ignore it. |
|
133 | + $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($nextSeparator + 1), null, true); |
|
134 | + if ($tokens[$next]['line'] === $tokens[$nextSeparator]['line']) { |
|
135 | + $space = strlen($tokens[($nextSeparator + 1)]['content']); |
|
136 | + if ($space > 1) { |
|
137 | + $error = 'Expected 1 space after comma in function call; %s found'; |
|
138 | + $data = array($space); |
|
139 | + $fix = $phpcsFile->addFixableError($error, $nextSeparator, 'TooMuchSpaceAfterComma', $data); |
|
140 | + if ($fix === true) { |
|
141 | + $phpcsFile->fixer->replaceToken(($nextSeparator + 1), ' '); |
|
142 | + } |
|
143 | + } |
|
144 | + } |
|
145 | + }//end if |
|
146 | + } else { |
|
147 | + // Token is a variable. |
|
148 | + $nextToken = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($nextSeparator + 1), $closeBracket, true); |
|
149 | + if ($nextToken !== false) { |
|
150 | + if ($tokens[$nextToken]['code'] === T_EQUAL) { |
|
151 | + if (($tokens[($nextToken - 1)]['code']) !== T_WHITESPACE) { |
|
152 | + $error = 'Expected 1 space before = sign of default value'; |
|
153 | + $fix = $phpcsFile->addFixableError($error, $nextToken, 'NoSpaceBeforeEquals'); |
|
154 | + if ($fix === true) { |
|
155 | + $phpcsFile->fixer->addContentBefore($nextToken, ' '); |
|
156 | + } |
|
157 | + } |
|
158 | + |
|
159 | + if ($tokens[($nextToken + 1)]['code'] !== T_WHITESPACE) { |
|
160 | + $error = 'Expected 1 space after = sign of default value'; |
|
161 | + $fix = $phpcsFile->addFixableError($error, $nextToken, 'NoSpaceAfterEquals'); |
|
162 | + if ($fix === true) { |
|
163 | + $phpcsFile->fixer->addContent($nextToken, ' '); |
|
164 | + } |
|
165 | + } |
|
166 | + } |
|
167 | + } |
|
168 | + }//end if |
|
169 | + }//end while |
|
170 | + |
|
171 | + }//end process() |
|
172 | 172 | |
173 | 173 | |
174 | 174 | }//end class |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function register() |
40 | 40 | { |
41 | - return array(T_STRING); |
|
41 | + return array( T_STRING ); |
|
42 | 42 | |
43 | 43 | }//end register() |
44 | 44 | |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @return void |
54 | 54 | */ |
55 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
55 | + public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) |
|
56 | 56 | { |
57 | 57 | $tokens = $phpcsFile->getTokens(); |
58 | 58 | |
@@ -63,24 +63,24 @@ discard block |
||
63 | 63 | // function or method *call*. |
64 | 64 | $functionName = $stackPtr; |
65 | 65 | $ignoreTokens = PHP_CodeSniffer_Tokens::$emptyTokens; |
66 | - $ignoreTokens[] = T_BITWISE_AND; |
|
67 | - $functionKeyword = $phpcsFile->findPrevious($ignoreTokens, ($stackPtr - 1), null, true); |
|
68 | - if ($tokens[$functionKeyword]['code'] === T_FUNCTION || $tokens[$functionKeyword]['code'] === T_CLASS) { |
|
66 | + $ignoreTokens[ ] = T_BITWISE_AND; |
|
67 | + $functionKeyword = $phpcsFile->findPrevious( $ignoreTokens, ( $stackPtr - 1 ), null, true ); |
|
68 | + if ( $tokens[ $functionKeyword ][ 'code' ] === T_FUNCTION || $tokens[ $functionKeyword ][ 'code' ] === T_CLASS ) { |
|
69 | 69 | return; |
70 | 70 | } |
71 | 71 | |
72 | 72 | // If the next non-whitespace token after the function or method call |
73 | 73 | // is not an opening parenthesis then it cant really be a *call*. |
74 | - $openBracket = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($functionName + 1), null, true); |
|
75 | - if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) { |
|
74 | + $openBracket = $phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ( $functionName + 1 ), null, true ); |
|
75 | + if ( $tokens[ $openBracket ][ 'code' ] !== T_OPEN_PARENTHESIS ) { |
|
76 | 76 | return; |
77 | 77 | } |
78 | 78 | |
79 | - if (isset($tokens[$openBracket]['parenthesis_closer']) === false) { |
|
79 | + if ( isset( $tokens[ $openBracket ][ 'parenthesis_closer' ] ) === false ) { |
|
80 | 80 | return; |
81 | 81 | } |
82 | 82 | |
83 | - $closeBracket = $tokens[$openBracket]['parenthesis_closer']; |
|
83 | + $closeBracket = $tokens[ $openBracket ][ 'parenthesis_closer' ]; |
|
84 | 84 | $nextSeparator = $openBracket; |
85 | 85 | |
86 | 86 | $find = array( |
@@ -90,77 +90,77 @@ discard block |
||
90 | 90 | T_OPEN_SHORT_ARRAY, |
91 | 91 | ); |
92 | 92 | |
93 | - while (($nextSeparator = $phpcsFile->findNext($find, ($nextSeparator + 1), $closeBracket)) !== false) { |
|
94 | - if ($tokens[$nextSeparator]['code'] === T_CLOSURE) { |
|
93 | + while ( ( $nextSeparator = $phpcsFile->findNext( $find, ( $nextSeparator + 1 ), $closeBracket ) ) !== false ) { |
|
94 | + if ( $tokens[ $nextSeparator ][ 'code' ] === T_CLOSURE ) { |
|
95 | 95 | // Skip closures. |
96 | - $nextSeparator = $tokens[$nextSeparator]['scope_closer']; |
|
96 | + $nextSeparator = $tokens[ $nextSeparator ][ 'scope_closer' ]; |
|
97 | 97 | continue; |
98 | - } else if ($tokens[$nextSeparator]['code'] === T_OPEN_SHORT_ARRAY) { |
|
98 | + } else if ( $tokens[ $nextSeparator ][ 'code' ] === T_OPEN_SHORT_ARRAY ) { |
|
99 | 99 | // Skips arrays using short notation. |
100 | - $nextSeparator = $tokens[$nextSeparator]['bracket_closer']; |
|
100 | + $nextSeparator = $tokens[ $nextSeparator ][ 'bracket_closer' ]; |
|
101 | 101 | continue; |
102 | 102 | } |
103 | 103 | |
104 | 104 | // Make sure the comma or variable belongs directly to this function call, |
105 | 105 | // and is not inside a nested function call or array. |
106 | - $brackets = $tokens[$nextSeparator]['nested_parenthesis']; |
|
107 | - $lastBracket = array_pop($brackets); |
|
108 | - if ($lastBracket !== $closeBracket) { |
|
106 | + $brackets = $tokens[ $nextSeparator ][ 'nested_parenthesis' ]; |
|
107 | + $lastBracket = array_pop( $brackets ); |
|
108 | + if ( $lastBracket !== $closeBracket ) { |
|
109 | 109 | continue; |
110 | 110 | } |
111 | 111 | |
112 | - if ($tokens[$nextSeparator]['code'] === T_COMMA) { |
|
113 | - if ($tokens[($nextSeparator - 1)]['code'] === T_WHITESPACE) { |
|
114 | - $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($nextSeparator - 2), null, true); |
|
115 | - if (isset(PHP_CodeSniffer_Tokens::$heredocTokens[$tokens[$prev]['code']]) === false) { |
|
112 | + if ( $tokens[ $nextSeparator ][ 'code' ] === T_COMMA ) { |
|
113 | + if ( $tokens[ ( $nextSeparator - 1 ) ][ 'code' ] === T_WHITESPACE ) { |
|
114 | + $prev = $phpcsFile->findPrevious( PHP_CodeSniffer_Tokens::$emptyTokens, ( $nextSeparator - 2 ), null, true ); |
|
115 | + if ( isset( PHP_CodeSniffer_Tokens::$heredocTokens[ $tokens[ $prev ][ 'code' ] ] ) === false ) { |
|
116 | 116 | $error = 'Space found before comma in function call'; |
117 | - $fix = $phpcsFile->addFixableError($error, $nextSeparator, 'SpaceBeforeComma'); |
|
118 | - if ($fix === true) { |
|
119 | - $phpcsFile->fixer->replaceToken(($nextSeparator - 1), ''); |
|
117 | + $fix = $phpcsFile->addFixableError( $error, $nextSeparator, 'SpaceBeforeComma' ); |
|
118 | + if ( $fix === true ) { |
|
119 | + $phpcsFile->fixer->replaceToken( ( $nextSeparator - 1 ), '' ); |
|
120 | 120 | } |
121 | 121 | } |
122 | 122 | } |
123 | 123 | |
124 | - if ($tokens[($nextSeparator + 1)]['code'] !== T_WHITESPACE) { |
|
124 | + if ( $tokens[ ( $nextSeparator + 1 ) ][ 'code' ] !== T_WHITESPACE ) { |
|
125 | 125 | $error = 'No space found after comma in function call'; |
126 | - $fix = $phpcsFile->addFixableError($error, $nextSeparator, 'NoSpaceAfterComma'); |
|
127 | - if ($fix === true) { |
|
128 | - $phpcsFile->fixer->addContent($nextSeparator, ' '); |
|
126 | + $fix = $phpcsFile->addFixableError( $error, $nextSeparator, 'NoSpaceAfterComma' ); |
|
127 | + if ( $fix === true ) { |
|
128 | + $phpcsFile->fixer->addContent( $nextSeparator, ' ' ); |
|
129 | 129 | } |
130 | 130 | } else { |
131 | 131 | // If there is a newline in the space, then they must be formatting |
132 | 132 | // each argument on a newline, which is valid, so ignore it. |
133 | - $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($nextSeparator + 1), null, true); |
|
134 | - if ($tokens[$next]['line'] === $tokens[$nextSeparator]['line']) { |
|
135 | - $space = strlen($tokens[($nextSeparator + 1)]['content']); |
|
136 | - if ($space > 1) { |
|
133 | + $next = $phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ( $nextSeparator + 1 ), null, true ); |
|
134 | + if ( $tokens[ $next ][ 'line' ] === $tokens[ $nextSeparator ][ 'line' ] ) { |
|
135 | + $space = strlen( $tokens[ ( $nextSeparator + 1 ) ][ 'content' ] ); |
|
136 | + if ( $space > 1 ) { |
|
137 | 137 | $error = 'Expected 1 space after comma in function call; %s found'; |
138 | - $data = array($space); |
|
139 | - $fix = $phpcsFile->addFixableError($error, $nextSeparator, 'TooMuchSpaceAfterComma', $data); |
|
140 | - if ($fix === true) { |
|
141 | - $phpcsFile->fixer->replaceToken(($nextSeparator + 1), ' '); |
|
138 | + $data = array( $space ); |
|
139 | + $fix = $phpcsFile->addFixableError( $error, $nextSeparator, 'TooMuchSpaceAfterComma', $data ); |
|
140 | + if ( $fix === true ) { |
|
141 | + $phpcsFile->fixer->replaceToken( ( $nextSeparator + 1 ), ' ' ); |
|
142 | 142 | } |
143 | 143 | } |
144 | 144 | } |
145 | 145 | }//end if |
146 | 146 | } else { |
147 | 147 | // Token is a variable. |
148 | - $nextToken = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($nextSeparator + 1), $closeBracket, true); |
|
149 | - if ($nextToken !== false) { |
|
150 | - if ($tokens[$nextToken]['code'] === T_EQUAL) { |
|
151 | - if (($tokens[($nextToken - 1)]['code']) !== T_WHITESPACE) { |
|
148 | + $nextToken = $phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ( $nextSeparator + 1 ), $closeBracket, true ); |
|
149 | + if ( $nextToken !== false ) { |
|
150 | + if ( $tokens[ $nextToken ][ 'code' ] === T_EQUAL ) { |
|
151 | + if ( ( $tokens[ ( $nextToken - 1 ) ][ 'code' ] ) !== T_WHITESPACE ) { |
|
152 | 152 | $error = 'Expected 1 space before = sign of default value'; |
153 | - $fix = $phpcsFile->addFixableError($error, $nextToken, 'NoSpaceBeforeEquals'); |
|
154 | - if ($fix === true) { |
|
155 | - $phpcsFile->fixer->addContentBefore($nextToken, ' '); |
|
153 | + $fix = $phpcsFile->addFixableError( $error, $nextToken, 'NoSpaceBeforeEquals' ); |
|
154 | + if ( $fix === true ) { |
|
155 | + $phpcsFile->fixer->addContentBefore( $nextToken, ' ' ); |
|
156 | 156 | } |
157 | 157 | } |
158 | 158 | |
159 | - if ($tokens[($nextToken + 1)]['code'] !== T_WHITESPACE) { |
|
159 | + if ( $tokens[ ( $nextToken + 1 ) ][ 'code' ] !== T_WHITESPACE ) { |
|
160 | 160 | $error = 'Expected 1 space after = sign of default value'; |
161 | - $fix = $phpcsFile->addFixableError($error, $nextToken, 'NoSpaceAfterEquals'); |
|
162 | - if ($fix === true) { |
|
163 | - $phpcsFile->fixer->addContent($nextToken, ' '); |
|
161 | + $fix = $phpcsFile->addFixableError( $error, $nextToken, 'NoSpaceAfterEquals' ); |
|
162 | + if ( $fix === true ) { |
|
163 | + $phpcsFile->fixer->addContent( $nextToken, ' ' ); |
|
164 | 164 | } |
165 | 165 | } |
166 | 166 | } |
@@ -27,8 +27,7 @@ discard block |
||
27 | 27 | * @version Release: @package_version@ |
28 | 28 | * @link http://pear.php.net/package/PHP_CodeSniffer |
29 | 29 | */ |
30 | -class Generic_Sniffs_Functions_FunctionCallArgumentSpacingSniff implements PHP_CodeSniffer_Sniff |
|
31 | -{ |
|
30 | +class Generic_Sniffs_Functions_FunctionCallArgumentSpacingSniff implements PHP_CodeSniffer_Sniff { |
|
32 | 31 | |
33 | 32 | |
34 | 33 | /** |
@@ -36,8 +35,7 @@ discard block |
||
36 | 35 | * |
37 | 36 | * @return array |
38 | 37 | */ |
39 | - public function register() |
|
40 | - { |
|
38 | + public function register() { |
|
41 | 39 | return array(T_STRING); |
42 | 40 | |
43 | 41 | }//end register() |
@@ -52,8 +50,7 @@ discard block |
||
52 | 50 | * |
53 | 51 | * @return void |
54 | 52 | */ |
55 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
56 | - { |
|
53 | + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { |
|
57 | 54 | $tokens = $phpcsFile->getTokens(); |
58 | 55 | |
59 | 56 | // Skip tokens that are the names of functions or classes |
@@ -31,161 +31,161 @@ |
||
31 | 31 | class Generic_Sniffs_Functions_OpeningFunctionBraceBsdAllmanSniff implements PHP_CodeSniffer_Sniff |
32 | 32 | { |
33 | 33 | |
34 | - /** |
|
35 | - * Should this sniff check function braces? |
|
36 | - * |
|
37 | - * @var bool |
|
38 | - */ |
|
39 | - public $checkFunctions = true; |
|
40 | - |
|
41 | - /** |
|
42 | - * Should this sniff check closure braces? |
|
43 | - * |
|
44 | - * @var bool |
|
45 | - */ |
|
46 | - public $checkClosures = false; |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * Registers the tokens that this sniff wants to listen for. |
|
51 | - * |
|
52 | - * @return void |
|
53 | - */ |
|
54 | - public function register() |
|
55 | - { |
|
56 | - return array( |
|
57 | - T_FUNCTION, |
|
58 | - T_CLOSURE, |
|
59 | - ); |
|
60 | - |
|
61 | - }//end register() |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * Processes this test, when one of its tokens is encountered. |
|
66 | - * |
|
67 | - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
68 | - * @param int $stackPtr The position of the current token in the |
|
69 | - * stack passed in $tokens. |
|
70 | - * |
|
71 | - * @return void |
|
72 | - */ |
|
73 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
74 | - { |
|
75 | - $tokens = $phpcsFile->getTokens(); |
|
76 | - |
|
77 | - if (isset($tokens[$stackPtr]['scope_opener']) === false) { |
|
78 | - return; |
|
79 | - } |
|
80 | - |
|
81 | - if (($tokens[$stackPtr]['code'] === T_FUNCTION |
|
82 | - && (bool) $this->checkFunctions === false) |
|
83 | - || ($tokens[$stackPtr]['code'] === T_CLOSURE |
|
84 | - && (bool) $this->checkClosures === false) |
|
85 | - ) { |
|
86 | - return; |
|
87 | - } |
|
88 | - |
|
89 | - $openingBrace = $tokens[$stackPtr]['scope_opener']; |
|
90 | - $closeBracket = $tokens[$stackPtr]['parenthesis_closer']; |
|
91 | - if ($tokens[$stackPtr]['code'] === T_CLOSURE) { |
|
92 | - $use = $phpcsFile->findNext(T_USE, ($closeBracket + 1), $tokens[$stackPtr]['scope_opener']); |
|
93 | - if ($use !== false) { |
|
94 | - $openBracket = $phpcsFile->findNext(T_OPEN_PARENTHESIS, ($use + 1)); |
|
95 | - $closeBracket = $tokens[$openBracket]['parenthesis_closer']; |
|
96 | - } |
|
97 | - } |
|
98 | - |
|
99 | - $functionLine = $tokens[$closeBracket]['line']; |
|
100 | - $braceLine = $tokens[$openingBrace]['line']; |
|
101 | - |
|
102 | - $lineDifference = ($braceLine - $functionLine); |
|
103 | - |
|
104 | - if ($lineDifference === 0) { |
|
105 | - $error = 'Opening brace should be on a new line'; |
|
106 | - $fix = $phpcsFile->addFixableError($error, $openingBrace, 'BraceOnSameLine'); |
|
107 | - if ($fix === true) { |
|
108 | - $phpcsFile->fixer->beginChangeset(); |
|
109 | - $indent = $phpcsFile->findFirstOnLine(array(), $openingBrace); |
|
110 | - if ($tokens[$indent]['code'] === T_WHITESPACE) { |
|
111 | - $phpcsFile->fixer->addContentBefore($openingBrace, $tokens[$indent]['content']); |
|
112 | - } |
|
113 | - |
|
114 | - $phpcsFile->fixer->addNewlineBefore($openingBrace); |
|
115 | - $phpcsFile->fixer->endChangeset(); |
|
116 | - } |
|
117 | - |
|
118 | - $phpcsFile->recordMetric($stackPtr, 'Function opening brace placement', 'same line'); |
|
119 | - } else if ($lineDifference > 1) { |
|
120 | - $error = 'Opening brace should be on the line after the declaration; found %s blank line(s)'; |
|
121 | - $data = array(($lineDifference - 1)); |
|
122 | - $fix = $phpcsFile->addFixableError($error, $openingBrace, 'BraceSpacing', $data); |
|
123 | - if ($fix === true) { |
|
124 | - for ($i = ($tokens[$stackPtr]['parenthesis_closer'] + 1); $i < $openingBrace; $i++) { |
|
125 | - if ($tokens[$i]['line'] === $braceLine) { |
|
126 | - $phpcsFile->fixer->addNewLineBefore($i); |
|
127 | - break; |
|
128 | - } |
|
129 | - |
|
130 | - $phpcsFile->fixer->replaceToken($i, ''); |
|
131 | - } |
|
132 | - } |
|
133 | - }//end if |
|
134 | - |
|
135 | - $next = $phpcsFile->findNext(T_WHITESPACE, ($openingBrace + 1), null, true); |
|
136 | - if ($tokens[$next]['line'] === $tokens[$openingBrace]['line']) { |
|
137 | - if ($next === $tokens[$stackPtr]['scope_closer']) { |
|
138 | - // Ignore empty functions. |
|
139 | - return; |
|
140 | - } |
|
141 | - |
|
142 | - $error = 'Opening brace must be the last content on the line'; |
|
143 | - $fix = $phpcsFile->addFixableError($error, $openingBrace, 'ContentAfterBrace'); |
|
144 | - if ($fix === true) { |
|
145 | - $phpcsFile->fixer->addNewline($openingBrace); |
|
146 | - } |
|
147 | - } |
|
148 | - |
|
149 | - // Only continue checking if the opening brace looks good. |
|
150 | - if ($lineDifference !== 1) { |
|
151 | - return; |
|
152 | - } |
|
153 | - |
|
154 | - // We need to actually find the first piece of content on this line, |
|
155 | - // as if this is a method with tokens before it (public, static etc) |
|
156 | - // or an if with an else before it, then we need to start the scope |
|
157 | - // checking from there, rather than the current token. |
|
158 | - $lineStart = $phpcsFile->findFirstOnLine(T_WHITESPACE, $stackPtr, true); |
|
159 | - |
|
160 | - // The opening brace is on the correct line, now it needs to be |
|
161 | - // checked to be correctly indented. |
|
162 | - $startColumn = $tokens[$lineStart]['column']; |
|
163 | - $braceIndent = $tokens[$openingBrace]['column']; |
|
164 | - |
|
165 | - if ($braceIndent !== $startColumn) { |
|
166 | - $expected = ($startColumn - 1); |
|
167 | - $found = ($braceIndent - 1); |
|
168 | - |
|
169 | - $error = 'Opening brace indented incorrectly; expected %s spaces, found %s'; |
|
170 | - $data = array( |
|
171 | - $expected, |
|
172 | - $found, |
|
173 | - ); |
|
174 | - |
|
175 | - $fix = $phpcsFile->addFixableError($error, $openingBrace, 'BraceIndent', $data); |
|
176 | - if ($fix === true) { |
|
177 | - $indent = str_repeat(' ', $expected); |
|
178 | - if ($found === 0) { |
|
179 | - $phpcsFile->fixer->addContentBefore($openingBrace, $indent); |
|
180 | - } else { |
|
181 | - $phpcsFile->fixer->replaceToken(($openingBrace - 1), $indent); |
|
182 | - } |
|
183 | - } |
|
184 | - }//end if |
|
185 | - |
|
186 | - $phpcsFile->recordMetric($stackPtr, 'Function opening brace placement', 'new line'); |
|
187 | - |
|
188 | - }//end process() |
|
34 | + /** |
|
35 | + * Should this sniff check function braces? |
|
36 | + * |
|
37 | + * @var bool |
|
38 | + */ |
|
39 | + public $checkFunctions = true; |
|
40 | + |
|
41 | + /** |
|
42 | + * Should this sniff check closure braces? |
|
43 | + * |
|
44 | + * @var bool |
|
45 | + */ |
|
46 | + public $checkClosures = false; |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * Registers the tokens that this sniff wants to listen for. |
|
51 | + * |
|
52 | + * @return void |
|
53 | + */ |
|
54 | + public function register() |
|
55 | + { |
|
56 | + return array( |
|
57 | + T_FUNCTION, |
|
58 | + T_CLOSURE, |
|
59 | + ); |
|
60 | + |
|
61 | + }//end register() |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * Processes this test, when one of its tokens is encountered. |
|
66 | + * |
|
67 | + * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
68 | + * @param int $stackPtr The position of the current token in the |
|
69 | + * stack passed in $tokens. |
|
70 | + * |
|
71 | + * @return void |
|
72 | + */ |
|
73 | + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
74 | + { |
|
75 | + $tokens = $phpcsFile->getTokens(); |
|
76 | + |
|
77 | + if (isset($tokens[$stackPtr]['scope_opener']) === false) { |
|
78 | + return; |
|
79 | + } |
|
80 | + |
|
81 | + if (($tokens[$stackPtr]['code'] === T_FUNCTION |
|
82 | + && (bool) $this->checkFunctions === false) |
|
83 | + || ($tokens[$stackPtr]['code'] === T_CLOSURE |
|
84 | + && (bool) $this->checkClosures === false) |
|
85 | + ) { |
|
86 | + return; |
|
87 | + } |
|
88 | + |
|
89 | + $openingBrace = $tokens[$stackPtr]['scope_opener']; |
|
90 | + $closeBracket = $tokens[$stackPtr]['parenthesis_closer']; |
|
91 | + if ($tokens[$stackPtr]['code'] === T_CLOSURE) { |
|
92 | + $use = $phpcsFile->findNext(T_USE, ($closeBracket + 1), $tokens[$stackPtr]['scope_opener']); |
|
93 | + if ($use !== false) { |
|
94 | + $openBracket = $phpcsFile->findNext(T_OPEN_PARENTHESIS, ($use + 1)); |
|
95 | + $closeBracket = $tokens[$openBracket]['parenthesis_closer']; |
|
96 | + } |
|
97 | + } |
|
98 | + |
|
99 | + $functionLine = $tokens[$closeBracket]['line']; |
|
100 | + $braceLine = $tokens[$openingBrace]['line']; |
|
101 | + |
|
102 | + $lineDifference = ($braceLine - $functionLine); |
|
103 | + |
|
104 | + if ($lineDifference === 0) { |
|
105 | + $error = 'Opening brace should be on a new line'; |
|
106 | + $fix = $phpcsFile->addFixableError($error, $openingBrace, 'BraceOnSameLine'); |
|
107 | + if ($fix === true) { |
|
108 | + $phpcsFile->fixer->beginChangeset(); |
|
109 | + $indent = $phpcsFile->findFirstOnLine(array(), $openingBrace); |
|
110 | + if ($tokens[$indent]['code'] === T_WHITESPACE) { |
|
111 | + $phpcsFile->fixer->addContentBefore($openingBrace, $tokens[$indent]['content']); |
|
112 | + } |
|
113 | + |
|
114 | + $phpcsFile->fixer->addNewlineBefore($openingBrace); |
|
115 | + $phpcsFile->fixer->endChangeset(); |
|
116 | + } |
|
117 | + |
|
118 | + $phpcsFile->recordMetric($stackPtr, 'Function opening brace placement', 'same line'); |
|
119 | + } else if ($lineDifference > 1) { |
|
120 | + $error = 'Opening brace should be on the line after the declaration; found %s blank line(s)'; |
|
121 | + $data = array(($lineDifference - 1)); |
|
122 | + $fix = $phpcsFile->addFixableError($error, $openingBrace, 'BraceSpacing', $data); |
|
123 | + if ($fix === true) { |
|
124 | + for ($i = ($tokens[$stackPtr]['parenthesis_closer'] + 1); $i < $openingBrace; $i++) { |
|
125 | + if ($tokens[$i]['line'] === $braceLine) { |
|
126 | + $phpcsFile->fixer->addNewLineBefore($i); |
|
127 | + break; |
|
128 | + } |
|
129 | + |
|
130 | + $phpcsFile->fixer->replaceToken($i, ''); |
|
131 | + } |
|
132 | + } |
|
133 | + }//end if |
|
134 | + |
|
135 | + $next = $phpcsFile->findNext(T_WHITESPACE, ($openingBrace + 1), null, true); |
|
136 | + if ($tokens[$next]['line'] === $tokens[$openingBrace]['line']) { |
|
137 | + if ($next === $tokens[$stackPtr]['scope_closer']) { |
|
138 | + // Ignore empty functions. |
|
139 | + return; |
|
140 | + } |
|
141 | + |
|
142 | + $error = 'Opening brace must be the last content on the line'; |
|
143 | + $fix = $phpcsFile->addFixableError($error, $openingBrace, 'ContentAfterBrace'); |
|
144 | + if ($fix === true) { |
|
145 | + $phpcsFile->fixer->addNewline($openingBrace); |
|
146 | + } |
|
147 | + } |
|
148 | + |
|
149 | + // Only continue checking if the opening brace looks good. |
|
150 | + if ($lineDifference !== 1) { |
|
151 | + return; |
|
152 | + } |
|
153 | + |
|
154 | + // We need to actually find the first piece of content on this line, |
|
155 | + // as if this is a method with tokens before it (public, static etc) |
|
156 | + // or an if with an else before it, then we need to start the scope |
|
157 | + // checking from there, rather than the current token. |
|
158 | + $lineStart = $phpcsFile->findFirstOnLine(T_WHITESPACE, $stackPtr, true); |
|
159 | + |
|
160 | + // The opening brace is on the correct line, now it needs to be |
|
161 | + // checked to be correctly indented. |
|
162 | + $startColumn = $tokens[$lineStart]['column']; |
|
163 | + $braceIndent = $tokens[$openingBrace]['column']; |
|
164 | + |
|
165 | + if ($braceIndent !== $startColumn) { |
|
166 | + $expected = ($startColumn - 1); |
|
167 | + $found = ($braceIndent - 1); |
|
168 | + |
|
169 | + $error = 'Opening brace indented incorrectly; expected %s spaces, found %s'; |
|
170 | + $data = array( |
|
171 | + $expected, |
|
172 | + $found, |
|
173 | + ); |
|
174 | + |
|
175 | + $fix = $phpcsFile->addFixableError($error, $openingBrace, 'BraceIndent', $data); |
|
176 | + if ($fix === true) { |
|
177 | + $indent = str_repeat(' ', $expected); |
|
178 | + if ($found === 0) { |
|
179 | + $phpcsFile->fixer->addContentBefore($openingBrace, $indent); |
|
180 | + } else { |
|
181 | + $phpcsFile->fixer->replaceToken(($openingBrace - 1), $indent); |
|
182 | + } |
|
183 | + } |
|
184 | + }//end if |
|
185 | + |
|
186 | + $phpcsFile->recordMetric($stackPtr, 'Function opening brace placement', 'new line'); |
|
187 | + |
|
188 | + }//end process() |
|
189 | 189 | |
190 | 190 | |
191 | 191 | }//end class |
@@ -70,84 +70,84 @@ discard block |
||
70 | 70 | * |
71 | 71 | * @return void |
72 | 72 | */ |
73 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
73 | + public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) |
|
74 | 74 | { |
75 | 75 | $tokens = $phpcsFile->getTokens(); |
76 | 76 | |
77 | - if (isset($tokens[$stackPtr]['scope_opener']) === false) { |
|
77 | + if ( isset( $tokens[ $stackPtr ][ 'scope_opener' ] ) === false ) { |
|
78 | 78 | return; |
79 | 79 | } |
80 | 80 | |
81 | - if (($tokens[$stackPtr]['code'] === T_FUNCTION |
|
82 | - && (bool) $this->checkFunctions === false) |
|
83 | - || ($tokens[$stackPtr]['code'] === T_CLOSURE |
|
84 | - && (bool) $this->checkClosures === false) |
|
81 | + if ( ( $tokens[ $stackPtr ][ 'code' ] === T_FUNCTION |
|
82 | + && (bool) $this->checkFunctions === false ) |
|
83 | + || ( $tokens[ $stackPtr ][ 'code' ] === T_CLOSURE |
|
84 | + && (bool) $this->checkClosures === false ) |
|
85 | 85 | ) { |
86 | 86 | return; |
87 | 87 | } |
88 | 88 | |
89 | - $openingBrace = $tokens[$stackPtr]['scope_opener']; |
|
90 | - $closeBracket = $tokens[$stackPtr]['parenthesis_closer']; |
|
91 | - if ($tokens[$stackPtr]['code'] === T_CLOSURE) { |
|
92 | - $use = $phpcsFile->findNext(T_USE, ($closeBracket + 1), $tokens[$stackPtr]['scope_opener']); |
|
93 | - if ($use !== false) { |
|
94 | - $openBracket = $phpcsFile->findNext(T_OPEN_PARENTHESIS, ($use + 1)); |
|
95 | - $closeBracket = $tokens[$openBracket]['parenthesis_closer']; |
|
89 | + $openingBrace = $tokens[ $stackPtr ][ 'scope_opener' ]; |
|
90 | + $closeBracket = $tokens[ $stackPtr ][ 'parenthesis_closer' ]; |
|
91 | + if ( $tokens[ $stackPtr ][ 'code' ] === T_CLOSURE ) { |
|
92 | + $use = $phpcsFile->findNext( T_USE, ( $closeBracket + 1 ), $tokens[ $stackPtr ][ 'scope_opener' ] ); |
|
93 | + if ( $use !== false ) { |
|
94 | + $openBracket = $phpcsFile->findNext( T_OPEN_PARENTHESIS, ( $use + 1 ) ); |
|
95 | + $closeBracket = $tokens[ $openBracket ][ 'parenthesis_closer' ]; |
|
96 | 96 | } |
97 | 97 | } |
98 | 98 | |
99 | - $functionLine = $tokens[$closeBracket]['line']; |
|
100 | - $braceLine = $tokens[$openingBrace]['line']; |
|
99 | + $functionLine = $tokens[ $closeBracket ][ 'line' ]; |
|
100 | + $braceLine = $tokens[ $openingBrace ][ 'line' ]; |
|
101 | 101 | |
102 | - $lineDifference = ($braceLine - $functionLine); |
|
102 | + $lineDifference = ( $braceLine - $functionLine ); |
|
103 | 103 | |
104 | - if ($lineDifference === 0) { |
|
104 | + if ( $lineDifference === 0 ) { |
|
105 | 105 | $error = 'Opening brace should be on a new line'; |
106 | - $fix = $phpcsFile->addFixableError($error, $openingBrace, 'BraceOnSameLine'); |
|
107 | - if ($fix === true) { |
|
106 | + $fix = $phpcsFile->addFixableError( $error, $openingBrace, 'BraceOnSameLine' ); |
|
107 | + if ( $fix === true ) { |
|
108 | 108 | $phpcsFile->fixer->beginChangeset(); |
109 | - $indent = $phpcsFile->findFirstOnLine(array(), $openingBrace); |
|
110 | - if ($tokens[$indent]['code'] === T_WHITESPACE) { |
|
111 | - $phpcsFile->fixer->addContentBefore($openingBrace, $tokens[$indent]['content']); |
|
109 | + $indent = $phpcsFile->findFirstOnLine( array(), $openingBrace ); |
|
110 | + if ( $tokens[ $indent ][ 'code' ] === T_WHITESPACE ) { |
|
111 | + $phpcsFile->fixer->addContentBefore( $openingBrace, $tokens[ $indent ][ 'content' ] ); |
|
112 | 112 | } |
113 | 113 | |
114 | - $phpcsFile->fixer->addNewlineBefore($openingBrace); |
|
114 | + $phpcsFile->fixer->addNewlineBefore( $openingBrace ); |
|
115 | 115 | $phpcsFile->fixer->endChangeset(); |
116 | 116 | } |
117 | 117 | |
118 | - $phpcsFile->recordMetric($stackPtr, 'Function opening brace placement', 'same line'); |
|
119 | - } else if ($lineDifference > 1) { |
|
118 | + $phpcsFile->recordMetric( $stackPtr, 'Function opening brace placement', 'same line' ); |
|
119 | + } else if ( $lineDifference > 1 ) { |
|
120 | 120 | $error = 'Opening brace should be on the line after the declaration; found %s blank line(s)'; |
121 | - $data = array(($lineDifference - 1)); |
|
122 | - $fix = $phpcsFile->addFixableError($error, $openingBrace, 'BraceSpacing', $data); |
|
123 | - if ($fix === true) { |
|
124 | - for ($i = ($tokens[$stackPtr]['parenthesis_closer'] + 1); $i < $openingBrace; $i++) { |
|
125 | - if ($tokens[$i]['line'] === $braceLine) { |
|
126 | - $phpcsFile->fixer->addNewLineBefore($i); |
|
121 | + $data = array( ( $lineDifference - 1 ) ); |
|
122 | + $fix = $phpcsFile->addFixableError( $error, $openingBrace, 'BraceSpacing', $data ); |
|
123 | + if ( $fix === true ) { |
|
124 | + for ( $i = ( $tokens[ $stackPtr ][ 'parenthesis_closer' ] + 1 ); $i < $openingBrace; $i++ ) { |
|
125 | + if ( $tokens[ $i ][ 'line' ] === $braceLine ) { |
|
126 | + $phpcsFile->fixer->addNewLineBefore( $i ); |
|
127 | 127 | break; |
128 | 128 | } |
129 | 129 | |
130 | - $phpcsFile->fixer->replaceToken($i, ''); |
|
130 | + $phpcsFile->fixer->replaceToken( $i, '' ); |
|
131 | 131 | } |
132 | 132 | } |
133 | 133 | }//end if |
134 | 134 | |
135 | - $next = $phpcsFile->findNext(T_WHITESPACE, ($openingBrace + 1), null, true); |
|
136 | - if ($tokens[$next]['line'] === $tokens[$openingBrace]['line']) { |
|
137 | - if ($next === $tokens[$stackPtr]['scope_closer']) { |
|
135 | + $next = $phpcsFile->findNext( T_WHITESPACE, ( $openingBrace + 1 ), null, true ); |
|
136 | + if ( $tokens[ $next ][ 'line' ] === $tokens[ $openingBrace ][ 'line' ] ) { |
|
137 | + if ( $next === $tokens[ $stackPtr ][ 'scope_closer' ] ) { |
|
138 | 138 | // Ignore empty functions. |
139 | 139 | return; |
140 | 140 | } |
141 | 141 | |
142 | 142 | $error = 'Opening brace must be the last content on the line'; |
143 | - $fix = $phpcsFile->addFixableError($error, $openingBrace, 'ContentAfterBrace'); |
|
144 | - if ($fix === true) { |
|
145 | - $phpcsFile->fixer->addNewline($openingBrace); |
|
143 | + $fix = $phpcsFile->addFixableError( $error, $openingBrace, 'ContentAfterBrace' ); |
|
144 | + if ( $fix === true ) { |
|
145 | + $phpcsFile->fixer->addNewline( $openingBrace ); |
|
146 | 146 | } |
147 | 147 | } |
148 | 148 | |
149 | 149 | // Only continue checking if the opening brace looks good. |
150 | - if ($lineDifference !== 1) { |
|
150 | + if ( $lineDifference !== 1 ) { |
|
151 | 151 | return; |
152 | 152 | } |
153 | 153 | |
@@ -155,16 +155,16 @@ discard block |
||
155 | 155 | // as if this is a method with tokens before it (public, static etc) |
156 | 156 | // or an if with an else before it, then we need to start the scope |
157 | 157 | // checking from there, rather than the current token. |
158 | - $lineStart = $phpcsFile->findFirstOnLine(T_WHITESPACE, $stackPtr, true); |
|
158 | + $lineStart = $phpcsFile->findFirstOnLine( T_WHITESPACE, $stackPtr, true ); |
|
159 | 159 | |
160 | 160 | // The opening brace is on the correct line, now it needs to be |
161 | 161 | // checked to be correctly indented. |
162 | - $startColumn = $tokens[$lineStart]['column']; |
|
163 | - $braceIndent = $tokens[$openingBrace]['column']; |
|
162 | + $startColumn = $tokens[ $lineStart ][ 'column' ]; |
|
163 | + $braceIndent = $tokens[ $openingBrace ][ 'column' ]; |
|
164 | 164 | |
165 | - if ($braceIndent !== $startColumn) { |
|
166 | - $expected = ($startColumn - 1); |
|
167 | - $found = ($braceIndent - 1); |
|
165 | + if ( $braceIndent !== $startColumn ) { |
|
166 | + $expected = ( $startColumn - 1 ); |
|
167 | + $found = ( $braceIndent - 1 ); |
|
168 | 168 | |
169 | 169 | $error = 'Opening brace indented incorrectly; expected %s spaces, found %s'; |
170 | 170 | $data = array( |
@@ -172,18 +172,18 @@ discard block |
||
172 | 172 | $found, |
173 | 173 | ); |
174 | 174 | |
175 | - $fix = $phpcsFile->addFixableError($error, $openingBrace, 'BraceIndent', $data); |
|
176 | - if ($fix === true) { |
|
177 | - $indent = str_repeat(' ', $expected); |
|
178 | - if ($found === 0) { |
|
179 | - $phpcsFile->fixer->addContentBefore($openingBrace, $indent); |
|
175 | + $fix = $phpcsFile->addFixableError( $error, $openingBrace, 'BraceIndent', $data ); |
|
176 | + if ( $fix === true ) { |
|
177 | + $indent = str_repeat( ' ', $expected ); |
|
178 | + if ( $found === 0 ) { |
|
179 | + $phpcsFile->fixer->addContentBefore( $openingBrace, $indent ); |
|
180 | 180 | } else { |
181 | - $phpcsFile->fixer->replaceToken(($openingBrace - 1), $indent); |
|
181 | + $phpcsFile->fixer->replaceToken( ( $openingBrace - 1 ), $indent ); |
|
182 | 182 | } |
183 | 183 | } |
184 | 184 | }//end if |
185 | 185 | |
186 | - $phpcsFile->recordMetric($stackPtr, 'Function opening brace placement', 'new line'); |
|
186 | + $phpcsFile->recordMetric( $stackPtr, 'Function opening brace placement', 'new line' ); |
|
187 | 187 | |
188 | 188 | }//end process() |
189 | 189 |
@@ -28,8 +28,7 @@ discard block |
||
28 | 28 | * @version Release: @package_version@ |
29 | 29 | * @link http://pear.php.net/package/PHP_CodeSniffer |
30 | 30 | */ |
31 | -class Generic_Sniffs_Functions_OpeningFunctionBraceBsdAllmanSniff implements PHP_CodeSniffer_Sniff |
|
32 | -{ |
|
31 | +class Generic_Sniffs_Functions_OpeningFunctionBraceBsdAllmanSniff implements PHP_CodeSniffer_Sniff { |
|
33 | 32 | |
34 | 33 | /** |
35 | 34 | * Should this sniff check function braces? |
@@ -51,8 +50,7 @@ discard block |
||
51 | 50 | * |
52 | 51 | * @return void |
53 | 52 | */ |
54 | - public function register() |
|
55 | - { |
|
53 | + public function register() { |
|
56 | 54 | return array( |
57 | 55 | T_FUNCTION, |
58 | 56 | T_CLOSURE, |
@@ -70,8 +68,7 @@ discard block |
||
70 | 68 | * |
71 | 69 | * @return void |
72 | 70 | */ |
73 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
74 | - { |
|
71 | + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { |
|
75 | 72 | $tokens = $phpcsFile->getTokens(); |
76 | 73 | |
77 | 74 | if (isset($tokens[$stackPtr]['scope_opener']) === false) { |