@@ -31,53 +31,53 @@ |
||
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 PHP_CodeSniffer_Tokens::$castTokens; |
|
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 PHP_CodeSniffer_Tokens::$castTokens; |
|
42 | 42 | |
43 | - }//end register() |
|
43 | + }//end register() |
|
44 | 44 | |
45 | 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 |
|
51 | - * the stack passed in $tokens. |
|
52 | - * |
|
53 | - * @return void |
|
54 | - */ |
|
55 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
56 | - { |
|
57 | - $tokens = $phpcsFile->getTokens(); |
|
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 |
|
51 | + * the stack passed in $tokens. |
|
52 | + * |
|
53 | + * @return void |
|
54 | + */ |
|
55 | + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
56 | + { |
|
57 | + $tokens = $phpcsFile->getTokens(); |
|
58 | 58 | |
59 | - if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) { |
|
60 | - $error = 'A cast statement must be followed by a single space'; |
|
61 | - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NoSpace'); |
|
62 | - if ($fix === true) { |
|
63 | - $phpcsFile->fixer->addContent($stackPtr, ' '); |
|
64 | - } |
|
59 | + if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) { |
|
60 | + $error = 'A cast statement must be followed by a single space'; |
|
61 | + $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NoSpace'); |
|
62 | + if ($fix === true) { |
|
63 | + $phpcsFile->fixer->addContent($stackPtr, ' '); |
|
64 | + } |
|
65 | 65 | |
66 | - $phpcsFile->recordMetric($stackPtr, 'Spacing after cast statement', 0); |
|
67 | - return; |
|
68 | - } |
|
66 | + $phpcsFile->recordMetric($stackPtr, 'Spacing after cast statement', 0); |
|
67 | + return; |
|
68 | + } |
|
69 | 69 | |
70 | - $phpcsFile->recordMetric($stackPtr, 'Spacing after cast statement', $tokens[($stackPtr + 1)]['length']); |
|
70 | + $phpcsFile->recordMetric($stackPtr, 'Spacing after cast statement', $tokens[($stackPtr + 1)]['length']); |
|
71 | 71 | |
72 | - if ($tokens[($stackPtr + 1)]['length'] !== 1) { |
|
73 | - $error = 'A cast statement must be followed by a single space'; |
|
74 | - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'TooMuchSpace'); |
|
75 | - if ($fix === true) { |
|
76 | - $phpcsFile->fixer->replaceToken(($stackPtr + 1), ' '); |
|
77 | - } |
|
78 | - } |
|
72 | + if ($tokens[($stackPtr + 1)]['length'] !== 1) { |
|
73 | + $error = 'A cast statement must be followed by a single space'; |
|
74 | + $fix = $phpcsFile->addFixableError($error, $stackPtr, 'TooMuchSpace'); |
|
75 | + if ($fix === true) { |
|
76 | + $phpcsFile->fixer->replaceToken(($stackPtr + 1), ' '); |
|
77 | + } |
|
78 | + } |
|
79 | 79 | |
80 | - }//end process() |
|
80 | + }//end process() |
|
81 | 81 | |
82 | 82 | |
83 | 83 | }//end class |
@@ -52,28 +52,28 @@ |
||
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 | |
59 | - if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) { |
|
59 | + if ( $tokens[ ( $stackPtr + 1 ) ][ 'code' ] !== T_WHITESPACE ) { |
|
60 | 60 | $error = 'A cast statement must be followed by a single space'; |
61 | - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NoSpace'); |
|
62 | - if ($fix === true) { |
|
63 | - $phpcsFile->fixer->addContent($stackPtr, ' '); |
|
61 | + $fix = $phpcsFile->addFixableError( $error, $stackPtr, 'NoSpace' ); |
|
62 | + if ( $fix === true ) { |
|
63 | + $phpcsFile->fixer->addContent( $stackPtr, ' ' ); |
|
64 | 64 | } |
65 | 65 | |
66 | - $phpcsFile->recordMetric($stackPtr, 'Spacing after cast statement', 0); |
|
66 | + $phpcsFile->recordMetric( $stackPtr, 'Spacing after cast statement', 0 ); |
|
67 | 67 | return; |
68 | 68 | } |
69 | 69 | |
70 | - $phpcsFile->recordMetric($stackPtr, 'Spacing after cast statement', $tokens[($stackPtr + 1)]['length']); |
|
70 | + $phpcsFile->recordMetric( $stackPtr, 'Spacing after cast statement', $tokens[ ( $stackPtr + 1 ) ][ 'length' ] ); |
|
71 | 71 | |
72 | - if ($tokens[($stackPtr + 1)]['length'] !== 1) { |
|
72 | + if ( $tokens[ ( $stackPtr + 1 ) ][ 'length' ] !== 1 ) { |
|
73 | 73 | $error = 'A cast statement must be followed by a single space'; |
74 | - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'TooMuchSpace'); |
|
75 | - if ($fix === true) { |
|
76 | - $phpcsFile->fixer->replaceToken(($stackPtr + 1), ' '); |
|
74 | + $fix = $phpcsFile->addFixableError( $error, $stackPtr, 'TooMuchSpace' ); |
|
75 | + if ( $fix === true ) { |
|
76 | + $phpcsFile->fixer->replaceToken( ( $stackPtr + 1 ), ' ' ); |
|
77 | 77 | } |
78 | 78 | } |
79 | 79 |
@@ -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_Formatting_SpaceAfterCastSniff implements PHP_CodeSniffer_Sniff |
|
31 | -{ |
|
30 | +class Generic_Sniffs_Formatting_SpaceAfterCastSniff 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 PHP_CodeSniffer_Tokens::$castTokens; |
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 | if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) { |
@@ -31,33 +31,33 @@ |
||
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_BACKTICK); |
|
42 | - |
|
43 | - }//end register() |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * Processes this test, when one of its tokens is encountered. |
|
48 | - * |
|
49 | - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
50 | - * @param int $stackPtr The position of the current token |
|
51 | - * in the stack passed in $tokens. |
|
52 | - * |
|
53 | - * @return void |
|
54 | - */ |
|
55 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
56 | - { |
|
57 | - $error = 'Use of the backtick operator is forbidden'; |
|
58 | - $phpcsFile->addError($error, $stackPtr, 'Found'); |
|
59 | - |
|
60 | - }//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_BACKTICK); |
|
42 | + |
|
43 | + }//end register() |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * Processes this test, when one of its tokens is encountered. |
|
48 | + * |
|
49 | + * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
50 | + * @param int $stackPtr The position of the current token |
|
51 | + * in the stack passed in $tokens. |
|
52 | + * |
|
53 | + * @return void |
|
54 | + */ |
|
55 | + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
56 | + { |
|
57 | + $error = 'Use of the backtick operator is forbidden'; |
|
58 | + $phpcsFile->addError($error, $stackPtr, 'Found'); |
|
59 | + |
|
60 | + }//end process() |
|
61 | 61 | |
62 | 62 | |
63 | 63 | }//end class |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function register() |
40 | 40 | { |
41 | - return array(T_BACKTICK); |
|
41 | + return array( T_BACKTICK ); |
|
42 | 42 | |
43 | 43 | }//end register() |
44 | 44 | |
@@ -52,10 +52,10 @@ 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 | $error = 'Use of the backtick operator is forbidden'; |
58 | - $phpcsFile->addError($error, $stackPtr, 'Found'); |
|
58 | + $phpcsFile->addError( $error, $stackPtr, 'Found' ); |
|
59 | 59 | |
60 | 60 | }//end process() |
61 | 61 |
@@ -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_PHP_BacktickOperatorSniff implements PHP_CodeSniffer_Sniff |
|
31 | -{ |
|
30 | +class Generic_Sniffs_PHP_BacktickOperatorSniff 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_BACKTICK); |
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 | $error = 'Use of the backtick operator is forbidden'; |
58 | 55 | $phpcsFile->addError($error, $stackPtr, 'Found'); |
59 | 56 |
@@ -31,67 +31,67 @@ |
||
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( |
|
42 | - T_OPEN_TAG, |
|
43 | - T_OPEN_TAG_WITH_ECHO, |
|
44 | - ); |
|
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( |
|
42 | + T_OPEN_TAG, |
|
43 | + T_OPEN_TAG_WITH_ECHO, |
|
44 | + ); |
|
45 | 45 | |
46 | - }//end register() |
|
46 | + }//end register() |
|
47 | 47 | |
48 | 48 | |
49 | - /** |
|
50 | - * Processes this test, when one of its tokens is encountered. |
|
51 | - * |
|
52 | - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
53 | - * @param int $stackPtr The position of the current token |
|
54 | - * in the stack passed in $tokens. |
|
55 | - * |
|
56 | - * @return void |
|
57 | - */ |
|
58 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
59 | - { |
|
60 | - $tokens = $phpcsFile->getTokens(); |
|
61 | - $openTag = $tokens[$stackPtr]; |
|
49 | + /** |
|
50 | + * Processes this test, when one of its tokens is encountered. |
|
51 | + * |
|
52 | + * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
53 | + * @param int $stackPtr The position of the current token |
|
54 | + * in the stack passed in $tokens. |
|
55 | + * |
|
56 | + * @return void |
|
57 | + */ |
|
58 | + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
59 | + { |
|
60 | + $tokens = $phpcsFile->getTokens(); |
|
61 | + $openTag = $tokens[$stackPtr]; |
|
62 | 62 | |
63 | - if ($openTag['content'] === '<?') { |
|
64 | - $error = 'Short PHP opening tag used; expected "<?php" but found "%s"'; |
|
65 | - $data = array($openTag['content']); |
|
66 | - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found', $data); |
|
67 | - if ($fix === true) { |
|
68 | - $phpcsFile->fixer->replaceToken($stackPtr, '<?php'); |
|
69 | - } |
|
63 | + if ($openTag['content'] === '<?') { |
|
64 | + $error = 'Short PHP opening tag used; expected "<?php" but found "%s"'; |
|
65 | + $data = array($openTag['content']); |
|
66 | + $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found', $data); |
|
67 | + if ($fix === true) { |
|
68 | + $phpcsFile->fixer->replaceToken($stackPtr, '<?php'); |
|
69 | + } |
|
70 | 70 | |
71 | - $phpcsFile->recordMetric($stackPtr, 'PHP short open tag used', 'yes'); |
|
72 | - } else { |
|
73 | - $phpcsFile->recordMetric($stackPtr, 'PHP short open tag used', 'no'); |
|
74 | - } |
|
71 | + $phpcsFile->recordMetric($stackPtr, 'PHP short open tag used', 'yes'); |
|
72 | + } else { |
|
73 | + $phpcsFile->recordMetric($stackPtr, 'PHP short open tag used', 'no'); |
|
74 | + } |
|
75 | 75 | |
76 | - if ($openTag['code'] === T_OPEN_TAG_WITH_ECHO) { |
|
77 | - $nextVar = $tokens[$phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true)]; |
|
78 | - $error = 'Short PHP opening tag used with echo; expected "<?php echo %s ..." but found "%s %s ..."'; |
|
79 | - $data = array( |
|
80 | - $nextVar['content'], |
|
81 | - $openTag['content'], |
|
82 | - $nextVar['content'], |
|
83 | - ); |
|
84 | - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'EchoFound', $data); |
|
85 | - if ($fix === true) { |
|
86 | - if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) { |
|
87 | - $phpcsFile->fixer->replaceToken($stackPtr, '<?php echo '); |
|
88 | - } else { |
|
89 | - $phpcsFile->fixer->replaceToken($stackPtr, '<?php echo'); |
|
90 | - } |
|
91 | - } |
|
92 | - } |
|
76 | + if ($openTag['code'] === T_OPEN_TAG_WITH_ECHO) { |
|
77 | + $nextVar = $tokens[$phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true)]; |
|
78 | + $error = 'Short PHP opening tag used with echo; expected "<?php echo %s ..." but found "%s %s ..."'; |
|
79 | + $data = array( |
|
80 | + $nextVar['content'], |
|
81 | + $openTag['content'], |
|
82 | + $nextVar['content'], |
|
83 | + ); |
|
84 | + $fix = $phpcsFile->addFixableError($error, $stackPtr, 'EchoFound', $data); |
|
85 | + if ($fix === true) { |
|
86 | + if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) { |
|
87 | + $phpcsFile->fixer->replaceToken($stackPtr, '<?php echo '); |
|
88 | + } else { |
|
89 | + $phpcsFile->fixer->replaceToken($stackPtr, '<?php echo'); |
|
90 | + } |
|
91 | + } |
|
92 | + } |
|
93 | 93 | |
94 | - }//end process() |
|
94 | + }//end process() |
|
95 | 95 | |
96 | 96 | |
97 | 97 | }//end class |
@@ -55,38 +55,38 @@ |
||
55 | 55 | * |
56 | 56 | * @return void |
57 | 57 | */ |
58 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
58 | + public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) |
|
59 | 59 | { |
60 | 60 | $tokens = $phpcsFile->getTokens(); |
61 | - $openTag = $tokens[$stackPtr]; |
|
61 | + $openTag = $tokens[ $stackPtr ]; |
|
62 | 62 | |
63 | - if ($openTag['content'] === '<?') { |
|
63 | + if ( $openTag[ 'content' ] === '<?' ) { |
|
64 | 64 | $error = 'Short PHP opening tag used; expected "<?php" but found "%s"'; |
65 | - $data = array($openTag['content']); |
|
66 | - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found', $data); |
|
67 | - if ($fix === true) { |
|
68 | - $phpcsFile->fixer->replaceToken($stackPtr, '<?php'); |
|
65 | + $data = array( $openTag[ 'content' ] ); |
|
66 | + $fix = $phpcsFile->addFixableError( $error, $stackPtr, 'Found', $data ); |
|
67 | + if ( $fix === true ) { |
|
68 | + $phpcsFile->fixer->replaceToken( $stackPtr, '<?php' ); |
|
69 | 69 | } |
70 | 70 | |
71 | - $phpcsFile->recordMetric($stackPtr, 'PHP short open tag used', 'yes'); |
|
71 | + $phpcsFile->recordMetric( $stackPtr, 'PHP short open tag used', 'yes' ); |
|
72 | 72 | } else { |
73 | - $phpcsFile->recordMetric($stackPtr, 'PHP short open tag used', 'no'); |
|
73 | + $phpcsFile->recordMetric( $stackPtr, 'PHP short open tag used', 'no' ); |
|
74 | 74 | } |
75 | 75 | |
76 | - if ($openTag['code'] === T_OPEN_TAG_WITH_ECHO) { |
|
77 | - $nextVar = $tokens[$phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true)]; |
|
76 | + if ( $openTag[ 'code' ] === T_OPEN_TAG_WITH_ECHO ) { |
|
77 | + $nextVar = $tokens[ $phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true ) ]; |
|
78 | 78 | $error = 'Short PHP opening tag used with echo; expected "<?php echo %s ..." but found "%s %s ..."'; |
79 | 79 | $data = array( |
80 | - $nextVar['content'], |
|
81 | - $openTag['content'], |
|
82 | - $nextVar['content'], |
|
80 | + $nextVar[ 'content' ], |
|
81 | + $openTag[ 'content' ], |
|
82 | + $nextVar[ 'content' ], |
|
83 | 83 | ); |
84 | - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'EchoFound', $data); |
|
85 | - if ($fix === true) { |
|
86 | - if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) { |
|
87 | - $phpcsFile->fixer->replaceToken($stackPtr, '<?php echo '); |
|
84 | + $fix = $phpcsFile->addFixableError( $error, $stackPtr, 'EchoFound', $data ); |
|
85 | + if ( $fix === true ) { |
|
86 | + if ( $tokens[ ( $stackPtr + 1 ) ][ 'code' ] !== T_WHITESPACE ) { |
|
87 | + $phpcsFile->fixer->replaceToken( $stackPtr, '<?php echo ' ); |
|
88 | 88 | } else { |
89 | - $phpcsFile->fixer->replaceToken($stackPtr, '<?php echo'); |
|
89 | + $phpcsFile->fixer->replaceToken( $stackPtr, '<?php echo' ); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | } |
@@ -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_PHP_DisallowShortOpenTagSniff implements PHP_CodeSniffer_Sniff |
|
31 | -{ |
|
30 | +class Generic_Sniffs_PHP_DisallowShortOpenTagSniff 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( |
42 | 40 | T_OPEN_TAG, |
43 | 41 | T_OPEN_TAG_WITH_ECHO, |
@@ -55,8 +53,7 @@ discard block |
||
55 | 53 | * |
56 | 54 | * @return void |
57 | 55 | */ |
58 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
59 | - { |
|
56 | + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { |
|
60 | 57 | $tokens = $phpcsFile->getTokens(); |
61 | 58 | $openTag = $tokens[$stackPtr]; |
62 | 59 |
@@ -31,58 +31,58 @@ |
||
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( |
|
42 | - T_TRUE, |
|
43 | - T_FALSE, |
|
44 | - T_NULL, |
|
45 | - ); |
|
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( |
|
42 | + T_TRUE, |
|
43 | + T_FALSE, |
|
44 | + T_NULL, |
|
45 | + ); |
|
46 | 46 | |
47 | - }//end register() |
|
47 | + }//end register() |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * Processes this sniff, when one of its tokens is encountered. |
|
52 | - * |
|
53 | - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
54 | - * @param int $stackPtr The position of the current token in the |
|
55 | - * stack passed in $tokens. |
|
56 | - * |
|
57 | - * @return void |
|
58 | - */ |
|
59 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
60 | - { |
|
61 | - $tokens = $phpcsFile->getTokens(); |
|
62 | - $keyword = $tokens[$stackPtr]['content']; |
|
63 | - $expected = strtoupper($keyword); |
|
64 | - if ($keyword !== $expected) { |
|
65 | - if ($keyword === strtolower($keyword)) { |
|
66 | - $phpcsFile->recordMetric($stackPtr, 'PHP constant case', 'lower'); |
|
67 | - } else { |
|
68 | - $phpcsFile->recordMetric($stackPtr, 'PHP constant case', 'mixed'); |
|
69 | - } |
|
50 | + /** |
|
51 | + * Processes this sniff, when one of its tokens is encountered. |
|
52 | + * |
|
53 | + * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
54 | + * @param int $stackPtr The position of the current token in the |
|
55 | + * stack passed in $tokens. |
|
56 | + * |
|
57 | + * @return void |
|
58 | + */ |
|
59 | + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
60 | + { |
|
61 | + $tokens = $phpcsFile->getTokens(); |
|
62 | + $keyword = $tokens[$stackPtr]['content']; |
|
63 | + $expected = strtoupper($keyword); |
|
64 | + if ($keyword !== $expected) { |
|
65 | + if ($keyword === strtolower($keyword)) { |
|
66 | + $phpcsFile->recordMetric($stackPtr, 'PHP constant case', 'lower'); |
|
67 | + } else { |
|
68 | + $phpcsFile->recordMetric($stackPtr, 'PHP constant case', 'mixed'); |
|
69 | + } |
|
70 | 70 | |
71 | - $error = 'TRUE, FALSE and NULL must be uppercase; expected "%s" but found "%s"'; |
|
72 | - $data = array( |
|
73 | - $expected, |
|
74 | - $keyword, |
|
75 | - ); |
|
71 | + $error = 'TRUE, FALSE and NULL must be uppercase; expected "%s" but found "%s"'; |
|
72 | + $data = array( |
|
73 | + $expected, |
|
74 | + $keyword, |
|
75 | + ); |
|
76 | 76 | |
77 | - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found', $data); |
|
78 | - if ($fix === true) { |
|
79 | - $phpcsFile->fixer->replaceToken($stackPtr, $expected); |
|
80 | - } |
|
81 | - } else { |
|
82 | - $phpcsFile->recordMetric($stackPtr, 'PHP constant case', 'upper'); |
|
83 | - } |
|
77 | + $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found', $data); |
|
78 | + if ($fix === true) { |
|
79 | + $phpcsFile->fixer->replaceToken($stackPtr, $expected); |
|
80 | + } |
|
81 | + } else { |
|
82 | + $phpcsFile->recordMetric($stackPtr, 'PHP constant case', 'upper'); |
|
83 | + } |
|
84 | 84 | |
85 | - }//end process() |
|
85 | + }//end process() |
|
86 | 86 | |
87 | 87 | |
88 | 88 | }//end class |
@@ -56,16 +56,16 @@ discard block |
||
56 | 56 | * |
57 | 57 | * @return void |
58 | 58 | */ |
59 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
59 | + public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) |
|
60 | 60 | { |
61 | 61 | $tokens = $phpcsFile->getTokens(); |
62 | - $keyword = $tokens[$stackPtr]['content']; |
|
63 | - $expected = strtoupper($keyword); |
|
64 | - if ($keyword !== $expected) { |
|
65 | - if ($keyword === strtolower($keyword)) { |
|
66 | - $phpcsFile->recordMetric($stackPtr, 'PHP constant case', 'lower'); |
|
62 | + $keyword = $tokens[ $stackPtr ][ 'content' ]; |
|
63 | + $expected = strtoupper( $keyword ); |
|
64 | + if ( $keyword !== $expected ) { |
|
65 | + if ( $keyword === strtolower( $keyword ) ) { |
|
66 | + $phpcsFile->recordMetric( $stackPtr, 'PHP constant case', 'lower' ); |
|
67 | 67 | } else { |
68 | - $phpcsFile->recordMetric($stackPtr, 'PHP constant case', 'mixed'); |
|
68 | + $phpcsFile->recordMetric( $stackPtr, 'PHP constant case', 'mixed' ); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | $error = 'TRUE, FALSE and NULL must be uppercase; expected "%s" but found "%s"'; |
@@ -74,12 +74,12 @@ discard block |
||
74 | 74 | $keyword, |
75 | 75 | ); |
76 | 76 | |
77 | - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found', $data); |
|
78 | - if ($fix === true) { |
|
79 | - $phpcsFile->fixer->replaceToken($stackPtr, $expected); |
|
77 | + $fix = $phpcsFile->addFixableError( $error, $stackPtr, 'Found', $data ); |
|
78 | + if ( $fix === true ) { |
|
79 | + $phpcsFile->fixer->replaceToken( $stackPtr, $expected ); |
|
80 | 80 | } |
81 | 81 | } else { |
82 | - $phpcsFile->recordMetric($stackPtr, 'PHP constant case', 'upper'); |
|
82 | + $phpcsFile->recordMetric( $stackPtr, 'PHP constant case', 'upper' ); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | }//end process() |
@@ -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_PHP_UpperCaseConstantSniff implements PHP_CodeSniffer_Sniff |
|
31 | -{ |
|
30 | +class Generic_Sniffs_PHP_UpperCaseConstantSniff 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( |
42 | 40 | T_TRUE, |
43 | 41 | T_FALSE, |
@@ -56,8 +54,7 @@ discard block |
||
56 | 54 | * |
57 | 55 | * @return void |
58 | 56 | */ |
59 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
60 | - { |
|
57 | + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { |
|
61 | 58 | $tokens = $phpcsFile->getTokens(); |
62 | 59 | $keyword = $tokens[$stackPtr]['content']; |
63 | 60 | $expected = strtoupper($keyword); |
@@ -30,64 +30,64 @@ |
||
30 | 30 | class Generic_Sniffs_PHP_SyntaxSniff implements PHP_CodeSniffer_Sniff |
31 | 31 | { |
32 | 32 | |
33 | - /** |
|
34 | - * The path to the PHP version we are checking with. |
|
35 | - * |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - private $_phpPath = null; |
|
33 | + /** |
|
34 | + * The path to the PHP version we are checking with. |
|
35 | + * |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + private $_phpPath = null; |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * Returns an array of tokens this test wants to listen for. |
|
43 | - * |
|
44 | - * @return array |
|
45 | - */ |
|
46 | - public function register() |
|
47 | - { |
|
48 | - return array(T_OPEN_TAG); |
|
41 | + /** |
|
42 | + * Returns an array of tokens this test wants to listen for. |
|
43 | + * |
|
44 | + * @return array |
|
45 | + */ |
|
46 | + public function register() |
|
47 | + { |
|
48 | + return array(T_OPEN_TAG); |
|
49 | 49 | |
50 | - }//end register() |
|
50 | + }//end register() |
|
51 | 51 | |
52 | 52 | |
53 | - /** |
|
54 | - * Processes this test, when one of its tokens is encountered. |
|
55 | - * |
|
56 | - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
57 | - * @param int $stackPtr The position of the current token in |
|
58 | - * the stack passed in $tokens. |
|
59 | - * |
|
60 | - * @return void |
|
61 | - */ |
|
62 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
63 | - { |
|
64 | - if ($this->_phpPath === null) { |
|
65 | - $this->_phpPath = PHP_CodeSniffer::getConfigData('php_path'); |
|
66 | - if ($this->_phpPath === null) { |
|
67 | - // PHP_BINARY is available in PHP 5.4+. |
|
68 | - if (defined('PHP_BINARY') === true) { |
|
69 | - $this->_phpPath = PHP_BINARY; |
|
70 | - } else { |
|
71 | - return; |
|
72 | - } |
|
73 | - } |
|
74 | - } |
|
53 | + /** |
|
54 | + * Processes this test, when one of its tokens is encountered. |
|
55 | + * |
|
56 | + * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
57 | + * @param int $stackPtr The position of the current token in |
|
58 | + * the stack passed in $tokens. |
|
59 | + * |
|
60 | + * @return void |
|
61 | + */ |
|
62 | + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
63 | + { |
|
64 | + if ($this->_phpPath === null) { |
|
65 | + $this->_phpPath = PHP_CodeSniffer::getConfigData('php_path'); |
|
66 | + if ($this->_phpPath === null) { |
|
67 | + // PHP_BINARY is available in PHP 5.4+. |
|
68 | + if (defined('PHP_BINARY') === true) { |
|
69 | + $this->_phpPath = PHP_BINARY; |
|
70 | + } else { |
|
71 | + return; |
|
72 | + } |
|
73 | + } |
|
74 | + } |
|
75 | 75 | |
76 | - $fileName = $phpcsFile->getFilename(); |
|
77 | - $cmd = $this->_phpPath." -l \"$fileName\" 2>&1"; |
|
78 | - $output = shell_exec($cmd); |
|
76 | + $fileName = $phpcsFile->getFilename(); |
|
77 | + $cmd = $this->_phpPath." -l \"$fileName\" 2>&1"; |
|
78 | + $output = shell_exec($cmd); |
|
79 | 79 | |
80 | - $matches = array(); |
|
81 | - if (preg_match('/^.*error:(.*) in .* on line ([0-9]+)/', trim($output), $matches) === 1) { |
|
82 | - $error = trim($matches[1]); |
|
83 | - $line = (int) $matches[2]; |
|
84 | - $phpcsFile->addErrorOnLine("PHP syntax error: $error", $line, 'PHPSyntax'); |
|
85 | - } |
|
80 | + $matches = array(); |
|
81 | + if (preg_match('/^.*error:(.*) in .* on line ([0-9]+)/', trim($output), $matches) === 1) { |
|
82 | + $error = trim($matches[1]); |
|
83 | + $line = (int) $matches[2]; |
|
84 | + $phpcsFile->addErrorOnLine("PHP syntax error: $error", $line, 'PHPSyntax'); |
|
85 | + } |
|
86 | 86 | |
87 | - // Ignore the rest of the file. |
|
88 | - return ($phpcsFile->numTokens + 1); |
|
87 | + // Ignore the rest of the file. |
|
88 | + return ($phpcsFile->numTokens + 1); |
|
89 | 89 | |
90 | - }//end process() |
|
90 | + }//end process() |
|
91 | 91 | |
92 | 92 | |
93 | 93 | }//end class |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function register() |
47 | 47 | { |
48 | - return array(T_OPEN_TAG); |
|
48 | + return array( T_OPEN_TAG ); |
|
49 | 49 | |
50 | 50 | }//end register() |
51 | 51 | |
@@ -59,13 +59,13 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @return void |
61 | 61 | */ |
62 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
62 | + public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) |
|
63 | 63 | { |
64 | - if ($this->_phpPath === null) { |
|
65 | - $this->_phpPath = PHP_CodeSniffer::getConfigData('php_path'); |
|
66 | - if ($this->_phpPath === null) { |
|
64 | + if ( $this->_phpPath === null ) { |
|
65 | + $this->_phpPath = PHP_CodeSniffer::getConfigData( 'php_path' ); |
|
66 | + if ( $this->_phpPath === null ) { |
|
67 | 67 | // PHP_BINARY is available in PHP 5.4+. |
68 | - if (defined('PHP_BINARY') === true) { |
|
68 | + if ( defined( 'PHP_BINARY' ) === true ) { |
|
69 | 69 | $this->_phpPath = PHP_BINARY; |
70 | 70 | } else { |
71 | 71 | return; |
@@ -74,18 +74,18 @@ discard block |
||
74 | 74 | } |
75 | 75 | |
76 | 76 | $fileName = $phpcsFile->getFilename(); |
77 | - $cmd = $this->_phpPath." -l \"$fileName\" 2>&1"; |
|
78 | - $output = shell_exec($cmd); |
|
77 | + $cmd = $this->_phpPath . " -l \"$fileName\" 2>&1"; |
|
78 | + $output = shell_exec( $cmd ); |
|
79 | 79 | |
80 | 80 | $matches = array(); |
81 | - if (preg_match('/^.*error:(.*) in .* on line ([0-9]+)/', trim($output), $matches) === 1) { |
|
82 | - $error = trim($matches[1]); |
|
83 | - $line = (int) $matches[2]; |
|
84 | - $phpcsFile->addErrorOnLine("PHP syntax error: $error", $line, 'PHPSyntax'); |
|
81 | + if ( preg_match( '/^.*error:(.*) in .* on line ([0-9]+)/', trim( $output ), $matches ) === 1 ) { |
|
82 | + $error = trim( $matches[ 1 ] ); |
|
83 | + $line = (int) $matches[ 2 ]; |
|
84 | + $phpcsFile->addErrorOnLine( "PHP syntax error: $error", $line, 'PHPSyntax' ); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | // Ignore the rest of the file. |
88 | - return ($phpcsFile->numTokens + 1); |
|
88 | + return ( $phpcsFile->numTokens + 1 ); |
|
89 | 89 | |
90 | 90 | }//end process() |
91 | 91 |
@@ -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_PHP_SyntaxSniff implements PHP_CodeSniffer_Sniff |
|
31 | -{ |
|
30 | +class Generic_Sniffs_PHP_SyntaxSniff implements PHP_CodeSniffer_Sniff { |
|
32 | 31 | |
33 | 32 | /** |
34 | 33 | * The path to the PHP version we are checking with. |
@@ -43,8 +42,7 @@ discard block |
||
43 | 42 | * |
44 | 43 | * @return array |
45 | 44 | */ |
46 | - public function register() |
|
47 | - { |
|
45 | + public function register() { |
|
48 | 46 | return array(T_OPEN_TAG); |
49 | 47 | |
50 | 48 | }//end register() |
@@ -59,8 +57,7 @@ discard block |
||
59 | 57 | * |
60 | 58 | * @return void |
61 | 59 | */ |
62 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
63 | - { |
|
60 | + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { |
|
64 | 61 | if ($this->_phpPath === null) { |
65 | 62 | $this->_phpPath = PHP_CodeSniffer::getConfigData('php_path'); |
66 | 63 | if ($this->_phpPath === null) { |
@@ -31,213 +31,213 @@ |
||
31 | 31 | class Generic_Sniffs_PHP_ForbiddenFunctionsSniff implements PHP_CodeSniffer_Sniff |
32 | 32 | { |
33 | 33 | |
34 | - /** |
|
35 | - * A list of forbidden functions with their alternatives. |
|
36 | - * |
|
37 | - * The value is NULL if no alternative exists. IE, the |
|
38 | - * function should just not be used. |
|
39 | - * |
|
40 | - * @var array(string => string|null) |
|
41 | - */ |
|
42 | - public $forbiddenFunctions = array( |
|
43 | - 'sizeof' => 'count', |
|
44 | - 'delete' => 'unset', |
|
45 | - ); |
|
46 | - |
|
47 | - /** |
|
48 | - * A cache of forbidden function names, for faster lookups. |
|
49 | - * |
|
50 | - * @var array(string) |
|
51 | - */ |
|
52 | - protected $forbiddenFunctionNames = array(); |
|
53 | - |
|
54 | - /** |
|
55 | - * If true, forbidden functions will be considered regular expressions. |
|
56 | - * |
|
57 | - * @var bool |
|
58 | - */ |
|
59 | - protected $patternMatch = false; |
|
60 | - |
|
61 | - /** |
|
62 | - * If true, an error will be thrown; otherwise a warning. |
|
63 | - * |
|
64 | - * @var bool |
|
65 | - */ |
|
66 | - public $error = true; |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * Returns an array of tokens this test wants to listen for. |
|
71 | - * |
|
72 | - * @return array |
|
73 | - */ |
|
74 | - public function register() |
|
75 | - { |
|
76 | - // Everyone has had a chance to figure out what forbidden functions |
|
77 | - // they want to check for, so now we can cache out the list. |
|
78 | - $this->forbiddenFunctionNames = array_keys($this->forbiddenFunctions); |
|
79 | - |
|
80 | - if ($this->patternMatch === true) { |
|
81 | - foreach ($this->forbiddenFunctionNames as $i => $name) { |
|
82 | - $this->forbiddenFunctionNames[$i] = '/'.$name.'/i'; |
|
83 | - } |
|
84 | - |
|
85 | - return array(T_STRING); |
|
86 | - } |
|
87 | - |
|
88 | - // If we are not pattern matching, we need to work out what |
|
89 | - // tokens to listen for. |
|
90 | - $string = '<?php '; |
|
91 | - foreach ($this->forbiddenFunctionNames as $name) { |
|
92 | - $string .= $name.'();'; |
|
93 | - } |
|
94 | - |
|
95 | - $register = array(); |
|
96 | - |
|
97 | - $tokens = token_get_all($string); |
|
98 | - array_shift($tokens); |
|
99 | - foreach ($tokens as $token) { |
|
100 | - if (is_array($token) === true) { |
|
101 | - $register[] = $token[0]; |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - $this->forbiddenFunctionNames = array_map('strtolower', $this->forbiddenFunctionNames); |
|
106 | - $this->forbiddenFunctions = array_combine($this->forbiddenFunctionNames, $this->forbiddenFunctions); |
|
107 | - |
|
108 | - return array_unique($register); |
|
109 | - |
|
110 | - }//end register() |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * Processes this test, when one of its tokens is encountered. |
|
115 | - * |
|
116 | - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
117 | - * @param int $stackPtr The position of the current token in |
|
118 | - * the stack passed in $tokens. |
|
119 | - * |
|
120 | - * @return void |
|
121 | - */ |
|
122 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
123 | - { |
|
124 | - $tokens = $phpcsFile->getTokens(); |
|
125 | - |
|
126 | - $ignore = array( |
|
127 | - T_DOUBLE_COLON => true, |
|
128 | - T_OBJECT_OPERATOR => true, |
|
129 | - T_FUNCTION => true, |
|
130 | - T_CONST => true, |
|
131 | - T_PUBLIC => true, |
|
132 | - T_PRIVATE => true, |
|
133 | - T_PROTECTED => true, |
|
134 | - T_AS => true, |
|
135 | - T_NEW => true, |
|
136 | - T_INSTEADOF => true, |
|
137 | - T_NS_SEPARATOR => true, |
|
138 | - T_IMPLEMENTS => true, |
|
139 | - ); |
|
140 | - |
|
141 | - $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); |
|
142 | - |
|
143 | - // If function call is directly preceded by a NS_SEPARATOR it points to the |
|
144 | - // global namespace, so we should still catch it. |
|
145 | - if ($tokens[$prevToken]['code'] === T_NS_SEPARATOR) { |
|
146 | - $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($prevToken - 1), null, true); |
|
147 | - if ($tokens[$prevToken]['code'] === T_STRING) { |
|
148 | - // Not in the global namespace. |
|
149 | - return; |
|
150 | - } |
|
151 | - } |
|
152 | - |
|
153 | - if (isset($ignore[$tokens[$prevToken]['code']]) === true) { |
|
154 | - // Not a call to a PHP function. |
|
155 | - return; |
|
156 | - } |
|
157 | - |
|
158 | - $nextToken = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); |
|
159 | - if (isset($ignore[$tokens[$nextToken]['code']]) === true) { |
|
160 | - // Not a call to a PHP function. |
|
161 | - return; |
|
162 | - } |
|
163 | - |
|
164 | - if ($tokens[$stackPtr]['code'] === T_STRING && $tokens[$nextToken]['code'] !== T_OPEN_PARENTHESIS) { |
|
165 | - // Not a call to a PHP function. |
|
166 | - return; |
|
167 | - } |
|
168 | - |
|
169 | - $function = strtolower($tokens[$stackPtr]['content']); |
|
170 | - $pattern = null; |
|
171 | - |
|
172 | - if ($this->patternMatch === true) { |
|
173 | - $count = 0; |
|
174 | - $pattern = preg_replace( |
|
175 | - $this->forbiddenFunctionNames, |
|
176 | - $this->forbiddenFunctionNames, |
|
177 | - $function, |
|
178 | - 1, |
|
179 | - $count |
|
180 | - ); |
|
181 | - |
|
182 | - if ($count === 0) { |
|
183 | - return; |
|
184 | - } |
|
185 | - |
|
186 | - // Remove the pattern delimiters and modifier. |
|
187 | - $pattern = substr($pattern, 1, -2); |
|
188 | - } else { |
|
189 | - if (in_array($function, $this->forbiddenFunctionNames) === false) { |
|
190 | - return; |
|
191 | - } |
|
192 | - }//end if |
|
193 | - |
|
194 | - $this->addError($phpcsFile, $stackPtr, $tokens[$stackPtr]['content'], $pattern); |
|
195 | - |
|
196 | - }//end process() |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * Generates the error or warning for this sniff. |
|
201 | - * |
|
202 | - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
203 | - * @param int $stackPtr The position of the forbidden function |
|
204 | - * in the token array. |
|
205 | - * @param string $function The name of the forbidden function. |
|
206 | - * @param string $pattern The pattern used for the match. |
|
207 | - * |
|
208 | - * @return void |
|
209 | - */ |
|
210 | - protected function addError($phpcsFile, $stackPtr, $function, $pattern=null) |
|
211 | - { |
|
212 | - $data = array($function); |
|
213 | - $error = 'The use of function %s() is '; |
|
214 | - if ($this->error === true) { |
|
215 | - $type = 'Found'; |
|
216 | - $error .= 'forbidden'; |
|
217 | - } else { |
|
218 | - $type = 'Discouraged'; |
|
219 | - $error .= 'discouraged'; |
|
220 | - } |
|
221 | - |
|
222 | - if ($pattern === null) { |
|
223 | - $pattern = strtolower($function); |
|
224 | - } |
|
225 | - |
|
226 | - if ($this->forbiddenFunctions[$pattern] !== null |
|
227 | - && $this->forbiddenFunctions[$pattern] !== 'null' |
|
228 | - ) { |
|
229 | - $type .= 'WithAlternative'; |
|
230 | - $data[] = $this->forbiddenFunctions[$pattern]; |
|
231 | - $error .= '; use %s() instead'; |
|
232 | - } |
|
233 | - |
|
234 | - if ($this->error === true) { |
|
235 | - $phpcsFile->addError($error, $stackPtr, $type, $data); |
|
236 | - } else { |
|
237 | - $phpcsFile->addWarning($error, $stackPtr, $type, $data); |
|
238 | - } |
|
239 | - |
|
240 | - }//end addError() |
|
34 | + /** |
|
35 | + * A list of forbidden functions with their alternatives. |
|
36 | + * |
|
37 | + * The value is NULL if no alternative exists. IE, the |
|
38 | + * function should just not be used. |
|
39 | + * |
|
40 | + * @var array(string => string|null) |
|
41 | + */ |
|
42 | + public $forbiddenFunctions = array( |
|
43 | + 'sizeof' => 'count', |
|
44 | + 'delete' => 'unset', |
|
45 | + ); |
|
46 | + |
|
47 | + /** |
|
48 | + * A cache of forbidden function names, for faster lookups. |
|
49 | + * |
|
50 | + * @var array(string) |
|
51 | + */ |
|
52 | + protected $forbiddenFunctionNames = array(); |
|
53 | + |
|
54 | + /** |
|
55 | + * If true, forbidden functions will be considered regular expressions. |
|
56 | + * |
|
57 | + * @var bool |
|
58 | + */ |
|
59 | + protected $patternMatch = false; |
|
60 | + |
|
61 | + /** |
|
62 | + * If true, an error will be thrown; otherwise a warning. |
|
63 | + * |
|
64 | + * @var bool |
|
65 | + */ |
|
66 | + public $error = true; |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * Returns an array of tokens this test wants to listen for. |
|
71 | + * |
|
72 | + * @return array |
|
73 | + */ |
|
74 | + public function register() |
|
75 | + { |
|
76 | + // Everyone has had a chance to figure out what forbidden functions |
|
77 | + // they want to check for, so now we can cache out the list. |
|
78 | + $this->forbiddenFunctionNames = array_keys($this->forbiddenFunctions); |
|
79 | + |
|
80 | + if ($this->patternMatch === true) { |
|
81 | + foreach ($this->forbiddenFunctionNames as $i => $name) { |
|
82 | + $this->forbiddenFunctionNames[$i] = '/'.$name.'/i'; |
|
83 | + } |
|
84 | + |
|
85 | + return array(T_STRING); |
|
86 | + } |
|
87 | + |
|
88 | + // If we are not pattern matching, we need to work out what |
|
89 | + // tokens to listen for. |
|
90 | + $string = '<?php '; |
|
91 | + foreach ($this->forbiddenFunctionNames as $name) { |
|
92 | + $string .= $name.'();'; |
|
93 | + } |
|
94 | + |
|
95 | + $register = array(); |
|
96 | + |
|
97 | + $tokens = token_get_all($string); |
|
98 | + array_shift($tokens); |
|
99 | + foreach ($tokens as $token) { |
|
100 | + if (is_array($token) === true) { |
|
101 | + $register[] = $token[0]; |
|
102 | + } |
|
103 | + } |
|
104 | + |
|
105 | + $this->forbiddenFunctionNames = array_map('strtolower', $this->forbiddenFunctionNames); |
|
106 | + $this->forbiddenFunctions = array_combine($this->forbiddenFunctionNames, $this->forbiddenFunctions); |
|
107 | + |
|
108 | + return array_unique($register); |
|
109 | + |
|
110 | + }//end register() |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * Processes this test, when one of its tokens is encountered. |
|
115 | + * |
|
116 | + * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
117 | + * @param int $stackPtr The position of the current token in |
|
118 | + * the stack passed in $tokens. |
|
119 | + * |
|
120 | + * @return void |
|
121 | + */ |
|
122 | + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
123 | + { |
|
124 | + $tokens = $phpcsFile->getTokens(); |
|
125 | + |
|
126 | + $ignore = array( |
|
127 | + T_DOUBLE_COLON => true, |
|
128 | + T_OBJECT_OPERATOR => true, |
|
129 | + T_FUNCTION => true, |
|
130 | + T_CONST => true, |
|
131 | + T_PUBLIC => true, |
|
132 | + T_PRIVATE => true, |
|
133 | + T_PROTECTED => true, |
|
134 | + T_AS => true, |
|
135 | + T_NEW => true, |
|
136 | + T_INSTEADOF => true, |
|
137 | + T_NS_SEPARATOR => true, |
|
138 | + T_IMPLEMENTS => true, |
|
139 | + ); |
|
140 | + |
|
141 | + $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); |
|
142 | + |
|
143 | + // If function call is directly preceded by a NS_SEPARATOR it points to the |
|
144 | + // global namespace, so we should still catch it. |
|
145 | + if ($tokens[$prevToken]['code'] === T_NS_SEPARATOR) { |
|
146 | + $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($prevToken - 1), null, true); |
|
147 | + if ($tokens[$prevToken]['code'] === T_STRING) { |
|
148 | + // Not in the global namespace. |
|
149 | + return; |
|
150 | + } |
|
151 | + } |
|
152 | + |
|
153 | + if (isset($ignore[$tokens[$prevToken]['code']]) === true) { |
|
154 | + // Not a call to a PHP function. |
|
155 | + return; |
|
156 | + } |
|
157 | + |
|
158 | + $nextToken = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); |
|
159 | + if (isset($ignore[$tokens[$nextToken]['code']]) === true) { |
|
160 | + // Not a call to a PHP function. |
|
161 | + return; |
|
162 | + } |
|
163 | + |
|
164 | + if ($tokens[$stackPtr]['code'] === T_STRING && $tokens[$nextToken]['code'] !== T_OPEN_PARENTHESIS) { |
|
165 | + // Not a call to a PHP function. |
|
166 | + return; |
|
167 | + } |
|
168 | + |
|
169 | + $function = strtolower($tokens[$stackPtr]['content']); |
|
170 | + $pattern = null; |
|
171 | + |
|
172 | + if ($this->patternMatch === true) { |
|
173 | + $count = 0; |
|
174 | + $pattern = preg_replace( |
|
175 | + $this->forbiddenFunctionNames, |
|
176 | + $this->forbiddenFunctionNames, |
|
177 | + $function, |
|
178 | + 1, |
|
179 | + $count |
|
180 | + ); |
|
181 | + |
|
182 | + if ($count === 0) { |
|
183 | + return; |
|
184 | + } |
|
185 | + |
|
186 | + // Remove the pattern delimiters and modifier. |
|
187 | + $pattern = substr($pattern, 1, -2); |
|
188 | + } else { |
|
189 | + if (in_array($function, $this->forbiddenFunctionNames) === false) { |
|
190 | + return; |
|
191 | + } |
|
192 | + }//end if |
|
193 | + |
|
194 | + $this->addError($phpcsFile, $stackPtr, $tokens[$stackPtr]['content'], $pattern); |
|
195 | + |
|
196 | + }//end process() |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * Generates the error or warning for this sniff. |
|
201 | + * |
|
202 | + * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
203 | + * @param int $stackPtr The position of the forbidden function |
|
204 | + * in the token array. |
|
205 | + * @param string $function The name of the forbidden function. |
|
206 | + * @param string $pattern The pattern used for the match. |
|
207 | + * |
|
208 | + * @return void |
|
209 | + */ |
|
210 | + protected function addError($phpcsFile, $stackPtr, $function, $pattern=null) |
|
211 | + { |
|
212 | + $data = array($function); |
|
213 | + $error = 'The use of function %s() is '; |
|
214 | + if ($this->error === true) { |
|
215 | + $type = 'Found'; |
|
216 | + $error .= 'forbidden'; |
|
217 | + } else { |
|
218 | + $type = 'Discouraged'; |
|
219 | + $error .= 'discouraged'; |
|
220 | + } |
|
221 | + |
|
222 | + if ($pattern === null) { |
|
223 | + $pattern = strtolower($function); |
|
224 | + } |
|
225 | + |
|
226 | + if ($this->forbiddenFunctions[$pattern] !== null |
|
227 | + && $this->forbiddenFunctions[$pattern] !== 'null' |
|
228 | + ) { |
|
229 | + $type .= 'WithAlternative'; |
|
230 | + $data[] = $this->forbiddenFunctions[$pattern]; |
|
231 | + $error .= '; use %s() instead'; |
|
232 | + } |
|
233 | + |
|
234 | + if ($this->error === true) { |
|
235 | + $phpcsFile->addError($error, $stackPtr, $type, $data); |
|
236 | + } else { |
|
237 | + $phpcsFile->addWarning($error, $stackPtr, $type, $data); |
|
238 | + } |
|
239 | + |
|
240 | + }//end addError() |
|
241 | 241 | |
242 | 242 | |
243 | 243 | }//end class |
@@ -75,37 +75,37 @@ discard block |
||
75 | 75 | { |
76 | 76 | // Everyone has had a chance to figure out what forbidden functions |
77 | 77 | // they want to check for, so now we can cache out the list. |
78 | - $this->forbiddenFunctionNames = array_keys($this->forbiddenFunctions); |
|
78 | + $this->forbiddenFunctionNames = array_keys( $this->forbiddenFunctions ); |
|
79 | 79 | |
80 | - if ($this->patternMatch === true) { |
|
81 | - foreach ($this->forbiddenFunctionNames as $i => $name) { |
|
82 | - $this->forbiddenFunctionNames[$i] = '/'.$name.'/i'; |
|
80 | + if ( $this->patternMatch === true ) { |
|
81 | + foreach ( $this->forbiddenFunctionNames as $i => $name ) { |
|
82 | + $this->forbiddenFunctionNames[ $i ] = '/' . $name . '/i'; |
|
83 | 83 | } |
84 | 84 | |
85 | - return array(T_STRING); |
|
85 | + return array( T_STRING ); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | // If we are not pattern matching, we need to work out what |
89 | 89 | // tokens to listen for. |
90 | 90 | $string = '<?php '; |
91 | - foreach ($this->forbiddenFunctionNames as $name) { |
|
92 | - $string .= $name.'();'; |
|
91 | + foreach ( $this->forbiddenFunctionNames as $name ) { |
|
92 | + $string .= $name . '();'; |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | $register = array(); |
96 | 96 | |
97 | - $tokens = token_get_all($string); |
|
98 | - array_shift($tokens); |
|
99 | - foreach ($tokens as $token) { |
|
100 | - if (is_array($token) === true) { |
|
101 | - $register[] = $token[0]; |
|
97 | + $tokens = token_get_all( $string ); |
|
98 | + array_shift( $tokens ); |
|
99 | + foreach ( $tokens as $token ) { |
|
100 | + if ( is_array( $token ) === true ) { |
|
101 | + $register[ ] = $token[ 0 ]; |
|
102 | 102 | } |
103 | 103 | } |
104 | 104 | |
105 | - $this->forbiddenFunctionNames = array_map('strtolower', $this->forbiddenFunctionNames); |
|
106 | - $this->forbiddenFunctions = array_combine($this->forbiddenFunctionNames, $this->forbiddenFunctions); |
|
105 | + $this->forbiddenFunctionNames = array_map( 'strtolower', $this->forbiddenFunctionNames ); |
|
106 | + $this->forbiddenFunctions = array_combine( $this->forbiddenFunctionNames, $this->forbiddenFunctions ); |
|
107 | 107 | |
108 | - return array_unique($register); |
|
108 | + return array_unique( $register ); |
|
109 | 109 | |
110 | 110 | }//end register() |
111 | 111 | |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * |
120 | 120 | * @return void |
121 | 121 | */ |
122 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
122 | + public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) |
|
123 | 123 | { |
124 | 124 | $tokens = $phpcsFile->getTokens(); |
125 | 125 | |
@@ -138,38 +138,38 @@ discard block |
||
138 | 138 | T_IMPLEMENTS => true, |
139 | 139 | ); |
140 | 140 | |
141 | - $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); |
|
141 | + $prevToken = $phpcsFile->findPrevious( T_WHITESPACE, ( $stackPtr - 1 ), null, true ); |
|
142 | 142 | |
143 | 143 | // If function call is directly preceded by a NS_SEPARATOR it points to the |
144 | 144 | // global namespace, so we should still catch it. |
145 | - if ($tokens[$prevToken]['code'] === T_NS_SEPARATOR) { |
|
146 | - $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($prevToken - 1), null, true); |
|
147 | - if ($tokens[$prevToken]['code'] === T_STRING) { |
|
145 | + if ( $tokens[ $prevToken ][ 'code' ] === T_NS_SEPARATOR ) { |
|
146 | + $prevToken = $phpcsFile->findPrevious( T_WHITESPACE, ( $prevToken - 1 ), null, true ); |
|
147 | + if ( $tokens[ $prevToken ][ 'code' ] === T_STRING ) { |
|
148 | 148 | // Not in the global namespace. |
149 | 149 | return; |
150 | 150 | } |
151 | 151 | } |
152 | 152 | |
153 | - if (isset($ignore[$tokens[$prevToken]['code']]) === true) { |
|
153 | + if ( isset( $ignore[ $tokens[ $prevToken ][ 'code' ] ] ) === true ) { |
|
154 | 154 | // Not a call to a PHP function. |
155 | 155 | return; |
156 | 156 | } |
157 | 157 | |
158 | - $nextToken = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); |
|
159 | - if (isset($ignore[$tokens[$nextToken]['code']]) === true) { |
|
158 | + $nextToken = $phpcsFile->findNext( T_WHITESPACE, ( $stackPtr + 1 ), null, true ); |
|
159 | + if ( isset( $ignore[ $tokens[ $nextToken ][ 'code' ] ] ) === true ) { |
|
160 | 160 | // Not a call to a PHP function. |
161 | 161 | return; |
162 | 162 | } |
163 | 163 | |
164 | - if ($tokens[$stackPtr]['code'] === T_STRING && $tokens[$nextToken]['code'] !== T_OPEN_PARENTHESIS) { |
|
164 | + if ( $tokens[ $stackPtr ][ 'code' ] === T_STRING && $tokens[ $nextToken ][ 'code' ] !== T_OPEN_PARENTHESIS ) { |
|
165 | 165 | // Not a call to a PHP function. |
166 | 166 | return; |
167 | 167 | } |
168 | 168 | |
169 | - $function = strtolower($tokens[$stackPtr]['content']); |
|
169 | + $function = strtolower( $tokens[ $stackPtr ][ 'content' ] ); |
|
170 | 170 | $pattern = null; |
171 | 171 | |
172 | - if ($this->patternMatch === true) { |
|
172 | + if ( $this->patternMatch === true ) { |
|
173 | 173 | $count = 0; |
174 | 174 | $pattern = preg_replace( |
175 | 175 | $this->forbiddenFunctionNames, |
@@ -179,19 +179,19 @@ discard block |
||
179 | 179 | $count |
180 | 180 | ); |
181 | 181 | |
182 | - if ($count === 0) { |
|
182 | + if ( $count === 0 ) { |
|
183 | 183 | return; |
184 | 184 | } |
185 | 185 | |
186 | 186 | // Remove the pattern delimiters and modifier. |
187 | - $pattern = substr($pattern, 1, -2); |
|
187 | + $pattern = substr( $pattern, 1, -2 ); |
|
188 | 188 | } else { |
189 | - if (in_array($function, $this->forbiddenFunctionNames) === false) { |
|
189 | + if ( in_array( $function, $this->forbiddenFunctionNames ) === false ) { |
|
190 | 190 | return; |
191 | 191 | } |
192 | 192 | }//end if |
193 | 193 | |
194 | - $this->addError($phpcsFile, $stackPtr, $tokens[$stackPtr]['content'], $pattern); |
|
194 | + $this->addError( $phpcsFile, $stackPtr, $tokens[ $stackPtr ][ 'content' ], $pattern ); |
|
195 | 195 | |
196 | 196 | }//end process() |
197 | 197 | |
@@ -207,11 +207,11 @@ discard block |
||
207 | 207 | * |
208 | 208 | * @return void |
209 | 209 | */ |
210 | - protected function addError($phpcsFile, $stackPtr, $function, $pattern=null) |
|
210 | + protected function addError( $phpcsFile, $stackPtr, $function, $pattern = null ) |
|
211 | 211 | { |
212 | - $data = array($function); |
|
212 | + $data = array( $function ); |
|
213 | 213 | $error = 'The use of function %s() is '; |
214 | - if ($this->error === true) { |
|
214 | + if ( $this->error === true ) { |
|
215 | 215 | $type = 'Found'; |
216 | 216 | $error .= 'forbidden'; |
217 | 217 | } else { |
@@ -219,22 +219,22 @@ discard block |
||
219 | 219 | $error .= 'discouraged'; |
220 | 220 | } |
221 | 221 | |
222 | - if ($pattern === null) { |
|
223 | - $pattern = strtolower($function); |
|
222 | + if ( $pattern === null ) { |
|
223 | + $pattern = strtolower( $function ); |
|
224 | 224 | } |
225 | 225 | |
226 | - if ($this->forbiddenFunctions[$pattern] !== null |
|
227 | - && $this->forbiddenFunctions[$pattern] !== 'null' |
|
226 | + if ( $this->forbiddenFunctions[ $pattern ] !== null |
|
227 | + && $this->forbiddenFunctions[ $pattern ] !== 'null' |
|
228 | 228 | ) { |
229 | 229 | $type .= 'WithAlternative'; |
230 | - $data[] = $this->forbiddenFunctions[$pattern]; |
|
230 | + $data[ ] = $this->forbiddenFunctions[ $pattern ]; |
|
231 | 231 | $error .= '; use %s() instead'; |
232 | 232 | } |
233 | 233 | |
234 | - if ($this->error === true) { |
|
235 | - $phpcsFile->addError($error, $stackPtr, $type, $data); |
|
234 | + if ( $this->error === true ) { |
|
235 | + $phpcsFile->addError( $error, $stackPtr, $type, $data ); |
|
236 | 236 | } else { |
237 | - $phpcsFile->addWarning($error, $stackPtr, $type, $data); |
|
237 | + $phpcsFile->addWarning( $error, $stackPtr, $type, $data ); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | }//end addError() |
@@ -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_PHP_ForbiddenFunctionsSniff implements PHP_CodeSniffer_Sniff |
|
32 | -{ |
|
31 | +class Generic_Sniffs_PHP_ForbiddenFunctionsSniff implements PHP_CodeSniffer_Sniff { |
|
33 | 32 | |
34 | 33 | /** |
35 | 34 | * A list of forbidden functions with their alternatives. |
@@ -71,8 +70,7 @@ discard block |
||
71 | 70 | * |
72 | 71 | * @return array |
73 | 72 | */ |
74 | - public function register() |
|
75 | - { |
|
73 | + public function register() { |
|
76 | 74 | // Everyone has had a chance to figure out what forbidden functions |
77 | 75 | // they want to check for, so now we can cache out the list. |
78 | 76 | $this->forbiddenFunctionNames = array_keys($this->forbiddenFunctions); |
@@ -119,8 +117,7 @@ discard block |
||
119 | 117 | * |
120 | 118 | * @return void |
121 | 119 | */ |
122 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
123 | - { |
|
120 | + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { |
|
124 | 121 | $tokens = $phpcsFile->getTokens(); |
125 | 122 | |
126 | 123 | $ignore = array( |
@@ -207,8 +204,7 @@ discard block |
||
207 | 204 | * |
208 | 205 | * @return void |
209 | 206 | */ |
210 | - protected function addError($phpcsFile, $stackPtr, $function, $pattern=null) |
|
211 | - { |
|
207 | + protected function addError($phpcsFile, $stackPtr, $function, $pattern=null) { |
|
212 | 208 | $data = array($function); |
213 | 209 | $error = 'The use of function %s() is '; |
214 | 210 | if ($this->error === true) { |
@@ -27,36 +27,36 @@ |
||
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); |
|
38 | - |
|
39 | - }//end register() |
|
40 | - |
|
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 | - $closeTag = $phpcsFile->findNext(T_CLOSE_TAG, $stackPtr); |
|
54 | - if ($closeTag === false) { |
|
55 | - $error = 'The PHP open tag does not have a corresponding PHP close tag'; |
|
56 | - $phpcsFile->addError($error, $stackPtr, 'NotFound'); |
|
57 | - } |
|
58 | - |
|
59 | - }//end process() |
|
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 | + |
|
39 | + }//end register() |
|
40 | + |
|
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 | + $closeTag = $phpcsFile->findNext(T_CLOSE_TAG, $stackPtr); |
|
54 | + if ($closeTag === false) { |
|
55 | + $error = 'The PHP open tag does not have a corresponding PHP close tag'; |
|
56 | + $phpcsFile->addError($error, $stackPtr, 'NotFound'); |
|
57 | + } |
|
58 | + |
|
59 | + }//end process() |
|
60 | 60 | |
61 | 61 | |
62 | 62 | }//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,12 +48,12 @@ 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 | - $closeTag = $phpcsFile->findNext(T_CLOSE_TAG, $stackPtr); |
|
54 | - if ($closeTag === false) { |
|
53 | + $closeTag = $phpcsFile->findNext( T_CLOSE_TAG, $stackPtr ); |
|
54 | + if ( $closeTag === false ) { |
|
55 | 55 | $error = 'The PHP open tag does not have a corresponding PHP close tag'; |
56 | - $phpcsFile->addError($error, $stackPtr, 'NotFound'); |
|
56 | + $phpcsFile->addError( $error, $stackPtr, 'NotFound' ); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | }//end process() |
@@ -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_ClosingPHPTagSniff implements PHP_CodeSniffer_Sniff |
|
27 | -{ |
|
26 | +class Generic_Sniffs_PHP_ClosingPHPTagSniff 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 | $closeTag = $phpcsFile->findNext(T_CLOSE_TAG, $stackPtr); |
54 | 51 | if ($closeTag === false) { |
55 | 52 | $error = 'The PHP open tag does not have a corresponding PHP close tag'; |
@@ -32,64 +32,64 @@ |
||
32 | 32 | class Generic_Sniffs_PHP_DeprecatedFunctionsSniff extends Generic_Sniffs_PHP_ForbiddenFunctionsSniff |
33 | 33 | { |
34 | 34 | |
35 | - /** |
|
36 | - * A list of forbidden functions with their alternatives. |
|
37 | - * |
|
38 | - * The value is NULL if no alternative exists. IE, the |
|
39 | - * function should just not be used. |
|
40 | - * |
|
41 | - * @var array(string => string|null) |
|
42 | - */ |
|
43 | - public $forbiddenFunctions = array(); |
|
35 | + /** |
|
36 | + * A list of forbidden functions with their alternatives. |
|
37 | + * |
|
38 | + * The value is NULL if no alternative exists. IE, the |
|
39 | + * function should just not be used. |
|
40 | + * |
|
41 | + * @var array(string => string|null) |
|
42 | + */ |
|
43 | + public $forbiddenFunctions = array(); |
|
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * Constructor. |
|
48 | - * |
|
49 | - * Uses the Reflection API to get a list of deprecated functions. |
|
50 | - */ |
|
51 | - public function __construct() |
|
52 | - { |
|
53 | - $functions = get_defined_functions(); |
|
46 | + /** |
|
47 | + * Constructor. |
|
48 | + * |
|
49 | + * Uses the Reflection API to get a list of deprecated functions. |
|
50 | + */ |
|
51 | + public function __construct() |
|
52 | + { |
|
53 | + $functions = get_defined_functions(); |
|
54 | 54 | |
55 | - foreach ($functions['internal'] as $functionName) { |
|
56 | - $function = new ReflectionFunction($functionName); |
|
57 | - if (method_exists($function, 'isDeprecated') === false) { |
|
58 | - break; |
|
59 | - } |
|
55 | + foreach ($functions['internal'] as $functionName) { |
|
56 | + $function = new ReflectionFunction($functionName); |
|
57 | + if (method_exists($function, 'isDeprecated') === false) { |
|
58 | + break; |
|
59 | + } |
|
60 | 60 | |
61 | - if ($function->isDeprecated() === true) { |
|
62 | - $this->forbiddenFunctions[$functionName] = null; |
|
63 | - } |
|
64 | - } |
|
61 | + if ($function->isDeprecated() === true) { |
|
62 | + $this->forbiddenFunctions[$functionName] = null; |
|
63 | + } |
|
64 | + } |
|
65 | 65 | |
66 | - }//end __construct() |
|
66 | + }//end __construct() |
|
67 | 67 | |
68 | 68 | |
69 | - /** |
|
70 | - * Generates the error or warning for this sniff. |
|
71 | - * |
|
72 | - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
73 | - * @param int $stackPtr The position of the forbidden function |
|
74 | - * in the token array. |
|
75 | - * @param string $function The name of the forbidden function. |
|
76 | - * @param string $pattern The pattern used for the match. |
|
77 | - * |
|
78 | - * @return void |
|
79 | - */ |
|
80 | - protected function addError($phpcsFile, $stackPtr, $function, $pattern=null) |
|
81 | - { |
|
82 | - $data = array($function); |
|
83 | - $error = 'Function %s() has been deprecated'; |
|
84 | - $type = 'Deprecated'; |
|
69 | + /** |
|
70 | + * Generates the error or warning for this sniff. |
|
71 | + * |
|
72 | + * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
73 | + * @param int $stackPtr The position of the forbidden function |
|
74 | + * in the token array. |
|
75 | + * @param string $function The name of the forbidden function. |
|
76 | + * @param string $pattern The pattern used for the match. |
|
77 | + * |
|
78 | + * @return void |
|
79 | + */ |
|
80 | + protected function addError($phpcsFile, $stackPtr, $function, $pattern=null) |
|
81 | + { |
|
82 | + $data = array($function); |
|
83 | + $error = 'Function %s() has been deprecated'; |
|
84 | + $type = 'Deprecated'; |
|
85 | 85 | |
86 | - if ($this->error === true) { |
|
87 | - $phpcsFile->addError($error, $stackPtr, $type, $data); |
|
88 | - } else { |
|
89 | - $phpcsFile->addWarning($error, $stackPtr, $type, $data); |
|
90 | - } |
|
86 | + if ($this->error === true) { |
|
87 | + $phpcsFile->addError($error, $stackPtr, $type, $data); |
|
88 | + } else { |
|
89 | + $phpcsFile->addWarning($error, $stackPtr, $type, $data); |
|
90 | + } |
|
91 | 91 | |
92 | - }//end addError() |
|
92 | + }//end addError() |
|
93 | 93 | |
94 | 94 | |
95 | 95 | }//end class |
@@ -52,14 +52,14 @@ discard block |
||
52 | 52 | { |
53 | 53 | $functions = get_defined_functions(); |
54 | 54 | |
55 | - foreach ($functions['internal'] as $functionName) { |
|
56 | - $function = new ReflectionFunction($functionName); |
|
57 | - if (method_exists($function, 'isDeprecated') === false) { |
|
55 | + foreach ( $functions[ 'internal' ] as $functionName ) { |
|
56 | + $function = new ReflectionFunction( $functionName ); |
|
57 | + if ( method_exists( $function, 'isDeprecated' ) === false ) { |
|
58 | 58 | break; |
59 | 59 | } |
60 | 60 | |
61 | - if ($function->isDeprecated() === true) { |
|
62 | - $this->forbiddenFunctions[$functionName] = null; |
|
61 | + if ( $function->isDeprecated() === true ) { |
|
62 | + $this->forbiddenFunctions[ $functionName ] = null; |
|
63 | 63 | } |
64 | 64 | } |
65 | 65 | |
@@ -77,16 +77,16 @@ discard block |
||
77 | 77 | * |
78 | 78 | * @return void |
79 | 79 | */ |
80 | - protected function addError($phpcsFile, $stackPtr, $function, $pattern=null) |
|
80 | + protected function addError( $phpcsFile, $stackPtr, $function, $pattern = null ) |
|
81 | 81 | { |
82 | - $data = array($function); |
|
82 | + $data = array( $function ); |
|
83 | 83 | $error = 'Function %s() has been deprecated'; |
84 | 84 | $type = 'Deprecated'; |
85 | 85 | |
86 | - if ($this->error === true) { |
|
87 | - $phpcsFile->addError($error, $stackPtr, $type, $data); |
|
86 | + if ( $this->error === true ) { |
|
87 | + $phpcsFile->addError( $error, $stackPtr, $type, $data ); |
|
88 | 88 | } else { |
89 | - $phpcsFile->addWarning($error, $stackPtr, $type, $data); |
|
89 | + $phpcsFile->addWarning( $error, $stackPtr, $type, $data ); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | }//end addError() |
@@ -29,8 +29,7 @@ discard block |
||
29 | 29 | * @version Release: @package_version@ |
30 | 30 | * @link http://pear.php.net/package/PHP_CodeSniffer |
31 | 31 | */ |
32 | -class Generic_Sniffs_PHP_DeprecatedFunctionsSniff extends Generic_Sniffs_PHP_ForbiddenFunctionsSniff |
|
33 | -{ |
|
32 | +class Generic_Sniffs_PHP_DeprecatedFunctionsSniff extends Generic_Sniffs_PHP_ForbiddenFunctionsSniff { |
|
34 | 33 | |
35 | 34 | /** |
36 | 35 | * A list of forbidden functions with their alternatives. |
@@ -48,8 +47,7 @@ discard block |
||
48 | 47 | * |
49 | 48 | * Uses the Reflection API to get a list of deprecated functions. |
50 | 49 | */ |
51 | - public function __construct() |
|
52 | - { |
|
50 | + public function __construct() { |
|
53 | 51 | $functions = get_defined_functions(); |
54 | 52 | |
55 | 53 | foreach ($functions['internal'] as $functionName) { |
@@ -77,8 +75,7 @@ discard block |
||
77 | 75 | * |
78 | 76 | * @return void |
79 | 77 | */ |
80 | - protected function addError($phpcsFile, $stackPtr, $function, $pattern=null) |
|
81 | - { |
|
78 | + protected function addError($phpcsFile, $stackPtr, $function, $pattern=null) { |
|
82 | 79 | $data = array($function); |
83 | 80 | $error = 'Function %s() has been deprecated'; |
84 | 81 | $type = 'Deprecated'; |
@@ -29,120 +29,120 @@ |
||
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( |
|
40 | - T_HALT_COMPILER, |
|
41 | - T_ABSTRACT, |
|
42 | - T_ARRAY, |
|
43 | - T_ARRAY_HINT, |
|
44 | - T_AS, |
|
45 | - T_BREAK, |
|
46 | - T_CALLABLE, |
|
47 | - T_CASE, |
|
48 | - T_CATCH, |
|
49 | - T_CLASS, |
|
50 | - T_CLONE, |
|
51 | - T_CONST, |
|
52 | - T_CONTINUE, |
|
53 | - T_DECLARE, |
|
54 | - T_DEFAULT, |
|
55 | - T_DO, |
|
56 | - T_ECHO, |
|
57 | - T_ELSE, |
|
58 | - T_ELSEIF, |
|
59 | - T_EMPTY, |
|
60 | - T_ENDDECLARE, |
|
61 | - T_ENDFOR, |
|
62 | - T_ENDFOREACH, |
|
63 | - T_ENDIF, |
|
64 | - T_ENDSWITCH, |
|
65 | - T_ENDWHILE, |
|
66 | - T_EVAL, |
|
67 | - T_EXIT, |
|
68 | - T_EXTENDS, |
|
69 | - T_FINAL, |
|
70 | - T_FINALLY, |
|
71 | - T_FOR, |
|
72 | - T_FOREACH, |
|
73 | - T_FUNCTION, |
|
74 | - T_GLOBAL, |
|
75 | - T_GOTO, |
|
76 | - T_IF, |
|
77 | - T_IMPLEMENTS, |
|
78 | - T_INCLUDE, |
|
79 | - T_INCLUDE_ONCE, |
|
80 | - T_INSTANCEOF, |
|
81 | - T_INSTEADOF, |
|
82 | - T_INTERFACE, |
|
83 | - T_ISSET, |
|
84 | - T_LIST, |
|
85 | - T_LOGICAL_AND, |
|
86 | - T_LOGICAL_OR, |
|
87 | - T_LOGICAL_XOR, |
|
88 | - T_NAMESPACE, |
|
89 | - T_NEW, |
|
90 | - T_PRINT, |
|
91 | - T_PRIVATE, |
|
92 | - T_PROTECTED, |
|
93 | - T_PUBLIC, |
|
94 | - T_REQUIRE, |
|
95 | - T_REQUIRE_ONCE, |
|
96 | - T_RETURN, |
|
97 | - T_STATIC, |
|
98 | - T_SWITCH, |
|
99 | - T_THROW, |
|
100 | - T_TRAIT, |
|
101 | - T_TRY, |
|
102 | - T_UNSET, |
|
103 | - T_USE, |
|
104 | - T_VAR, |
|
105 | - T_WHILE, |
|
106 | - ); |
|
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( |
|
40 | + T_HALT_COMPILER, |
|
41 | + T_ABSTRACT, |
|
42 | + T_ARRAY, |
|
43 | + T_ARRAY_HINT, |
|
44 | + T_AS, |
|
45 | + T_BREAK, |
|
46 | + T_CALLABLE, |
|
47 | + T_CASE, |
|
48 | + T_CATCH, |
|
49 | + T_CLASS, |
|
50 | + T_CLONE, |
|
51 | + T_CONST, |
|
52 | + T_CONTINUE, |
|
53 | + T_DECLARE, |
|
54 | + T_DEFAULT, |
|
55 | + T_DO, |
|
56 | + T_ECHO, |
|
57 | + T_ELSE, |
|
58 | + T_ELSEIF, |
|
59 | + T_EMPTY, |
|
60 | + T_ENDDECLARE, |
|
61 | + T_ENDFOR, |
|
62 | + T_ENDFOREACH, |
|
63 | + T_ENDIF, |
|
64 | + T_ENDSWITCH, |
|
65 | + T_ENDWHILE, |
|
66 | + T_EVAL, |
|
67 | + T_EXIT, |
|
68 | + T_EXTENDS, |
|
69 | + T_FINAL, |
|
70 | + T_FINALLY, |
|
71 | + T_FOR, |
|
72 | + T_FOREACH, |
|
73 | + T_FUNCTION, |
|
74 | + T_GLOBAL, |
|
75 | + T_GOTO, |
|
76 | + T_IF, |
|
77 | + T_IMPLEMENTS, |
|
78 | + T_INCLUDE, |
|
79 | + T_INCLUDE_ONCE, |
|
80 | + T_INSTANCEOF, |
|
81 | + T_INSTEADOF, |
|
82 | + T_INTERFACE, |
|
83 | + T_ISSET, |
|
84 | + T_LIST, |
|
85 | + T_LOGICAL_AND, |
|
86 | + T_LOGICAL_OR, |
|
87 | + T_LOGICAL_XOR, |
|
88 | + T_NAMESPACE, |
|
89 | + T_NEW, |
|
90 | + T_PRINT, |
|
91 | + T_PRIVATE, |
|
92 | + T_PROTECTED, |
|
93 | + T_PUBLIC, |
|
94 | + T_REQUIRE, |
|
95 | + T_REQUIRE_ONCE, |
|
96 | + T_RETURN, |
|
97 | + T_STATIC, |
|
98 | + T_SWITCH, |
|
99 | + T_THROW, |
|
100 | + T_TRAIT, |
|
101 | + T_TRY, |
|
102 | + T_UNSET, |
|
103 | + T_USE, |
|
104 | + T_VAR, |
|
105 | + T_WHILE, |
|
106 | + ); |
|
107 | 107 | |
108 | - }//end register() |
|
108 | + }//end register() |
|
109 | 109 | |
110 | 110 | |
111 | - /** |
|
112 | - * Processes this sniff, when one of its tokens is encountered. |
|
113 | - * |
|
114 | - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
115 | - * @param int $stackPtr The position of the current token in the |
|
116 | - * stack passed in $tokens. |
|
117 | - * |
|
118 | - * @return void |
|
119 | - */ |
|
120 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
121 | - { |
|
122 | - $tokens = $phpcsFile->getTokens(); |
|
123 | - $keyword = $tokens[$stackPtr]['content']; |
|
124 | - if (strtolower($keyword) !== $keyword) { |
|
125 | - if ($keyword === strtoupper($keyword)) { |
|
126 | - $phpcsFile->recordMetric($stackPtr, 'PHP keyword case', 'upper'); |
|
127 | - } else { |
|
128 | - $phpcsFile->recordMetric($stackPtr, 'PHP keyword case', 'mixed'); |
|
129 | - } |
|
111 | + /** |
|
112 | + * Processes this sniff, when one of its tokens is encountered. |
|
113 | + * |
|
114 | + * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
115 | + * @param int $stackPtr The position of the current token in the |
|
116 | + * stack passed in $tokens. |
|
117 | + * |
|
118 | + * @return void |
|
119 | + */ |
|
120 | + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
121 | + { |
|
122 | + $tokens = $phpcsFile->getTokens(); |
|
123 | + $keyword = $tokens[$stackPtr]['content']; |
|
124 | + if (strtolower($keyword) !== $keyword) { |
|
125 | + if ($keyword === strtoupper($keyword)) { |
|
126 | + $phpcsFile->recordMetric($stackPtr, 'PHP keyword case', 'upper'); |
|
127 | + } else { |
|
128 | + $phpcsFile->recordMetric($stackPtr, 'PHP keyword case', 'mixed'); |
|
129 | + } |
|
130 | 130 | |
131 | - $error = 'PHP keywords must be lowercase; expected "%s" but found "%s"'; |
|
132 | - $data = array( |
|
133 | - strtolower($keyword), |
|
134 | - $keyword, |
|
135 | - ); |
|
131 | + $error = 'PHP keywords must be lowercase; expected "%s" but found "%s"'; |
|
132 | + $data = array( |
|
133 | + strtolower($keyword), |
|
134 | + $keyword, |
|
135 | + ); |
|
136 | 136 | |
137 | - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found', $data); |
|
138 | - if ($fix === true) { |
|
139 | - $phpcsFile->fixer->replaceToken($stackPtr, strtolower($keyword)); |
|
140 | - } |
|
141 | - } else { |
|
142 | - $phpcsFile->recordMetric($stackPtr, 'PHP keyword case', 'lower'); |
|
143 | - } |
|
137 | + $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found', $data); |
|
138 | + if ($fix === true) { |
|
139 | + $phpcsFile->fixer->replaceToken($stackPtr, strtolower($keyword)); |
|
140 | + } |
|
141 | + } else { |
|
142 | + $phpcsFile->recordMetric($stackPtr, 'PHP keyword case', 'lower'); |
|
143 | + } |
|
144 | 144 | |
145 | - }//end process() |
|
145 | + }//end process() |
|
146 | 146 | |
147 | 147 | |
148 | 148 | }//end class |
@@ -117,29 +117,29 @@ |
||
117 | 117 | * |
118 | 118 | * @return void |
119 | 119 | */ |
120 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
120 | + public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) |
|
121 | 121 | { |
122 | 122 | $tokens = $phpcsFile->getTokens(); |
123 | - $keyword = $tokens[$stackPtr]['content']; |
|
124 | - if (strtolower($keyword) !== $keyword) { |
|
125 | - if ($keyword === strtoupper($keyword)) { |
|
126 | - $phpcsFile->recordMetric($stackPtr, 'PHP keyword case', 'upper'); |
|
123 | + $keyword = $tokens[ $stackPtr ][ 'content' ]; |
|
124 | + if ( strtolower( $keyword ) !== $keyword ) { |
|
125 | + if ( $keyword === strtoupper( $keyword ) ) { |
|
126 | + $phpcsFile->recordMetric( $stackPtr, 'PHP keyword case', 'upper' ); |
|
127 | 127 | } else { |
128 | - $phpcsFile->recordMetric($stackPtr, 'PHP keyword case', 'mixed'); |
|
128 | + $phpcsFile->recordMetric( $stackPtr, 'PHP keyword case', 'mixed' ); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | $error = 'PHP keywords must be lowercase; expected "%s" but found "%s"'; |
132 | 132 | $data = array( |
133 | - strtolower($keyword), |
|
133 | + strtolower( $keyword ), |
|
134 | 134 | $keyword, |
135 | 135 | ); |
136 | 136 | |
137 | - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found', $data); |
|
138 | - if ($fix === true) { |
|
139 | - $phpcsFile->fixer->replaceToken($stackPtr, strtolower($keyword)); |
|
137 | + $fix = $phpcsFile->addFixableError( $error, $stackPtr, 'Found', $data ); |
|
138 | + if ( $fix === true ) { |
|
139 | + $phpcsFile->fixer->replaceToken( $stackPtr, strtolower( $keyword ) ); |
|
140 | 140 | } |
141 | 141 | } else { |
142 | - $phpcsFile->recordMetric($stackPtr, 'PHP keyword case', 'lower'); |
|
142 | + $phpcsFile->recordMetric( $stackPtr, 'PHP keyword case', 'lower' ); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | }//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_LowerCaseKeywordSniff implements PHP_CodeSniffer_Sniff |
|
29 | -{ |
|
28 | +class Generic_Sniffs_PHP_LowerCaseKeywordSniff 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( |
40 | 38 | T_HALT_COMPILER, |
41 | 39 | T_ABSTRACT, |
@@ -117,8 +115,7 @@ discard block |
||
117 | 115 | * |
118 | 116 | * @return void |
119 | 117 | */ |
120 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
121 | - { |
|
118 | + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { |
|
122 | 119 | $tokens = $phpcsFile->getTokens(); |
123 | 120 | $keyword = $tokens[$stackPtr]['content']; |
124 | 121 | if (strtolower($keyword) !== $keyword) { |