@@ -28,70 +28,70 @@ |
||
| 28 | 28 | class NewConstantArraysUsingDefineSniff extends Sniff |
| 29 | 29 | { |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Returns an array of tokens this test wants to listen for. |
|
| 33 | - * |
|
| 34 | - * @return array |
|
| 35 | - */ |
|
| 36 | - public function register() |
|
| 37 | - { |
|
| 38 | - return array(\T_STRING); |
|
| 39 | - } |
|
| 31 | + /** |
|
| 32 | + * Returns an array of tokens this test wants to listen for. |
|
| 33 | + * |
|
| 34 | + * @return array |
|
| 35 | + */ |
|
| 36 | + public function register() |
|
| 37 | + { |
|
| 38 | + return array(\T_STRING); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Processes this test, when one of its tokens is encountered. |
|
| 43 | - * |
|
| 44 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 45 | - * @param int $stackPtr The position of the current token in the |
|
| 46 | - * stack passed in $tokens. |
|
| 47 | - * |
|
| 48 | - * @return void |
|
| 49 | - */ |
|
| 50 | - public function process(File $phpcsFile, $stackPtr) |
|
| 51 | - { |
|
| 52 | - if ($this->supportsBelow('5.6') !== true) { |
|
| 53 | - return; |
|
| 54 | - } |
|
| 41 | + /** |
|
| 42 | + * Processes this test, when one of its tokens is encountered. |
|
| 43 | + * |
|
| 44 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 45 | + * @param int $stackPtr The position of the current token in the |
|
| 46 | + * stack passed in $tokens. |
|
| 47 | + * |
|
| 48 | + * @return void |
|
| 49 | + */ |
|
| 50 | + public function process(File $phpcsFile, $stackPtr) |
|
| 51 | + { |
|
| 52 | + if ($this->supportsBelow('5.6') !== true) { |
|
| 53 | + return; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - $tokens = $phpcsFile->getTokens(); |
|
| 56 | + $tokens = $phpcsFile->getTokens(); |
|
| 57 | 57 | |
| 58 | - $ignore = array( |
|
| 59 | - \T_DOUBLE_COLON => true, |
|
| 60 | - \T_OBJECT_OPERATOR => true, |
|
| 61 | - \T_FUNCTION => true, |
|
| 62 | - \T_CONST => true, |
|
| 63 | - ); |
|
| 58 | + $ignore = array( |
|
| 59 | + \T_DOUBLE_COLON => true, |
|
| 60 | + \T_OBJECT_OPERATOR => true, |
|
| 61 | + \T_FUNCTION => true, |
|
| 62 | + \T_CONST => true, |
|
| 63 | + ); |
|
| 64 | 64 | |
| 65 | - $prevToken = $phpcsFile->findPrevious(\T_WHITESPACE, ($stackPtr - 1), null, true); |
|
| 66 | - if (isset($ignore[$tokens[$prevToken]['code']]) === true) { |
|
| 67 | - // Not a call to a PHP function. |
|
| 68 | - return; |
|
| 69 | - } |
|
| 65 | + $prevToken = $phpcsFile->findPrevious(\T_WHITESPACE, ($stackPtr - 1), null, true); |
|
| 66 | + if (isset($ignore[$tokens[$prevToken]['code']]) === true) { |
|
| 67 | + // Not a call to a PHP function. |
|
| 68 | + return; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - $functionLc = strtolower($tokens[$stackPtr]['content']); |
|
| 72 | - if ($functionLc !== 'define') { |
|
| 73 | - return; |
|
| 74 | - } |
|
| 71 | + $functionLc = strtolower($tokens[$stackPtr]['content']); |
|
| 72 | + if ($functionLc !== 'define') { |
|
| 73 | + return; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - $secondParam = $this->getFunctionCallParameter($phpcsFile, $stackPtr, 2); |
|
| 77 | - if (isset($secondParam['start'], $secondParam['end']) === false) { |
|
| 78 | - return; |
|
| 79 | - } |
|
| 76 | + $secondParam = $this->getFunctionCallParameter($phpcsFile, $stackPtr, 2); |
|
| 77 | + if (isset($secondParam['start'], $secondParam['end']) === false) { |
|
| 78 | + return; |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - $targetNestingLevel = 0; |
|
| 82 | - if (isset($tokens[$secondParam['start']]['nested_parenthesis'])) { |
|
| 83 | - $targetNestingLevel = \count($tokens[$secondParam['start']]['nested_parenthesis']); |
|
| 84 | - } |
|
| 81 | + $targetNestingLevel = 0; |
|
| 82 | + if (isset($tokens[$secondParam['start']]['nested_parenthesis'])) { |
|
| 83 | + $targetNestingLevel = \count($tokens[$secondParam['start']]['nested_parenthesis']); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - $array = $phpcsFile->findNext(array(\T_ARRAY, \T_OPEN_SHORT_ARRAY), $secondParam['start'], ($secondParam['end'] + 1)); |
|
| 87 | - if ($array !== false) { |
|
| 88 | - if ((isset($tokens[$array]['nested_parenthesis']) === false && $targetNestingLevel === 0) || \count($tokens[$array]['nested_parenthesis']) === $targetNestingLevel) { |
|
| 89 | - $phpcsFile->addError( |
|
| 90 | - 'Constant arrays using define are not allowed in PHP 5.6 or earlier', |
|
| 91 | - $array, |
|
| 92 | - 'Found' |
|
| 93 | - ); |
|
| 94 | - } |
|
| 95 | - } |
|
| 96 | - } |
|
| 86 | + $array = $phpcsFile->findNext(array(\T_ARRAY, \T_OPEN_SHORT_ARRAY), $secondParam['start'], ($secondParam['end'] + 1)); |
|
| 87 | + if ($array !== false) { |
|
| 88 | + if ((isset($tokens[$array]['nested_parenthesis']) === false && $targetNestingLevel === 0) || \count($tokens[$array]['nested_parenthesis']) === $targetNestingLevel) { |
|
| 89 | + $phpcsFile->addError( |
|
| 90 | + 'Constant arrays using define are not allowed in PHP 5.6 or earlier', |
|
| 91 | + $array, |
|
| 92 | + 'Found' |
|
| 93 | + ); |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | 97 | } |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | public function register() |
| 37 | 37 | { |
| 38 | - return array(\T_STRING); |
|
| 38 | + return array( \T_STRING ); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | /** |
@@ -47,9 +47,9 @@ discard block |
||
| 47 | 47 | * |
| 48 | 48 | * @return void |
| 49 | 49 | */ |
| 50 | - public function process(File $phpcsFile, $stackPtr) |
|
| 50 | + public function process( File $phpcsFile, $stackPtr ) |
|
| 51 | 51 | { |
| 52 | - if ($this->supportsBelow('5.6') !== true) { |
|
| 52 | + if ( $this->supportsBelow( '5.6' ) !== true ) { |
|
| 53 | 53 | return; |
| 54 | 54 | } |
| 55 | 55 | |
@@ -62,30 +62,30 @@ discard block |
||
| 62 | 62 | \T_CONST => true, |
| 63 | 63 | ); |
| 64 | 64 | |
| 65 | - $prevToken = $phpcsFile->findPrevious(\T_WHITESPACE, ($stackPtr - 1), null, true); |
|
| 66 | - if (isset($ignore[$tokens[$prevToken]['code']]) === true) { |
|
| 65 | + $prevToken = $phpcsFile->findPrevious( \T_WHITESPACE, ( $stackPtr - 1 ), null, true ); |
|
| 66 | + if ( isset( $ignore[ $tokens[ $prevToken ][ 'code' ] ] ) === true ) { |
|
| 67 | 67 | // Not a call to a PHP function. |
| 68 | 68 | return; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - $functionLc = strtolower($tokens[$stackPtr]['content']); |
|
| 72 | - if ($functionLc !== 'define') { |
|
| 71 | + $functionLc = strtolower( $tokens[ $stackPtr ][ 'content' ] ); |
|
| 72 | + if ( $functionLc !== 'define' ) { |
|
| 73 | 73 | return; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - $secondParam = $this->getFunctionCallParameter($phpcsFile, $stackPtr, 2); |
|
| 77 | - if (isset($secondParam['start'], $secondParam['end']) === false) { |
|
| 76 | + $secondParam = $this->getFunctionCallParameter( $phpcsFile, $stackPtr, 2 ); |
|
| 77 | + if ( isset( $secondParam[ 'start' ], $secondParam[ 'end' ] ) === false ) { |
|
| 78 | 78 | return; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | $targetNestingLevel = 0; |
| 82 | - if (isset($tokens[$secondParam['start']]['nested_parenthesis'])) { |
|
| 83 | - $targetNestingLevel = \count($tokens[$secondParam['start']]['nested_parenthesis']); |
|
| 82 | + if ( isset( $tokens[ $secondParam[ 'start' ] ][ 'nested_parenthesis' ] ) ) { |
|
| 83 | + $targetNestingLevel = \count( $tokens[ $secondParam[ 'start' ] ][ 'nested_parenthesis' ] ); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - $array = $phpcsFile->findNext(array(\T_ARRAY, \T_OPEN_SHORT_ARRAY), $secondParam['start'], ($secondParam['end'] + 1)); |
|
| 87 | - if ($array !== false) { |
|
| 88 | - if ((isset($tokens[$array]['nested_parenthesis']) === false && $targetNestingLevel === 0) || \count($tokens[$array]['nested_parenthesis']) === $targetNestingLevel) { |
|
| 86 | + $array = $phpcsFile->findNext( array( \T_ARRAY, \T_OPEN_SHORT_ARRAY ), $secondParam[ 'start' ], ( $secondParam[ 'end' ] + 1 ) ); |
|
| 87 | + if ( $array !== false ) { |
|
| 88 | + if ( ( isset( $tokens[ $array ][ 'nested_parenthesis' ] ) === false && $targetNestingLevel === 0 ) || \count( $tokens[ $array ][ 'nested_parenthesis' ] ) === $targetNestingLevel ) { |
|
| 89 | 89 | $phpcsFile->addError( |
| 90 | 90 | 'Constant arrays using define are not allowed in PHP 5.6 or earlier', |
| 91 | 91 | $array, |
@@ -25,16 +25,14 @@ discard block |
||
| 25 | 25 | * @package PHPCompatibility |
| 26 | 26 | * @author Wim Godden <[email protected]> |
| 27 | 27 | */ |
| 28 | -class NewConstantArraysUsingDefineSniff extends Sniff |
|
| 29 | -{ |
|
| 28 | +class NewConstantArraysUsingDefineSniff extends Sniff { |
|
| 30 | 29 | |
| 31 | 30 | /** |
| 32 | 31 | * Returns an array of tokens this test wants to listen for. |
| 33 | 32 | * |
| 34 | 33 | * @return array |
| 35 | 34 | */ |
| 36 | - public function register() |
|
| 37 | - { |
|
| 35 | + public function register() { |
|
| 38 | 36 | return array(\T_STRING); |
| 39 | 37 | } |
| 40 | 38 | |
@@ -47,8 +45,7 @@ discard block |
||
| 47 | 45 | * |
| 48 | 46 | * @return void |
| 49 | 47 | */ |
| 50 | - public function process(File $phpcsFile, $stackPtr) |
|
| 51 | - { |
|
| 48 | + public function process(File $phpcsFile, $stackPtr) { |
|
| 52 | 49 | if ($this->supportsBelow('5.6') !== true) { |
| 53 | 50 | return; |
| 54 | 51 | } |
@@ -65,7 +65,7 @@ |
||
| 65 | 65 | /** |
| 66 | 66 | * Returns an array of tokens this test wants to listen for. |
| 67 | 67 | * |
| 68 | - * @return array |
|
| 68 | + * @return integer[] |
|
| 69 | 69 | */ |
| 70 | 70 | public function register() |
| 71 | 71 | { |
@@ -35,56 +35,56 @@ |
||
| 35 | 35 | class NewHeredocSniff extends NewConstantScalarExpressionsSniff |
| 36 | 36 | { |
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Error message. |
|
| 40 | - * |
|
| 41 | - * @var string |
|
| 42 | - */ |
|
| 43 | - const ERROR_PHRASE = 'Initializing %s using the Heredoc syntax was not supported in PHP 5.2 or earlier'; |
|
| 38 | + /** |
|
| 39 | + * Error message. |
|
| 40 | + * |
|
| 41 | + * @var string |
|
| 42 | + */ |
|
| 43 | + const ERROR_PHRASE = 'Initializing %s using the Heredoc syntax was not supported in PHP 5.2 or earlier'; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Partial error phrases to be used in combination with the error message constant. |
|
| 47 | - * |
|
| 48 | - * @var array |
|
| 49 | - */ |
|
| 50 | - protected $errorPhrases = array( |
|
| 51 | - 'const' => 'constants', |
|
| 52 | - 'property' => 'class properties', |
|
| 53 | - 'staticvar' => 'static variables', |
|
| 54 | - 'default' => 'default parameter values', |
|
| 55 | - ); |
|
| 45 | + /** |
|
| 46 | + * Partial error phrases to be used in combination with the error message constant. |
|
| 47 | + * |
|
| 48 | + * @var array |
|
| 49 | + */ |
|
| 50 | + protected $errorPhrases = array( |
|
| 51 | + 'const' => 'constants', |
|
| 52 | + 'property' => 'class properties', |
|
| 53 | + 'staticvar' => 'static variables', |
|
| 54 | + 'default' => 'default parameter values', |
|
| 55 | + ); |
|
| 56 | 56 | |
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Do a version check to determine if this sniff needs to run at all. |
|
| 60 | - * |
|
| 61 | - * @return bool |
|
| 62 | - */ |
|
| 63 | - protected function bowOutEarly() |
|
| 64 | - { |
|
| 65 | - return ($this->supportsBelow('5.2') !== true); |
|
| 66 | - } |
|
| 58 | + /** |
|
| 59 | + * Do a version check to determine if this sniff needs to run at all. |
|
| 60 | + * |
|
| 61 | + * @return bool |
|
| 62 | + */ |
|
| 63 | + protected function bowOutEarly() |
|
| 64 | + { |
|
| 65 | + return ($this->supportsBelow('5.2') !== true); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Is a value declared and does the declared value not contain an heredoc ? |
|
| 71 | - * |
|
| 72 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 73 | - * @param int $stackPtr The position of the current token in the |
|
| 74 | - * stack passed in $tokens. |
|
| 75 | - * @param int $end The end of the value definition. |
|
| 76 | - * |
|
| 77 | - * @return bool True if no heredoc (or assignment) is found, false otherwise. |
|
| 78 | - */ |
|
| 79 | - protected function isValidAssignment(File $phpcsFile, $stackPtr, $end) |
|
| 80 | - { |
|
| 81 | - $tokens = $phpcsFile->getTokens(); |
|
| 82 | - $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), $end, true); |
|
| 83 | - if ($next === false || $tokens[$next]['code'] !== \T_EQUAL) { |
|
| 84 | - // No value assigned. |
|
| 85 | - return true; |
|
| 86 | - } |
|
| 69 | + /** |
|
| 70 | + * Is a value declared and does the declared value not contain an heredoc ? |
|
| 71 | + * |
|
| 72 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 73 | + * @param int $stackPtr The position of the current token in the |
|
| 74 | + * stack passed in $tokens. |
|
| 75 | + * @param int $end The end of the value definition. |
|
| 76 | + * |
|
| 77 | + * @return bool True if no heredoc (or assignment) is found, false otherwise. |
|
| 78 | + */ |
|
| 79 | + protected function isValidAssignment(File $phpcsFile, $stackPtr, $end) |
|
| 80 | + { |
|
| 81 | + $tokens = $phpcsFile->getTokens(); |
|
| 82 | + $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), $end, true); |
|
| 83 | + if ($next === false || $tokens[$next]['code'] !== \T_EQUAL) { |
|
| 84 | + // No value assigned. |
|
| 85 | + return true; |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - return ($phpcsFile->findNext(\T_START_HEREDOC, ($next + 1), $end, false, null, true) === false); |
|
| 89 | - } |
|
| 88 | + return ($phpcsFile->findNext(\T_START_HEREDOC, ($next + 1), $end, false, null, true) === false); |
|
| 89 | + } |
|
| 90 | 90 | } |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | */ |
| 63 | 63 | protected function bowOutEarly() |
| 64 | 64 | { |
| 65 | - return ($this->supportsBelow('5.2') !== true); |
|
| 65 | + return ( $this->supportsBelow( '5.2' ) !== true ); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | |
@@ -76,15 +76,15 @@ discard block |
||
| 76 | 76 | * |
| 77 | 77 | * @return bool True if no heredoc (or assignment) is found, false otherwise. |
| 78 | 78 | */ |
| 79 | - protected function isValidAssignment(File $phpcsFile, $stackPtr, $end) |
|
| 79 | + protected function isValidAssignment( File $phpcsFile, $stackPtr, $end ) |
|
| 80 | 80 | { |
| 81 | 81 | $tokens = $phpcsFile->getTokens(); |
| 82 | - $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), $end, true); |
|
| 83 | - if ($next === false || $tokens[$next]['code'] !== \T_EQUAL) { |
|
| 82 | + $next = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), $end, true ); |
|
| 83 | + if ( $next === false || $tokens[ $next ][ 'code' ] !== \T_EQUAL ) { |
|
| 84 | 84 | // No value assigned. |
| 85 | 85 | return true; |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - return ($phpcsFile->findNext(\T_START_HEREDOC, ($next + 1), $end, false, null, true) === false); |
|
| 88 | + return ( $phpcsFile->findNext( \T_START_HEREDOC, ( $next + 1 ), $end, false, null, true ) === false ); |
|
| 89 | 89 | } |
| 90 | 90 | } |
@@ -32,8 +32,7 @@ discard block |
||
| 32 | 32 | * @package PHPCompatibility |
| 33 | 33 | * @author Juliette Reinders Folmer <[email protected]> |
| 34 | 34 | */ |
| 35 | -class NewHeredocSniff extends NewConstantScalarExpressionsSniff |
|
| 36 | -{ |
|
| 35 | +class NewHeredocSniff extends NewConstantScalarExpressionsSniff { |
|
| 37 | 36 | |
| 38 | 37 | /** |
| 39 | 38 | * Error message. |
@@ -60,8 +59,7 @@ discard block |
||
| 60 | 59 | * |
| 61 | 60 | * @return bool |
| 62 | 61 | */ |
| 63 | - protected function bowOutEarly() |
|
| 64 | - { |
|
| 62 | + protected function bowOutEarly() { |
|
| 65 | 63 | return ($this->supportsBelow('5.2') !== true); |
| 66 | 64 | } |
| 67 | 65 | |
@@ -76,8 +74,7 @@ discard block |
||
| 76 | 74 | * |
| 77 | 75 | * @return bool True if no heredoc (or assignment) is found, false otherwise. |
| 78 | 76 | */ |
| 79 | - protected function isValidAssignment(File $phpcsFile, $stackPtr, $end) |
|
| 80 | - { |
|
| 77 | + protected function isValidAssignment(File $phpcsFile, $stackPtr, $end) { |
|
| 81 | 78 | $tokens = $phpcsFile->getTokens(); |
| 82 | 79 | $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), $end, true); |
| 83 | 80 | if ($next === false || $tokens[$next]['code'] !== \T_EQUAL) { |
@@ -29,59 +29,59 @@ |
||
| 29 | 29 | class NewAnonymousClassesSniff extends Sniff |
| 30 | 30 | { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Tokens which in various PHP versions indicate the `class` keyword. |
|
| 34 | - * |
|
| 35 | - * The dedicated anonymous class token is added from the `register()` |
|
| 36 | - * method if the token is available. |
|
| 37 | - * |
|
| 38 | - * @var array |
|
| 39 | - */ |
|
| 40 | - private $indicators = array( |
|
| 41 | - \T_CLASS => \T_CLASS, |
|
| 42 | - ); |
|
| 32 | + /** |
|
| 33 | + * Tokens which in various PHP versions indicate the `class` keyword. |
|
| 34 | + * |
|
| 35 | + * The dedicated anonymous class token is added from the `register()` |
|
| 36 | + * method if the token is available. |
|
| 37 | + * |
|
| 38 | + * @var array |
|
| 39 | + */ |
|
| 40 | + private $indicators = array( |
|
| 41 | + \T_CLASS => \T_CLASS, |
|
| 42 | + ); |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Returns an array of tokens this test wants to listen for. |
|
| 46 | - * |
|
| 47 | - * @return array |
|
| 48 | - */ |
|
| 49 | - public function register() |
|
| 50 | - { |
|
| 51 | - if (\defined('T_ANON_CLASS')) { |
|
| 52 | - $this->indicators[\T_ANON_CLASS] = \T_ANON_CLASS; |
|
| 53 | - } |
|
| 44 | + /** |
|
| 45 | + * Returns an array of tokens this test wants to listen for. |
|
| 46 | + * |
|
| 47 | + * @return array |
|
| 48 | + */ |
|
| 49 | + public function register() |
|
| 50 | + { |
|
| 51 | + if (\defined('T_ANON_CLASS')) { |
|
| 52 | + $this->indicators[\T_ANON_CLASS] = \T_ANON_CLASS; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - return array(\T_NEW); |
|
| 56 | - } |
|
| 55 | + return array(\T_NEW); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Processes this test, when one of its tokens is encountered. |
|
| 61 | - * |
|
| 62 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 63 | - * @param int $stackPtr The position of the current token in the |
|
| 64 | - * stack passed in $tokens. |
|
| 65 | - * |
|
| 66 | - * @return void |
|
| 67 | - */ |
|
| 68 | - public function process(File $phpcsFile, $stackPtr) |
|
| 69 | - { |
|
| 70 | - if ($this->supportsBelow('5.6') === false) { |
|
| 71 | - return; |
|
| 72 | - } |
|
| 59 | + /** |
|
| 60 | + * Processes this test, when one of its tokens is encountered. |
|
| 61 | + * |
|
| 62 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 63 | + * @param int $stackPtr The position of the current token in the |
|
| 64 | + * stack passed in $tokens. |
|
| 65 | + * |
|
| 66 | + * @return void |
|
| 67 | + */ |
|
| 68 | + public function process(File $phpcsFile, $stackPtr) |
|
| 69 | + { |
|
| 70 | + if ($this->supportsBelow('5.6') === false) { |
|
| 71 | + return; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - $tokens = $phpcsFile->getTokens(); |
|
| 75 | - $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true); |
|
| 76 | - if ($nextNonEmpty === false || isset($this->indicators[$tokens[$nextNonEmpty]['code']]) === false) { |
|
| 77 | - return; |
|
| 78 | - } |
|
| 74 | + $tokens = $phpcsFile->getTokens(); |
|
| 75 | + $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true); |
|
| 76 | + if ($nextNonEmpty === false || isset($this->indicators[$tokens[$nextNonEmpty]['code']]) === false) { |
|
| 77 | + return; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - // Still here ? In that case, it is an anonymous class. |
|
| 81 | - $phpcsFile->addError( |
|
| 82 | - 'Anonymous classes are not supported in PHP 5.6 or earlier', |
|
| 83 | - $stackPtr, |
|
| 84 | - 'Found' |
|
| 85 | - ); |
|
| 86 | - } |
|
| 80 | + // Still here ? In that case, it is an anonymous class. |
|
| 81 | + $phpcsFile->addError( |
|
| 82 | + 'Anonymous classes are not supported in PHP 5.6 or earlier', |
|
| 83 | + $stackPtr, |
|
| 84 | + 'Found' |
|
| 85 | + ); |
|
| 86 | + } |
|
| 87 | 87 | } |
@@ -48,11 +48,11 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | public function register() |
| 50 | 50 | { |
| 51 | - if (\defined('T_ANON_CLASS')) { |
|
| 52 | - $this->indicators[\T_ANON_CLASS] = \T_ANON_CLASS; |
|
| 51 | + if ( \defined( 'T_ANON_CLASS' ) ) { |
|
| 52 | + $this->indicators[ \T_ANON_CLASS ] = \T_ANON_CLASS; |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - return array(\T_NEW); |
|
| 55 | + return array( \T_NEW ); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | |
@@ -65,15 +65,15 @@ discard block |
||
| 65 | 65 | * |
| 66 | 66 | * @return void |
| 67 | 67 | */ |
| 68 | - public function process(File $phpcsFile, $stackPtr) |
|
| 68 | + public function process( File $phpcsFile, $stackPtr ) |
|
| 69 | 69 | { |
| 70 | - if ($this->supportsBelow('5.6') === false) { |
|
| 70 | + if ( $this->supportsBelow( '5.6' ) === false ) { |
|
| 71 | 71 | return; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | $tokens = $phpcsFile->getTokens(); |
| 75 | - $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true); |
|
| 76 | - if ($nextNonEmpty === false || isset($this->indicators[$tokens[$nextNonEmpty]['code']]) === false) { |
|
| 75 | + $nextNonEmpty = $phpcsFile->findNext( Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true ); |
|
| 76 | + if ( $nextNonEmpty === false || isset( $this->indicators[ $tokens[ $nextNonEmpty ][ 'code' ] ] ) === false ) { |
|
| 77 | 77 | return; |
| 78 | 78 | } |
| 79 | 79 | |
@@ -26,8 +26,7 @@ discard block |
||
| 26 | 26 | * @package PHPCompatibility |
| 27 | 27 | * @author Wim Godden <[email protected]> |
| 28 | 28 | */ |
| 29 | -class NewAnonymousClassesSniff extends Sniff |
|
| 30 | -{ |
|
| 29 | +class NewAnonymousClassesSniff extends Sniff { |
|
| 31 | 30 | |
| 32 | 31 | /** |
| 33 | 32 | * Tokens which in various PHP versions indicate the `class` keyword. |
@@ -46,8 +45,7 @@ discard block |
||
| 46 | 45 | * |
| 47 | 46 | * @return array |
| 48 | 47 | */ |
| 49 | - public function register() |
|
| 50 | - { |
|
| 48 | + public function register() { |
|
| 51 | 49 | if (\defined('T_ANON_CLASS')) { |
| 52 | 50 | $this->indicators[\T_ANON_CLASS] = \T_ANON_CLASS; |
| 53 | 51 | } |
@@ -65,8 +63,7 @@ discard block |
||
| 65 | 63 | * |
| 66 | 64 | * @return void |
| 67 | 65 | */ |
| 68 | - public function process(File $phpcsFile, $stackPtr) |
|
| 69 | - { |
|
| 66 | + public function process(File $phpcsFile, $stackPtr) { |
|
| 70 | 67 | if ($this->supportsBelow('5.6') === false) { |
| 71 | 68 | return; |
| 72 | 69 | } |
@@ -65,7 +65,7 @@ |
||
| 65 | 65 | /** |
| 66 | 66 | * Returns an array of tokens this test wants to listen for. |
| 67 | 67 | * |
| 68 | - * @return array |
|
| 68 | + * @return integer[] |
|
| 69 | 69 | */ |
| 70 | 70 | public function register() |
| 71 | 71 | { |
@@ -28,51 +28,51 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | class NewConstVisibilitySniff extends Sniff |
| 30 | 30 | { |
| 31 | - /** |
|
| 32 | - * Returns an array of tokens this test wants to listen for. |
|
| 33 | - * |
|
| 34 | - * @return array |
|
| 35 | - */ |
|
| 36 | - public function register() |
|
| 37 | - { |
|
| 38 | - return array(\T_CONST); |
|
| 39 | - } |
|
| 31 | + /** |
|
| 32 | + * Returns an array of tokens this test wants to listen for. |
|
| 33 | + * |
|
| 34 | + * @return array |
|
| 35 | + */ |
|
| 36 | + public function register() |
|
| 37 | + { |
|
| 38 | + return array(\T_CONST); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Processes this test, when one of its tokens is encountered. |
|
| 43 | - * |
|
| 44 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 45 | - * @param int $stackPtr The position of the current token |
|
| 46 | - * in the stack passed in $tokens. |
|
| 47 | - * |
|
| 48 | - * @return void |
|
| 49 | - */ |
|
| 50 | - public function process(File $phpcsFile, $stackPtr) |
|
| 51 | - { |
|
| 52 | - if ($this->supportsBelow('7.0') === false) { |
|
| 53 | - return; |
|
| 54 | - } |
|
| 41 | + /** |
|
| 42 | + * Processes this test, when one of its tokens is encountered. |
|
| 43 | + * |
|
| 44 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 45 | + * @param int $stackPtr The position of the current token |
|
| 46 | + * in the stack passed in $tokens. |
|
| 47 | + * |
|
| 48 | + * @return void |
|
| 49 | + */ |
|
| 50 | + public function process(File $phpcsFile, $stackPtr) |
|
| 51 | + { |
|
| 52 | + if ($this->supportsBelow('7.0') === false) { |
|
| 53 | + return; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - $tokens = $phpcsFile->getTokens(); |
|
| 57 | - $prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true, null, true); |
|
| 56 | + $tokens = $phpcsFile->getTokens(); |
|
| 57 | + $prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true, null, true); |
|
| 58 | 58 | |
| 59 | - // Is the previous token a visibility indicator ? |
|
| 60 | - if ($prevToken === false || isset(Tokens::$scopeModifiers[$tokens[$prevToken]['code']]) === false) { |
|
| 61 | - return; |
|
| 62 | - } |
|
| 59 | + // Is the previous token a visibility indicator ? |
|
| 60 | + if ($prevToken === false || isset(Tokens::$scopeModifiers[$tokens[$prevToken]['code']]) === false) { |
|
| 61 | + return; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - // Is this a class constant ? |
|
| 65 | - if ($this->isClassConstant($phpcsFile, $stackPtr) === false) { |
|
| 66 | - // This may be a constant declaration in the global namespace with visibility, |
|
| 67 | - // but that would throw a parse error, i.e. not our concern. |
|
| 68 | - return; |
|
| 69 | - } |
|
| 64 | + // Is this a class constant ? |
|
| 65 | + if ($this->isClassConstant($phpcsFile, $stackPtr) === false) { |
|
| 66 | + // This may be a constant declaration in the global namespace with visibility, |
|
| 67 | + // but that would throw a parse error, i.e. not our concern. |
|
| 68 | + return; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - $phpcsFile->addError( |
|
| 72 | - 'Visibility indicators for class constants are not supported in PHP 7.0 or earlier. Found "%s const"', |
|
| 73 | - $stackPtr, |
|
| 74 | - 'Found', |
|
| 75 | - array($tokens[$prevToken]['content']) |
|
| 76 | - ); |
|
| 77 | - } |
|
| 71 | + $phpcsFile->addError( |
|
| 72 | + 'Visibility indicators for class constants are not supported in PHP 7.0 or earlier. Found "%s const"', |
|
| 73 | + $stackPtr, |
|
| 74 | + 'Found', |
|
| 75 | + array($tokens[$prevToken]['content']) |
|
| 76 | + ); |
|
| 77 | + } |
|
| 78 | 78 | } |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | public function register() |
| 37 | 37 | { |
| 38 | - return array(\T_CONST); |
|
| 38 | + return array( \T_CONST ); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | /** |
@@ -47,22 +47,22 @@ discard block |
||
| 47 | 47 | * |
| 48 | 48 | * @return void |
| 49 | 49 | */ |
| 50 | - public function process(File $phpcsFile, $stackPtr) |
|
| 50 | + public function process( File $phpcsFile, $stackPtr ) |
|
| 51 | 51 | { |
| 52 | - if ($this->supportsBelow('7.0') === false) { |
|
| 52 | + if ( $this->supportsBelow( '7.0' ) === false ) { |
|
| 53 | 53 | return; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | $tokens = $phpcsFile->getTokens(); |
| 57 | - $prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true, null, true); |
|
| 57 | + $prevToken = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true, null, true ); |
|
| 58 | 58 | |
| 59 | 59 | // Is the previous token a visibility indicator ? |
| 60 | - if ($prevToken === false || isset(Tokens::$scopeModifiers[$tokens[$prevToken]['code']]) === false) { |
|
| 60 | + if ( $prevToken === false || isset( Tokens::$scopeModifiers[ $tokens[ $prevToken ][ 'code' ] ] ) === false ) { |
|
| 61 | 61 | return; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | // Is this a class constant ? |
| 65 | - if ($this->isClassConstant($phpcsFile, $stackPtr) === false) { |
|
| 65 | + if ( $this->isClassConstant( $phpcsFile, $stackPtr ) === false ) { |
|
| 66 | 66 | // This may be a constant declaration in the global namespace with visibility, |
| 67 | 67 | // but that would throw a parse error, i.e. not our concern. |
| 68 | 68 | return; |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | 'Visibility indicators for class constants are not supported in PHP 7.0 or earlier. Found "%s const"', |
| 73 | 73 | $stackPtr, |
| 74 | 74 | 'Found', |
| 75 | - array($tokens[$prevToken]['content']) |
|
| 75 | + array( $tokens[ $prevToken ][ 'content' ] ) |
|
| 76 | 76 | ); |
| 77 | 77 | } |
| 78 | 78 | } |
@@ -26,15 +26,13 @@ discard block |
||
| 26 | 26 | * @package PHPCompatibility |
| 27 | 27 | * @author Juliette Reinders Folmer <[email protected]> |
| 28 | 28 | */ |
| 29 | -class NewConstVisibilitySniff extends Sniff |
|
| 30 | -{ |
|
| 29 | +class NewConstVisibilitySniff extends Sniff { |
|
| 31 | 30 | /** |
| 32 | 31 | * Returns an array of tokens this test wants to listen for. |
| 33 | 32 | * |
| 34 | 33 | * @return array |
| 35 | 34 | */ |
| 36 | - public function register() |
|
| 37 | - { |
|
| 35 | + public function register() { |
|
| 38 | 36 | return array(\T_CONST); |
| 39 | 37 | } |
| 40 | 38 | |
@@ -47,8 +45,7 @@ discard block |
||
| 47 | 45 | * |
| 48 | 46 | * @return void |
| 49 | 47 | */ |
| 50 | - public function process(File $phpcsFile, $stackPtr) |
|
| 51 | - { |
|
| 48 | + public function process(File $phpcsFile, $stackPtr) { |
|
| 52 | 49 | if ($this->supportsBelow('7.0') === false) { |
| 53 | 50 | return; |
| 54 | 51 | } |
@@ -65,7 +65,7 @@ |
||
| 65 | 65 | /** |
| 66 | 66 | * Returns an array of tokens this test wants to listen for. |
| 67 | 67 | * |
| 68 | - * @return array |
|
| 68 | + * @return integer[] |
|
| 69 | 69 | */ |
| 70 | 70 | public function register() |
| 71 | 71 | { |
@@ -24,824 +24,824 @@ |
||
| 24 | 24 | class NewClassesSniff extends AbstractNewFeatureSniff |
| 25 | 25 | { |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * A list of new classes, not present in older versions. |
|
| 29 | - * |
|
| 30 | - * The array lists : version number with false (not present) or true (present). |
|
| 31 | - * If's sufficient to list the first version where the class appears. |
|
| 32 | - * |
|
| 33 | - * @var array(string => array(string => bool)) |
|
| 34 | - */ |
|
| 35 | - protected $newClasses = array( |
|
| 36 | - 'ArrayObject' => array( |
|
| 37 | - '4.4' => false, |
|
| 38 | - '5.0' => true, |
|
| 39 | - ), |
|
| 40 | - 'ArrayIterator' => array( |
|
| 41 | - '4.4' => false, |
|
| 42 | - '5.0' => true, |
|
| 43 | - ), |
|
| 44 | - 'CachingIterator' => array( |
|
| 45 | - '4.4' => false, |
|
| 46 | - '5.0' => true, |
|
| 47 | - ), |
|
| 48 | - 'DirectoryIterator' => array( |
|
| 49 | - '4.4' => false, |
|
| 50 | - '5.0' => true, |
|
| 51 | - ), |
|
| 52 | - 'RecursiveDirectoryIterator' => array( |
|
| 53 | - '4.4' => false, |
|
| 54 | - '5.0' => true, |
|
| 55 | - ), |
|
| 56 | - 'RecursiveIteratorIterator' => array( |
|
| 57 | - '4.4' => false, |
|
| 58 | - '5.0' => true, |
|
| 59 | - ), |
|
| 60 | - 'php_user_filter' => array( |
|
| 61 | - '4.4' => false, |
|
| 62 | - '5.0' => true, |
|
| 63 | - ), |
|
| 64 | - 'tidy' => array( |
|
| 65 | - '4.4' => false, |
|
| 66 | - '5.0' => true, |
|
| 67 | - ), |
|
| 68 | - |
|
| 69 | - 'SimpleXMLElement' => array( |
|
| 70 | - '5.0.0' => false, |
|
| 71 | - '5.0.1' => true, |
|
| 72 | - ), |
|
| 73 | - 'tidyNode' => array( |
|
| 74 | - '5.0.0' => false, |
|
| 75 | - '5.0.1' => true, |
|
| 76 | - ), |
|
| 77 | - |
|
| 78 | - 'libXMLError' => array( |
|
| 79 | - '5.0' => false, |
|
| 80 | - '5.1' => true, |
|
| 81 | - ), |
|
| 82 | - 'PDO' => array( |
|
| 83 | - '5.0' => false, |
|
| 84 | - '5.1' => true, |
|
| 85 | - ), |
|
| 86 | - 'PDOStatement' => array( |
|
| 87 | - '5.0' => false, |
|
| 88 | - '5.1' => true, |
|
| 89 | - ), |
|
| 90 | - 'AppendIterator' => array( |
|
| 91 | - '5.0' => false, |
|
| 92 | - '5.1' => true, |
|
| 93 | - ), |
|
| 94 | - 'EmptyIterator' => array( |
|
| 95 | - '5.0' => false, |
|
| 96 | - '5.1' => true, |
|
| 97 | - ), |
|
| 98 | - 'FilterIterator' => array( |
|
| 99 | - '5.0' => false, |
|
| 100 | - '5.1' => true, |
|
| 101 | - ), |
|
| 102 | - 'InfiniteIterator' => array( |
|
| 103 | - '5.0' => false, |
|
| 104 | - '5.1' => true, |
|
| 105 | - ), |
|
| 106 | - 'IteratorIterator' => array( |
|
| 107 | - '5.0' => false, |
|
| 108 | - '5.1' => true, |
|
| 109 | - ), |
|
| 110 | - 'LimitIterator' => array( |
|
| 111 | - '5.0' => false, |
|
| 112 | - '5.1' => true, |
|
| 113 | - ), |
|
| 114 | - 'NoRewindIterator' => array( |
|
| 115 | - '5.0' => false, |
|
| 116 | - '5.1' => true, |
|
| 117 | - ), |
|
| 118 | - 'ParentIterator' => array( |
|
| 119 | - '5.0' => false, |
|
| 120 | - '5.1' => true, |
|
| 121 | - ), |
|
| 122 | - 'RecursiveArrayIterator' => array( |
|
| 123 | - '5.0' => false, |
|
| 124 | - '5.1' => true, |
|
| 125 | - ), |
|
| 126 | - 'RecursiveCachingIterator' => array( |
|
| 127 | - '5.0' => false, |
|
| 128 | - '5.1' => true, |
|
| 129 | - ), |
|
| 130 | - 'RecursiveFilterIterator' => array( |
|
| 131 | - '5.0' => false, |
|
| 132 | - '5.1' => true, |
|
| 133 | - ), |
|
| 134 | - 'SimpleXMLIterator' => array( |
|
| 135 | - '5.0' => false, |
|
| 136 | - '5.1' => true, |
|
| 137 | - ), |
|
| 138 | - 'SplFileObject' => array( |
|
| 139 | - '5.0' => false, |
|
| 140 | - '5.1' => true, |
|
| 141 | - ), |
|
| 142 | - 'XMLReader' => array( |
|
| 143 | - '5.0' => false, |
|
| 144 | - '5.1' => true, |
|
| 145 | - ), |
|
| 146 | - |
|
| 147 | - 'SplFileInfo' => array( |
|
| 148 | - '5.1.1' => false, |
|
| 149 | - '5.1.2' => true, |
|
| 150 | - ), |
|
| 151 | - 'SplTempFileObject' => array( |
|
| 152 | - '5.1.1' => false, |
|
| 153 | - '5.1.2' => true, |
|
| 154 | - ), |
|
| 155 | - 'XMLWriter' => array( |
|
| 156 | - '5.1.1' => false, |
|
| 157 | - '5.1.2' => true, |
|
| 158 | - ), |
|
| 159 | - |
|
| 160 | - 'DateTime' => array( |
|
| 161 | - '5.1' => false, |
|
| 162 | - '5.2' => true, |
|
| 163 | - ), |
|
| 164 | - 'DateTimeZone' => array( |
|
| 165 | - '5.1' => false, |
|
| 166 | - '5.2' => true, |
|
| 167 | - ), |
|
| 168 | - 'RegexIterator' => array( |
|
| 169 | - '5.1' => false, |
|
| 170 | - '5.2' => true, |
|
| 171 | - ), |
|
| 172 | - 'RecursiveRegexIterator' => array( |
|
| 173 | - '5.1' => false, |
|
| 174 | - '5.2' => true, |
|
| 175 | - ), |
|
| 176 | - 'ReflectionFunctionAbstract' => array( |
|
| 177 | - '5.1' => false, |
|
| 178 | - '5.2' => true, |
|
| 179 | - ), |
|
| 180 | - 'ZipArchive' => array( |
|
| 181 | - '5.1' => false, |
|
| 182 | - '5.2' => true, |
|
| 183 | - ), |
|
| 184 | - |
|
| 185 | - 'Closure' => array( |
|
| 186 | - '5.2' => false, |
|
| 187 | - '5.3' => true, |
|
| 188 | - ), |
|
| 189 | - 'DateInterval' => array( |
|
| 190 | - '5.2' => false, |
|
| 191 | - '5.3' => true, |
|
| 192 | - ), |
|
| 193 | - 'DatePeriod' => array( |
|
| 194 | - '5.2' => false, |
|
| 195 | - '5.3' => true, |
|
| 196 | - ), |
|
| 197 | - 'finfo' => array( |
|
| 198 | - '5.2' => false, |
|
| 199 | - '5.3' => true, |
|
| 200 | - ), |
|
| 201 | - 'Collator' => array( |
|
| 202 | - '5.2' => false, |
|
| 203 | - '5.3' => true, |
|
| 204 | - ), |
|
| 205 | - 'NumberFormatter' => array( |
|
| 206 | - '5.2' => false, |
|
| 207 | - '5.3' => true, |
|
| 208 | - ), |
|
| 209 | - 'Locale' => array( |
|
| 210 | - '5.2' => false, |
|
| 211 | - '5.3' => true, |
|
| 212 | - ), |
|
| 213 | - 'Normalizer' => array( |
|
| 214 | - '5.2' => false, |
|
| 215 | - '5.3' => true, |
|
| 216 | - ), |
|
| 217 | - 'MessageFormatter' => array( |
|
| 218 | - '5.2' => false, |
|
| 219 | - '5.3' => true, |
|
| 220 | - ), |
|
| 221 | - 'IntlDateFormatter' => array( |
|
| 222 | - '5.2' => false, |
|
| 223 | - '5.3' => true, |
|
| 224 | - ), |
|
| 225 | - 'Phar' => array( |
|
| 226 | - '5.2' => false, |
|
| 227 | - '5.3' => true, |
|
| 228 | - ), |
|
| 229 | - 'PharData' => array( |
|
| 230 | - '5.2' => false, |
|
| 231 | - '5.3' => true, |
|
| 232 | - ), |
|
| 233 | - 'PharFileInfo' => array( |
|
| 234 | - '5.2' => false, |
|
| 235 | - '5.3' => true, |
|
| 236 | - ), |
|
| 237 | - 'FilesystemIterator' => array( |
|
| 238 | - '5.2' => false, |
|
| 239 | - '5.3' => true, |
|
| 240 | - ), |
|
| 241 | - 'GlobIterator' => array( |
|
| 242 | - '5.2' => false, |
|
| 243 | - '5.3' => true, |
|
| 244 | - ), |
|
| 245 | - 'MultipleIterator' => array( |
|
| 246 | - '5.2' => false, |
|
| 247 | - '5.3' => true, |
|
| 248 | - ), |
|
| 249 | - 'RecursiveTreeIterator' => array( |
|
| 250 | - '5.2' => false, |
|
| 251 | - '5.3' => true, |
|
| 252 | - ), |
|
| 253 | - 'SplDoublyLinkedList' => array( |
|
| 254 | - '5.2' => false, |
|
| 255 | - '5.3' => true, |
|
| 256 | - ), |
|
| 257 | - 'SplFixedArray' => array( |
|
| 258 | - '5.2' => false, |
|
| 259 | - '5.3' => true, |
|
| 260 | - ), |
|
| 261 | - 'SplHeap' => array( |
|
| 262 | - '5.2' => false, |
|
| 263 | - '5.3' => true, |
|
| 264 | - ), |
|
| 265 | - 'SplMaxHeap' => array( |
|
| 266 | - '5.2' => false, |
|
| 267 | - '5.3' => true, |
|
| 268 | - ), |
|
| 269 | - 'SplMinHeap' => array( |
|
| 270 | - '5.2' => false, |
|
| 271 | - '5.3' => true, |
|
| 272 | - ), |
|
| 273 | - 'SplObjectStorage' => array( |
|
| 274 | - '5.2' => false, |
|
| 275 | - '5.3' => true, |
|
| 276 | - ), |
|
| 277 | - 'SplPriorityQueue' => array( |
|
| 278 | - '5.2' => false, |
|
| 279 | - '5.3' => true, |
|
| 280 | - ), |
|
| 281 | - 'SplQueue' => array( |
|
| 282 | - '5.2' => false, |
|
| 283 | - '5.3' => true, |
|
| 284 | - ), |
|
| 285 | - 'SplStack' => array( |
|
| 286 | - '5.2' => false, |
|
| 287 | - '5.3' => true, |
|
| 288 | - ), |
|
| 289 | - |
|
| 290 | - 'ResourceBundle' => array( |
|
| 291 | - '5.3.1' => false, |
|
| 292 | - '5.3.2' => true, |
|
| 293 | - ), |
|
| 294 | - |
|
| 295 | - 'CallbackFilterIterator' => array( |
|
| 296 | - '5.3' => false, |
|
| 297 | - '5.4' => true, |
|
| 298 | - ), |
|
| 299 | - 'RecursiveCallbackFilterIterator' => array( |
|
| 300 | - '5.3' => false, |
|
| 301 | - '5.4' => true, |
|
| 302 | - ), |
|
| 303 | - 'ReflectionZendExtension' => array( |
|
| 304 | - '5.3' => false, |
|
| 305 | - '5.4' => true, |
|
| 306 | - ), |
|
| 307 | - 'SessionHandler' => array( |
|
| 308 | - '5.3' => false, |
|
| 309 | - '5.4' => true, |
|
| 310 | - ), |
|
| 311 | - 'SNMP' => array( |
|
| 312 | - '5.3' => false, |
|
| 313 | - '5.4' => true, |
|
| 314 | - ), |
|
| 315 | - 'Transliterator' => array( |
|
| 316 | - '5.3' => false, |
|
| 317 | - '5.4' => true, |
|
| 318 | - ), |
|
| 319 | - 'Spoofchecker' => array( |
|
| 320 | - '5.3' => false, |
|
| 321 | - '5.4' => true, |
|
| 322 | - ), |
|
| 323 | - |
|
| 324 | - 'Generator' => array( |
|
| 325 | - '5.4' => false, |
|
| 326 | - '5.5' => true, |
|
| 327 | - ), |
|
| 328 | - 'CURLFile' => array( |
|
| 329 | - '5.4' => false, |
|
| 330 | - '5.5' => true, |
|
| 331 | - ), |
|
| 332 | - 'DateTimeImmutable' => array( |
|
| 333 | - '5.4' => false, |
|
| 334 | - '5.5' => true, |
|
| 335 | - ), |
|
| 336 | - 'IntlCalendar' => array( |
|
| 337 | - '5.4' => false, |
|
| 338 | - '5.5' => true, |
|
| 339 | - ), |
|
| 340 | - 'IntlGregorianCalendar' => array( |
|
| 341 | - '5.4' => false, |
|
| 342 | - '5.5' => true, |
|
| 343 | - ), |
|
| 344 | - 'IntlTimeZone' => array( |
|
| 345 | - '5.4' => false, |
|
| 346 | - '5.5' => true, |
|
| 347 | - ), |
|
| 348 | - 'IntlBreakIterator' => array( |
|
| 349 | - '5.4' => false, |
|
| 350 | - '5.5' => true, |
|
| 351 | - ), |
|
| 352 | - 'IntlRuleBasedBreakIterator' => array( |
|
| 353 | - '5.4' => false, |
|
| 354 | - '5.5' => true, |
|
| 355 | - ), |
|
| 356 | - 'IntlCodePointBreakIterator' => array( |
|
| 357 | - '5.4' => false, |
|
| 358 | - '5.5' => true, |
|
| 359 | - ), |
|
| 360 | - 'UConverter' => array( |
|
| 361 | - '5.4' => false, |
|
| 362 | - '5.5' => true, |
|
| 363 | - ), |
|
| 364 | - |
|
| 365 | - 'GMP' => array( |
|
| 366 | - '5.5' => false, |
|
| 367 | - '5.6' => true, |
|
| 368 | - ), |
|
| 369 | - |
|
| 370 | - 'IntlChar' => array( |
|
| 371 | - '5.6' => false, |
|
| 372 | - '7.0' => true, |
|
| 373 | - ), |
|
| 374 | - 'ReflectionType' => array( |
|
| 375 | - '5.6' => false, |
|
| 376 | - '7.0' => true, |
|
| 377 | - ), |
|
| 378 | - 'ReflectionGenerator' => array( |
|
| 379 | - '5.6' => false, |
|
| 380 | - '7.0' => true, |
|
| 381 | - ), |
|
| 382 | - |
|
| 383 | - 'ReflectionClassConstant' => array( |
|
| 384 | - '7.0' => false, |
|
| 385 | - '7.1' => true, |
|
| 386 | - ), |
|
| 387 | - |
|
| 388 | - ); |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * A list of new Exception classes, not present in older versions. |
|
| 392 | - * |
|
| 393 | - * The array lists : version number with false (not present) or true (present). |
|
| 394 | - * If's sufficient to list the first version where the class appears. |
|
| 395 | - * |
|
| 396 | - * {@internal Classes listed here do not need to be added to the $newClasses |
|
| 397 | - * property as well. |
|
| 398 | - * This list is automatically added to the $newClasses property |
|
| 399 | - * in the `register()` method.}} |
|
| 400 | - * |
|
| 401 | - * {@internal Helper to update this list: https://3v4l.org/MhlUp}} |
|
| 402 | - * |
|
| 403 | - * @var array(string => array(string => bool)) |
|
| 404 | - */ |
|
| 405 | - protected $newExceptions = array( |
|
| 406 | - 'com_exception' => array( |
|
| 407 | - '4.4' => false, |
|
| 408 | - '5.0' => true, |
|
| 409 | - ), |
|
| 410 | - 'DOMException' => array( |
|
| 411 | - '4.4' => false, |
|
| 412 | - '5.0' => true, |
|
| 413 | - ), |
|
| 414 | - 'Exception' => array( |
|
| 415 | - // According to the docs introduced in PHP 5.1, but this appears to be. |
|
| 416 | - // an error. Class was introduced with try/catch keywords in PHP 5.0. |
|
| 417 | - '4.4' => false, |
|
| 418 | - '5.0' => true, |
|
| 419 | - ), |
|
| 420 | - 'ReflectionException' => array( |
|
| 421 | - '4.4' => false, |
|
| 422 | - '5.0' => true, |
|
| 423 | - ), |
|
| 424 | - 'SoapFault' => array( |
|
| 425 | - '4.4' => false, |
|
| 426 | - '5.0' => true, |
|
| 427 | - ), |
|
| 428 | - 'SQLiteException' => array( |
|
| 429 | - '4.4' => false, |
|
| 430 | - '5.0' => true, |
|
| 431 | - ), |
|
| 432 | - |
|
| 433 | - 'ErrorException' => array( |
|
| 434 | - '5.0' => false, |
|
| 435 | - '5.1' => true, |
|
| 436 | - ), |
|
| 437 | - 'BadFunctionCallException' => array( |
|
| 438 | - '5.0' => false, |
|
| 439 | - '5.1' => true, |
|
| 440 | - ), |
|
| 441 | - 'BadMethodCallException' => array( |
|
| 442 | - '5.0' => false, |
|
| 443 | - '5.1' => true, |
|
| 444 | - ), |
|
| 445 | - 'DomainException' => array( |
|
| 446 | - '5.0' => false, |
|
| 447 | - '5.1' => true, |
|
| 448 | - ), |
|
| 449 | - 'InvalidArgumentException' => array( |
|
| 450 | - '5.0' => false, |
|
| 451 | - '5.1' => true, |
|
| 452 | - ), |
|
| 453 | - 'LengthException' => array( |
|
| 454 | - '5.0' => false, |
|
| 455 | - '5.1' => true, |
|
| 456 | - ), |
|
| 457 | - 'LogicException' => array( |
|
| 458 | - '5.0' => false, |
|
| 459 | - '5.1' => true, |
|
| 460 | - ), |
|
| 461 | - 'mysqli_sql_exception' => array( |
|
| 462 | - '5.0' => false, |
|
| 463 | - '5.1' => true, |
|
| 464 | - ), |
|
| 465 | - 'OutOfBoundsException' => array( |
|
| 466 | - '5.0' => false, |
|
| 467 | - '5.1' => true, |
|
| 468 | - ), |
|
| 469 | - 'OutOfRangeException' => array( |
|
| 470 | - '5.0' => false, |
|
| 471 | - '5.1' => true, |
|
| 472 | - ), |
|
| 473 | - 'OverflowException' => array( |
|
| 474 | - '5.0' => false, |
|
| 475 | - '5.1' => true, |
|
| 476 | - ), |
|
| 477 | - 'PDOException' => array( |
|
| 478 | - '5.0' => false, |
|
| 479 | - '5.1' => true, |
|
| 480 | - ), |
|
| 481 | - 'RangeException' => array( |
|
| 482 | - '5.0' => false, |
|
| 483 | - '5.1' => true, |
|
| 484 | - ), |
|
| 485 | - 'RuntimeException' => array( |
|
| 486 | - '5.0' => false, |
|
| 487 | - '5.1' => true, |
|
| 488 | - ), |
|
| 489 | - 'UnderflowException' => array( |
|
| 490 | - '5.0' => false, |
|
| 491 | - '5.1' => true, |
|
| 492 | - ), |
|
| 493 | - 'UnexpectedValueException' => array( |
|
| 494 | - '5.0' => false, |
|
| 495 | - '5.1' => true, |
|
| 496 | - ), |
|
| 497 | - |
|
| 498 | - 'PharException' => array( |
|
| 499 | - '5.2' => false, |
|
| 500 | - '5.3' => true, |
|
| 501 | - ), |
|
| 502 | - |
|
| 503 | - 'SNMPException' => array( |
|
| 504 | - '5.3' => false, |
|
| 505 | - '5.4' => true, |
|
| 506 | - ), |
|
| 507 | - |
|
| 508 | - 'IntlException' => array( |
|
| 509 | - '5.4' => false, |
|
| 510 | - '5.5' => true, |
|
| 511 | - ), |
|
| 512 | - |
|
| 513 | - 'Error' => array( |
|
| 514 | - '5.6' => false, |
|
| 515 | - '7.0' => true, |
|
| 516 | - ), |
|
| 517 | - 'ArithmeticError' => array( |
|
| 518 | - '5.6' => false, |
|
| 519 | - '7.0' => true, |
|
| 520 | - ), |
|
| 521 | - 'AssertionError' => array( |
|
| 522 | - '5.6' => false, |
|
| 523 | - '7.0' => true, |
|
| 524 | - ), |
|
| 525 | - 'DivisionByZeroError' => array( |
|
| 526 | - '5.6' => false, |
|
| 527 | - '7.0' => true, |
|
| 528 | - ), |
|
| 529 | - 'ParseError' => array( |
|
| 530 | - '5.6' => false, |
|
| 531 | - '7.0' => true, |
|
| 532 | - ), |
|
| 533 | - 'TypeError' => array( |
|
| 534 | - '5.6' => false, |
|
| 535 | - '7.0' => true, |
|
| 536 | - ), |
|
| 537 | - 'ClosedGeneratorException' => array( |
|
| 538 | - '5.6' => false, |
|
| 539 | - '7.0' => true, |
|
| 540 | - ), |
|
| 541 | - 'UI\Exception\InvalidArgumentException' => array( |
|
| 542 | - '5.6' => false, |
|
| 543 | - '7.0' => true, |
|
| 544 | - ), |
|
| 545 | - 'UI\Exception\RuntimeException' => array( |
|
| 546 | - '5.6' => false, |
|
| 547 | - '7.0' => true, |
|
| 548 | - ), |
|
| 549 | - |
|
| 550 | - 'ArgumentCountError' => array( |
|
| 551 | - '7.0' => false, |
|
| 552 | - '7.1' => true, |
|
| 553 | - ), |
|
| 554 | - |
|
| 555 | - 'SodiumException' => array( |
|
| 556 | - '7.1' => false, |
|
| 557 | - '7.2' => true, |
|
| 558 | - ), |
|
| 559 | - |
|
| 560 | - 'CompileError' => array( |
|
| 561 | - '7.2' => false, |
|
| 562 | - '7.3' => true, |
|
| 563 | - ), |
|
| 564 | - 'JsonException' => array( |
|
| 565 | - '7.2' => false, |
|
| 566 | - '7.3' => true, |
|
| 567 | - ), |
|
| 568 | - |
|
| 569 | - 'ReflectionReference' => array( |
|
| 570 | - '7.3' => false, |
|
| 571 | - '7.4' => true, |
|
| 572 | - ), |
|
| 573 | - ); |
|
| 574 | - |
|
| 575 | - |
|
| 576 | - /** |
|
| 577 | - * Returns an array of tokens this test wants to listen for. |
|
| 578 | - * |
|
| 579 | - * @return array |
|
| 580 | - */ |
|
| 581 | - public function register() |
|
| 582 | - { |
|
| 583 | - // Handle case-insensitivity of class names. |
|
| 584 | - $this->newClasses = $this->arrayKeysToLowercase($this->newClasses); |
|
| 585 | - $this->newExceptions = $this->arrayKeysToLowercase($this->newExceptions); |
|
| 586 | - |
|
| 587 | - // Add the Exception classes to the Classes list. |
|
| 588 | - $this->newClasses = array_merge($this->newClasses, $this->newExceptions); |
|
| 589 | - |
|
| 590 | - $targets = array( |
|
| 591 | - \T_NEW, |
|
| 592 | - \T_CLASS, |
|
| 593 | - \T_DOUBLE_COLON, |
|
| 594 | - \T_FUNCTION, |
|
| 595 | - \T_CLOSURE, |
|
| 596 | - \T_CATCH, |
|
| 597 | - ); |
|
| 598 | - |
|
| 599 | - if (\defined('T_ANON_CLASS')) { |
|
| 600 | - $targets[] = \T_ANON_CLASS; |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - if (\defined('T_RETURN_TYPE')) { |
|
| 604 | - $targets[] = \T_RETURN_TYPE; |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - return $targets; |
|
| 608 | - } |
|
| 609 | - |
|
| 610 | - |
|
| 611 | - /** |
|
| 612 | - * Processes this test, when one of its tokens is encountered. |
|
| 613 | - * |
|
| 614 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 615 | - * @param int $stackPtr The position of the current token in |
|
| 616 | - * the stack passed in $tokens. |
|
| 617 | - * |
|
| 618 | - * @return void |
|
| 619 | - */ |
|
| 620 | - public function process(File $phpcsFile, $stackPtr) |
|
| 621 | - { |
|
| 622 | - $tokens = $phpcsFile->getTokens(); |
|
| 623 | - |
|
| 624 | - switch ($tokens[$stackPtr]['type']) { |
|
| 625 | - case 'T_FUNCTION': |
|
| 626 | - case 'T_CLOSURE': |
|
| 627 | - $this->processFunctionToken($phpcsFile, $stackPtr); |
|
| 628 | - |
|
| 629 | - // Deal with older PHPCS version which don't recognize return type hints |
|
| 630 | - // as well as newer PHPCS versions (3.3.0+) where the tokenization has changed. |
|
| 631 | - $returnTypeHint = $this->getReturnTypeHintToken($phpcsFile, $stackPtr); |
|
| 632 | - if ($returnTypeHint !== false) { |
|
| 633 | - $this->processReturnTypeToken($phpcsFile, $returnTypeHint); |
|
| 634 | - } |
|
| 635 | - break; |
|
| 636 | - |
|
| 637 | - case 'T_CATCH': |
|
| 638 | - $this->processCatchToken($phpcsFile, $stackPtr); |
|
| 639 | - break; |
|
| 640 | - |
|
| 641 | - case 'T_RETURN_TYPE': |
|
| 642 | - $this->processReturnTypeToken($phpcsFile, $stackPtr); |
|
| 643 | - break; |
|
| 644 | - |
|
| 645 | - default: |
|
| 646 | - $this->processSingularToken($phpcsFile, $stackPtr); |
|
| 647 | - break; |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - |
|
| 652 | - /** |
|
| 653 | - * Processes this test for when a token resulting in a singular class name is encountered. |
|
| 654 | - * |
|
| 655 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 656 | - * @param int $stackPtr The position of the current token in |
|
| 657 | - * the stack passed in $tokens. |
|
| 658 | - * |
|
| 659 | - * @return void |
|
| 660 | - */ |
|
| 661 | - private function processSingularToken(File $phpcsFile, $stackPtr) |
|
| 662 | - { |
|
| 663 | - $tokens = $phpcsFile->getTokens(); |
|
| 664 | - $FQClassName = ''; |
|
| 665 | - |
|
| 666 | - if ($tokens[$stackPtr]['type'] === 'T_NEW') { |
|
| 667 | - $FQClassName = $this->getFQClassNameFromNewToken($phpcsFile, $stackPtr); |
|
| 668 | - |
|
| 669 | - } elseif ($tokens[$stackPtr]['type'] === 'T_CLASS' || $tokens[$stackPtr]['type'] === 'T_ANON_CLASS') { |
|
| 670 | - $FQClassName = $this->getFQExtendedClassName($phpcsFile, $stackPtr); |
|
| 671 | - |
|
| 672 | - } elseif ($tokens[$stackPtr]['type'] === 'T_DOUBLE_COLON') { |
|
| 673 | - $FQClassName = $this->getFQClassNameFromDoubleColonToken($phpcsFile, $stackPtr); |
|
| 674 | - } |
|
| 675 | - |
|
| 676 | - if ($FQClassName === '') { |
|
| 677 | - return; |
|
| 678 | - } |
|
| 679 | - |
|
| 680 | - $className = substr($FQClassName, 1); // Remove global namespace indicator. |
|
| 681 | - $classNameLc = strtolower($className); |
|
| 682 | - |
|
| 683 | - if (isset($this->newClasses[$classNameLc]) === false) { |
|
| 684 | - return; |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - $itemInfo = array( |
|
| 688 | - 'name' => $className, |
|
| 689 | - 'nameLc' => $classNameLc, |
|
| 690 | - ); |
|
| 691 | - $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - |
|
| 695 | - /** |
|
| 696 | - * Processes this test for when a function token is encountered. |
|
| 697 | - * |
|
| 698 | - * - Detect new classes when used as a type hint. |
|
| 699 | - * |
|
| 700 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 701 | - * @param int $stackPtr The position of the current token in |
|
| 702 | - * the stack passed in $tokens. |
|
| 703 | - * |
|
| 704 | - * @return void |
|
| 705 | - */ |
|
| 706 | - private function processFunctionToken(File $phpcsFile, $stackPtr) |
|
| 707 | - { |
|
| 708 | - // Retrieve typehints stripped of global NS indicator and/or nullable indicator. |
|
| 709 | - $typeHints = $this->getTypeHintsFromFunctionDeclaration($phpcsFile, $stackPtr); |
|
| 710 | - if (empty($typeHints) || \is_array($typeHints) === false) { |
|
| 711 | - return; |
|
| 712 | - } |
|
| 713 | - |
|
| 714 | - foreach ($typeHints as $hint) { |
|
| 715 | - |
|
| 716 | - $typeHintLc = strtolower($hint); |
|
| 717 | - |
|
| 718 | - if (isset($this->newClasses[$typeHintLc]) === true) { |
|
| 719 | - $itemInfo = array( |
|
| 720 | - 'name' => $hint, |
|
| 721 | - 'nameLc' => $typeHintLc, |
|
| 722 | - ); |
|
| 723 | - $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
| 724 | - } |
|
| 725 | - } |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - |
|
| 729 | - /** |
|
| 730 | - * Processes this test for when a catch token is encountered. |
|
| 731 | - * |
|
| 732 | - * - Detect exceptions when used in a catch statement. |
|
| 733 | - * |
|
| 734 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 735 | - * @param int $stackPtr The position of the current token in |
|
| 736 | - * the stack passed in $tokens. |
|
| 737 | - * |
|
| 738 | - * @return void |
|
| 739 | - */ |
|
| 740 | - private function processCatchToken(File $phpcsFile, $stackPtr) |
|
| 741 | - { |
|
| 742 | - $tokens = $phpcsFile->getTokens(); |
|
| 743 | - |
|
| 744 | - // Bow out during live coding. |
|
| 745 | - if (isset($tokens[$stackPtr]['parenthesis_opener'], $tokens[$stackPtr]['parenthesis_closer']) === false) { |
|
| 746 | - return; |
|
| 747 | - } |
|
| 748 | - |
|
| 749 | - $opener = $tokens[$stackPtr]['parenthesis_opener']; |
|
| 750 | - $closer = ($tokens[$stackPtr]['parenthesis_closer'] + 1); |
|
| 751 | - $name = ''; |
|
| 752 | - $listen = array( |
|
| 753 | - // Parts of a (namespaced) class name. |
|
| 754 | - \T_STRING => true, |
|
| 755 | - \T_NS_SEPARATOR => true, |
|
| 756 | - // End/split tokens. |
|
| 757 | - \T_VARIABLE => false, |
|
| 758 | - \T_BITWISE_OR => false, |
|
| 759 | - \T_CLOSE_CURLY_BRACKET => false, // Shouldn't be needed as we expect a var before this. |
|
| 760 | - ); |
|
| 761 | - |
|
| 762 | - for ($i = ($opener + 1); $i < $closer; $i++) { |
|
| 763 | - if (isset($listen[$tokens[$i]['code']]) === false) { |
|
| 764 | - continue; |
|
| 765 | - } |
|
| 766 | - |
|
| 767 | - if ($listen[$tokens[$i]['code']] === true) { |
|
| 768 | - $name .= $tokens[$i]['content']; |
|
| 769 | - continue; |
|
| 770 | - } else { |
|
| 771 | - if (empty($name) === true) { |
|
| 772 | - // Weird, we should have a name by the time we encounter a variable or |. |
|
| 773 | - // So this may be the closer. |
|
| 774 | - continue; |
|
| 775 | - } |
|
| 776 | - |
|
| 777 | - $name = ltrim($name, '\\'); |
|
| 778 | - $nameLC = strtolower($name); |
|
| 779 | - |
|
| 780 | - if (isset($this->newExceptions[$nameLC]) === true) { |
|
| 781 | - $itemInfo = array( |
|
| 782 | - 'name' => $name, |
|
| 783 | - 'nameLc' => $nameLC, |
|
| 784 | - ); |
|
| 785 | - $this->handleFeature($phpcsFile, $i, $itemInfo); |
|
| 786 | - } |
|
| 787 | - |
|
| 788 | - // Reset for a potential multi-catch. |
|
| 789 | - $name = ''; |
|
| 790 | - } |
|
| 791 | - } |
|
| 792 | - } |
|
| 793 | - |
|
| 794 | - |
|
| 795 | - /** |
|
| 796 | - * Processes this test for when a return type token is encountered. |
|
| 797 | - * |
|
| 798 | - * - Detect new classes when used as a return type declaration. |
|
| 799 | - * |
|
| 800 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 801 | - * @param int $stackPtr The position of the current token in |
|
| 802 | - * the stack passed in $tokens. |
|
| 803 | - * |
|
| 804 | - * @return void |
|
| 805 | - */ |
|
| 806 | - private function processReturnTypeToken(File $phpcsFile, $stackPtr) |
|
| 807 | - { |
|
| 808 | - $returnTypeHint = $this->getReturnTypeHintName($phpcsFile, $stackPtr); |
|
| 809 | - $returnTypeHint = ltrim($returnTypeHint, '\\'); |
|
| 810 | - $returnTypeHintLc = strtolower($returnTypeHint); |
|
| 811 | - |
|
| 812 | - if (isset($this->newClasses[$returnTypeHintLc]) === false) { |
|
| 813 | - return; |
|
| 814 | - } |
|
| 815 | - |
|
| 816 | - // Still here ? Then this is a return type declaration using a new class. |
|
| 817 | - $itemInfo = array( |
|
| 818 | - 'name' => $returnTypeHint, |
|
| 819 | - 'nameLc' => $returnTypeHintLc, |
|
| 820 | - ); |
|
| 821 | - $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
| 822 | - } |
|
| 823 | - |
|
| 824 | - |
|
| 825 | - /** |
|
| 826 | - * Get the relevant sub-array for a specific item from a multi-dimensional array. |
|
| 827 | - * |
|
| 828 | - * @param array $itemInfo Base information about the item. |
|
| 829 | - * |
|
| 830 | - * @return array Version and other information about the item. |
|
| 831 | - */ |
|
| 832 | - public function getItemArray(array $itemInfo) |
|
| 833 | - { |
|
| 834 | - return $this->newClasses[$itemInfo['nameLc']]; |
|
| 835 | - } |
|
| 836 | - |
|
| 837 | - |
|
| 838 | - /** |
|
| 839 | - * Get the error message template for this sniff. |
|
| 840 | - * |
|
| 841 | - * @return string |
|
| 842 | - */ |
|
| 843 | - protected function getErrorMsgTemplate() |
|
| 844 | - { |
|
| 845 | - return 'The built-in class ' . parent::getErrorMsgTemplate(); |
|
| 846 | - } |
|
| 27 | + /** |
|
| 28 | + * A list of new classes, not present in older versions. |
|
| 29 | + * |
|
| 30 | + * The array lists : version number with false (not present) or true (present). |
|
| 31 | + * If's sufficient to list the first version where the class appears. |
|
| 32 | + * |
|
| 33 | + * @var array(string => array(string => bool)) |
|
| 34 | + */ |
|
| 35 | + protected $newClasses = array( |
|
| 36 | + 'ArrayObject' => array( |
|
| 37 | + '4.4' => false, |
|
| 38 | + '5.0' => true, |
|
| 39 | + ), |
|
| 40 | + 'ArrayIterator' => array( |
|
| 41 | + '4.4' => false, |
|
| 42 | + '5.0' => true, |
|
| 43 | + ), |
|
| 44 | + 'CachingIterator' => array( |
|
| 45 | + '4.4' => false, |
|
| 46 | + '5.0' => true, |
|
| 47 | + ), |
|
| 48 | + 'DirectoryIterator' => array( |
|
| 49 | + '4.4' => false, |
|
| 50 | + '5.0' => true, |
|
| 51 | + ), |
|
| 52 | + 'RecursiveDirectoryIterator' => array( |
|
| 53 | + '4.4' => false, |
|
| 54 | + '5.0' => true, |
|
| 55 | + ), |
|
| 56 | + 'RecursiveIteratorIterator' => array( |
|
| 57 | + '4.4' => false, |
|
| 58 | + '5.0' => true, |
|
| 59 | + ), |
|
| 60 | + 'php_user_filter' => array( |
|
| 61 | + '4.4' => false, |
|
| 62 | + '5.0' => true, |
|
| 63 | + ), |
|
| 64 | + 'tidy' => array( |
|
| 65 | + '4.4' => false, |
|
| 66 | + '5.0' => true, |
|
| 67 | + ), |
|
| 68 | + |
|
| 69 | + 'SimpleXMLElement' => array( |
|
| 70 | + '5.0.0' => false, |
|
| 71 | + '5.0.1' => true, |
|
| 72 | + ), |
|
| 73 | + 'tidyNode' => array( |
|
| 74 | + '5.0.0' => false, |
|
| 75 | + '5.0.1' => true, |
|
| 76 | + ), |
|
| 77 | + |
|
| 78 | + 'libXMLError' => array( |
|
| 79 | + '5.0' => false, |
|
| 80 | + '5.1' => true, |
|
| 81 | + ), |
|
| 82 | + 'PDO' => array( |
|
| 83 | + '5.0' => false, |
|
| 84 | + '5.1' => true, |
|
| 85 | + ), |
|
| 86 | + 'PDOStatement' => array( |
|
| 87 | + '5.0' => false, |
|
| 88 | + '5.1' => true, |
|
| 89 | + ), |
|
| 90 | + 'AppendIterator' => array( |
|
| 91 | + '5.0' => false, |
|
| 92 | + '5.1' => true, |
|
| 93 | + ), |
|
| 94 | + 'EmptyIterator' => array( |
|
| 95 | + '5.0' => false, |
|
| 96 | + '5.1' => true, |
|
| 97 | + ), |
|
| 98 | + 'FilterIterator' => array( |
|
| 99 | + '5.0' => false, |
|
| 100 | + '5.1' => true, |
|
| 101 | + ), |
|
| 102 | + 'InfiniteIterator' => array( |
|
| 103 | + '5.0' => false, |
|
| 104 | + '5.1' => true, |
|
| 105 | + ), |
|
| 106 | + 'IteratorIterator' => array( |
|
| 107 | + '5.0' => false, |
|
| 108 | + '5.1' => true, |
|
| 109 | + ), |
|
| 110 | + 'LimitIterator' => array( |
|
| 111 | + '5.0' => false, |
|
| 112 | + '5.1' => true, |
|
| 113 | + ), |
|
| 114 | + 'NoRewindIterator' => array( |
|
| 115 | + '5.0' => false, |
|
| 116 | + '5.1' => true, |
|
| 117 | + ), |
|
| 118 | + 'ParentIterator' => array( |
|
| 119 | + '5.0' => false, |
|
| 120 | + '5.1' => true, |
|
| 121 | + ), |
|
| 122 | + 'RecursiveArrayIterator' => array( |
|
| 123 | + '5.0' => false, |
|
| 124 | + '5.1' => true, |
|
| 125 | + ), |
|
| 126 | + 'RecursiveCachingIterator' => array( |
|
| 127 | + '5.0' => false, |
|
| 128 | + '5.1' => true, |
|
| 129 | + ), |
|
| 130 | + 'RecursiveFilterIterator' => array( |
|
| 131 | + '5.0' => false, |
|
| 132 | + '5.1' => true, |
|
| 133 | + ), |
|
| 134 | + 'SimpleXMLIterator' => array( |
|
| 135 | + '5.0' => false, |
|
| 136 | + '5.1' => true, |
|
| 137 | + ), |
|
| 138 | + 'SplFileObject' => array( |
|
| 139 | + '5.0' => false, |
|
| 140 | + '5.1' => true, |
|
| 141 | + ), |
|
| 142 | + 'XMLReader' => array( |
|
| 143 | + '5.0' => false, |
|
| 144 | + '5.1' => true, |
|
| 145 | + ), |
|
| 146 | + |
|
| 147 | + 'SplFileInfo' => array( |
|
| 148 | + '5.1.1' => false, |
|
| 149 | + '5.1.2' => true, |
|
| 150 | + ), |
|
| 151 | + 'SplTempFileObject' => array( |
|
| 152 | + '5.1.1' => false, |
|
| 153 | + '5.1.2' => true, |
|
| 154 | + ), |
|
| 155 | + 'XMLWriter' => array( |
|
| 156 | + '5.1.1' => false, |
|
| 157 | + '5.1.2' => true, |
|
| 158 | + ), |
|
| 159 | + |
|
| 160 | + 'DateTime' => array( |
|
| 161 | + '5.1' => false, |
|
| 162 | + '5.2' => true, |
|
| 163 | + ), |
|
| 164 | + 'DateTimeZone' => array( |
|
| 165 | + '5.1' => false, |
|
| 166 | + '5.2' => true, |
|
| 167 | + ), |
|
| 168 | + 'RegexIterator' => array( |
|
| 169 | + '5.1' => false, |
|
| 170 | + '5.2' => true, |
|
| 171 | + ), |
|
| 172 | + 'RecursiveRegexIterator' => array( |
|
| 173 | + '5.1' => false, |
|
| 174 | + '5.2' => true, |
|
| 175 | + ), |
|
| 176 | + 'ReflectionFunctionAbstract' => array( |
|
| 177 | + '5.1' => false, |
|
| 178 | + '5.2' => true, |
|
| 179 | + ), |
|
| 180 | + 'ZipArchive' => array( |
|
| 181 | + '5.1' => false, |
|
| 182 | + '5.2' => true, |
|
| 183 | + ), |
|
| 184 | + |
|
| 185 | + 'Closure' => array( |
|
| 186 | + '5.2' => false, |
|
| 187 | + '5.3' => true, |
|
| 188 | + ), |
|
| 189 | + 'DateInterval' => array( |
|
| 190 | + '5.2' => false, |
|
| 191 | + '5.3' => true, |
|
| 192 | + ), |
|
| 193 | + 'DatePeriod' => array( |
|
| 194 | + '5.2' => false, |
|
| 195 | + '5.3' => true, |
|
| 196 | + ), |
|
| 197 | + 'finfo' => array( |
|
| 198 | + '5.2' => false, |
|
| 199 | + '5.3' => true, |
|
| 200 | + ), |
|
| 201 | + 'Collator' => array( |
|
| 202 | + '5.2' => false, |
|
| 203 | + '5.3' => true, |
|
| 204 | + ), |
|
| 205 | + 'NumberFormatter' => array( |
|
| 206 | + '5.2' => false, |
|
| 207 | + '5.3' => true, |
|
| 208 | + ), |
|
| 209 | + 'Locale' => array( |
|
| 210 | + '5.2' => false, |
|
| 211 | + '5.3' => true, |
|
| 212 | + ), |
|
| 213 | + 'Normalizer' => array( |
|
| 214 | + '5.2' => false, |
|
| 215 | + '5.3' => true, |
|
| 216 | + ), |
|
| 217 | + 'MessageFormatter' => array( |
|
| 218 | + '5.2' => false, |
|
| 219 | + '5.3' => true, |
|
| 220 | + ), |
|
| 221 | + 'IntlDateFormatter' => array( |
|
| 222 | + '5.2' => false, |
|
| 223 | + '5.3' => true, |
|
| 224 | + ), |
|
| 225 | + 'Phar' => array( |
|
| 226 | + '5.2' => false, |
|
| 227 | + '5.3' => true, |
|
| 228 | + ), |
|
| 229 | + 'PharData' => array( |
|
| 230 | + '5.2' => false, |
|
| 231 | + '5.3' => true, |
|
| 232 | + ), |
|
| 233 | + 'PharFileInfo' => array( |
|
| 234 | + '5.2' => false, |
|
| 235 | + '5.3' => true, |
|
| 236 | + ), |
|
| 237 | + 'FilesystemIterator' => array( |
|
| 238 | + '5.2' => false, |
|
| 239 | + '5.3' => true, |
|
| 240 | + ), |
|
| 241 | + 'GlobIterator' => array( |
|
| 242 | + '5.2' => false, |
|
| 243 | + '5.3' => true, |
|
| 244 | + ), |
|
| 245 | + 'MultipleIterator' => array( |
|
| 246 | + '5.2' => false, |
|
| 247 | + '5.3' => true, |
|
| 248 | + ), |
|
| 249 | + 'RecursiveTreeIterator' => array( |
|
| 250 | + '5.2' => false, |
|
| 251 | + '5.3' => true, |
|
| 252 | + ), |
|
| 253 | + 'SplDoublyLinkedList' => array( |
|
| 254 | + '5.2' => false, |
|
| 255 | + '5.3' => true, |
|
| 256 | + ), |
|
| 257 | + 'SplFixedArray' => array( |
|
| 258 | + '5.2' => false, |
|
| 259 | + '5.3' => true, |
|
| 260 | + ), |
|
| 261 | + 'SplHeap' => array( |
|
| 262 | + '5.2' => false, |
|
| 263 | + '5.3' => true, |
|
| 264 | + ), |
|
| 265 | + 'SplMaxHeap' => array( |
|
| 266 | + '5.2' => false, |
|
| 267 | + '5.3' => true, |
|
| 268 | + ), |
|
| 269 | + 'SplMinHeap' => array( |
|
| 270 | + '5.2' => false, |
|
| 271 | + '5.3' => true, |
|
| 272 | + ), |
|
| 273 | + 'SplObjectStorage' => array( |
|
| 274 | + '5.2' => false, |
|
| 275 | + '5.3' => true, |
|
| 276 | + ), |
|
| 277 | + 'SplPriorityQueue' => array( |
|
| 278 | + '5.2' => false, |
|
| 279 | + '5.3' => true, |
|
| 280 | + ), |
|
| 281 | + 'SplQueue' => array( |
|
| 282 | + '5.2' => false, |
|
| 283 | + '5.3' => true, |
|
| 284 | + ), |
|
| 285 | + 'SplStack' => array( |
|
| 286 | + '5.2' => false, |
|
| 287 | + '5.3' => true, |
|
| 288 | + ), |
|
| 289 | + |
|
| 290 | + 'ResourceBundle' => array( |
|
| 291 | + '5.3.1' => false, |
|
| 292 | + '5.3.2' => true, |
|
| 293 | + ), |
|
| 294 | + |
|
| 295 | + 'CallbackFilterIterator' => array( |
|
| 296 | + '5.3' => false, |
|
| 297 | + '5.4' => true, |
|
| 298 | + ), |
|
| 299 | + 'RecursiveCallbackFilterIterator' => array( |
|
| 300 | + '5.3' => false, |
|
| 301 | + '5.4' => true, |
|
| 302 | + ), |
|
| 303 | + 'ReflectionZendExtension' => array( |
|
| 304 | + '5.3' => false, |
|
| 305 | + '5.4' => true, |
|
| 306 | + ), |
|
| 307 | + 'SessionHandler' => array( |
|
| 308 | + '5.3' => false, |
|
| 309 | + '5.4' => true, |
|
| 310 | + ), |
|
| 311 | + 'SNMP' => array( |
|
| 312 | + '5.3' => false, |
|
| 313 | + '5.4' => true, |
|
| 314 | + ), |
|
| 315 | + 'Transliterator' => array( |
|
| 316 | + '5.3' => false, |
|
| 317 | + '5.4' => true, |
|
| 318 | + ), |
|
| 319 | + 'Spoofchecker' => array( |
|
| 320 | + '5.3' => false, |
|
| 321 | + '5.4' => true, |
|
| 322 | + ), |
|
| 323 | + |
|
| 324 | + 'Generator' => array( |
|
| 325 | + '5.4' => false, |
|
| 326 | + '5.5' => true, |
|
| 327 | + ), |
|
| 328 | + 'CURLFile' => array( |
|
| 329 | + '5.4' => false, |
|
| 330 | + '5.5' => true, |
|
| 331 | + ), |
|
| 332 | + 'DateTimeImmutable' => array( |
|
| 333 | + '5.4' => false, |
|
| 334 | + '5.5' => true, |
|
| 335 | + ), |
|
| 336 | + 'IntlCalendar' => array( |
|
| 337 | + '5.4' => false, |
|
| 338 | + '5.5' => true, |
|
| 339 | + ), |
|
| 340 | + 'IntlGregorianCalendar' => array( |
|
| 341 | + '5.4' => false, |
|
| 342 | + '5.5' => true, |
|
| 343 | + ), |
|
| 344 | + 'IntlTimeZone' => array( |
|
| 345 | + '5.4' => false, |
|
| 346 | + '5.5' => true, |
|
| 347 | + ), |
|
| 348 | + 'IntlBreakIterator' => array( |
|
| 349 | + '5.4' => false, |
|
| 350 | + '5.5' => true, |
|
| 351 | + ), |
|
| 352 | + 'IntlRuleBasedBreakIterator' => array( |
|
| 353 | + '5.4' => false, |
|
| 354 | + '5.5' => true, |
|
| 355 | + ), |
|
| 356 | + 'IntlCodePointBreakIterator' => array( |
|
| 357 | + '5.4' => false, |
|
| 358 | + '5.5' => true, |
|
| 359 | + ), |
|
| 360 | + 'UConverter' => array( |
|
| 361 | + '5.4' => false, |
|
| 362 | + '5.5' => true, |
|
| 363 | + ), |
|
| 364 | + |
|
| 365 | + 'GMP' => array( |
|
| 366 | + '5.5' => false, |
|
| 367 | + '5.6' => true, |
|
| 368 | + ), |
|
| 369 | + |
|
| 370 | + 'IntlChar' => array( |
|
| 371 | + '5.6' => false, |
|
| 372 | + '7.0' => true, |
|
| 373 | + ), |
|
| 374 | + 'ReflectionType' => array( |
|
| 375 | + '5.6' => false, |
|
| 376 | + '7.0' => true, |
|
| 377 | + ), |
|
| 378 | + 'ReflectionGenerator' => array( |
|
| 379 | + '5.6' => false, |
|
| 380 | + '7.0' => true, |
|
| 381 | + ), |
|
| 382 | + |
|
| 383 | + 'ReflectionClassConstant' => array( |
|
| 384 | + '7.0' => false, |
|
| 385 | + '7.1' => true, |
|
| 386 | + ), |
|
| 387 | + |
|
| 388 | + ); |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * A list of new Exception classes, not present in older versions. |
|
| 392 | + * |
|
| 393 | + * The array lists : version number with false (not present) or true (present). |
|
| 394 | + * If's sufficient to list the first version where the class appears. |
|
| 395 | + * |
|
| 396 | + * {@internal Classes listed here do not need to be added to the $newClasses |
|
| 397 | + * property as well. |
|
| 398 | + * This list is automatically added to the $newClasses property |
|
| 399 | + * in the `register()` method.}} |
|
| 400 | + * |
|
| 401 | + * {@internal Helper to update this list: https://3v4l.org/MhlUp}} |
|
| 402 | + * |
|
| 403 | + * @var array(string => array(string => bool)) |
|
| 404 | + */ |
|
| 405 | + protected $newExceptions = array( |
|
| 406 | + 'com_exception' => array( |
|
| 407 | + '4.4' => false, |
|
| 408 | + '5.0' => true, |
|
| 409 | + ), |
|
| 410 | + 'DOMException' => array( |
|
| 411 | + '4.4' => false, |
|
| 412 | + '5.0' => true, |
|
| 413 | + ), |
|
| 414 | + 'Exception' => array( |
|
| 415 | + // According to the docs introduced in PHP 5.1, but this appears to be. |
|
| 416 | + // an error. Class was introduced with try/catch keywords in PHP 5.0. |
|
| 417 | + '4.4' => false, |
|
| 418 | + '5.0' => true, |
|
| 419 | + ), |
|
| 420 | + 'ReflectionException' => array( |
|
| 421 | + '4.4' => false, |
|
| 422 | + '5.0' => true, |
|
| 423 | + ), |
|
| 424 | + 'SoapFault' => array( |
|
| 425 | + '4.4' => false, |
|
| 426 | + '5.0' => true, |
|
| 427 | + ), |
|
| 428 | + 'SQLiteException' => array( |
|
| 429 | + '4.4' => false, |
|
| 430 | + '5.0' => true, |
|
| 431 | + ), |
|
| 432 | + |
|
| 433 | + 'ErrorException' => array( |
|
| 434 | + '5.0' => false, |
|
| 435 | + '5.1' => true, |
|
| 436 | + ), |
|
| 437 | + 'BadFunctionCallException' => array( |
|
| 438 | + '5.0' => false, |
|
| 439 | + '5.1' => true, |
|
| 440 | + ), |
|
| 441 | + 'BadMethodCallException' => array( |
|
| 442 | + '5.0' => false, |
|
| 443 | + '5.1' => true, |
|
| 444 | + ), |
|
| 445 | + 'DomainException' => array( |
|
| 446 | + '5.0' => false, |
|
| 447 | + '5.1' => true, |
|
| 448 | + ), |
|
| 449 | + 'InvalidArgumentException' => array( |
|
| 450 | + '5.0' => false, |
|
| 451 | + '5.1' => true, |
|
| 452 | + ), |
|
| 453 | + 'LengthException' => array( |
|
| 454 | + '5.0' => false, |
|
| 455 | + '5.1' => true, |
|
| 456 | + ), |
|
| 457 | + 'LogicException' => array( |
|
| 458 | + '5.0' => false, |
|
| 459 | + '5.1' => true, |
|
| 460 | + ), |
|
| 461 | + 'mysqli_sql_exception' => array( |
|
| 462 | + '5.0' => false, |
|
| 463 | + '5.1' => true, |
|
| 464 | + ), |
|
| 465 | + 'OutOfBoundsException' => array( |
|
| 466 | + '5.0' => false, |
|
| 467 | + '5.1' => true, |
|
| 468 | + ), |
|
| 469 | + 'OutOfRangeException' => array( |
|
| 470 | + '5.0' => false, |
|
| 471 | + '5.1' => true, |
|
| 472 | + ), |
|
| 473 | + 'OverflowException' => array( |
|
| 474 | + '5.0' => false, |
|
| 475 | + '5.1' => true, |
|
| 476 | + ), |
|
| 477 | + 'PDOException' => array( |
|
| 478 | + '5.0' => false, |
|
| 479 | + '5.1' => true, |
|
| 480 | + ), |
|
| 481 | + 'RangeException' => array( |
|
| 482 | + '5.0' => false, |
|
| 483 | + '5.1' => true, |
|
| 484 | + ), |
|
| 485 | + 'RuntimeException' => array( |
|
| 486 | + '5.0' => false, |
|
| 487 | + '5.1' => true, |
|
| 488 | + ), |
|
| 489 | + 'UnderflowException' => array( |
|
| 490 | + '5.0' => false, |
|
| 491 | + '5.1' => true, |
|
| 492 | + ), |
|
| 493 | + 'UnexpectedValueException' => array( |
|
| 494 | + '5.0' => false, |
|
| 495 | + '5.1' => true, |
|
| 496 | + ), |
|
| 497 | + |
|
| 498 | + 'PharException' => array( |
|
| 499 | + '5.2' => false, |
|
| 500 | + '5.3' => true, |
|
| 501 | + ), |
|
| 502 | + |
|
| 503 | + 'SNMPException' => array( |
|
| 504 | + '5.3' => false, |
|
| 505 | + '5.4' => true, |
|
| 506 | + ), |
|
| 507 | + |
|
| 508 | + 'IntlException' => array( |
|
| 509 | + '5.4' => false, |
|
| 510 | + '5.5' => true, |
|
| 511 | + ), |
|
| 512 | + |
|
| 513 | + 'Error' => array( |
|
| 514 | + '5.6' => false, |
|
| 515 | + '7.0' => true, |
|
| 516 | + ), |
|
| 517 | + 'ArithmeticError' => array( |
|
| 518 | + '5.6' => false, |
|
| 519 | + '7.0' => true, |
|
| 520 | + ), |
|
| 521 | + 'AssertionError' => array( |
|
| 522 | + '5.6' => false, |
|
| 523 | + '7.0' => true, |
|
| 524 | + ), |
|
| 525 | + 'DivisionByZeroError' => array( |
|
| 526 | + '5.6' => false, |
|
| 527 | + '7.0' => true, |
|
| 528 | + ), |
|
| 529 | + 'ParseError' => array( |
|
| 530 | + '5.6' => false, |
|
| 531 | + '7.0' => true, |
|
| 532 | + ), |
|
| 533 | + 'TypeError' => array( |
|
| 534 | + '5.6' => false, |
|
| 535 | + '7.0' => true, |
|
| 536 | + ), |
|
| 537 | + 'ClosedGeneratorException' => array( |
|
| 538 | + '5.6' => false, |
|
| 539 | + '7.0' => true, |
|
| 540 | + ), |
|
| 541 | + 'UI\Exception\InvalidArgumentException' => array( |
|
| 542 | + '5.6' => false, |
|
| 543 | + '7.0' => true, |
|
| 544 | + ), |
|
| 545 | + 'UI\Exception\RuntimeException' => array( |
|
| 546 | + '5.6' => false, |
|
| 547 | + '7.0' => true, |
|
| 548 | + ), |
|
| 549 | + |
|
| 550 | + 'ArgumentCountError' => array( |
|
| 551 | + '7.0' => false, |
|
| 552 | + '7.1' => true, |
|
| 553 | + ), |
|
| 554 | + |
|
| 555 | + 'SodiumException' => array( |
|
| 556 | + '7.1' => false, |
|
| 557 | + '7.2' => true, |
|
| 558 | + ), |
|
| 559 | + |
|
| 560 | + 'CompileError' => array( |
|
| 561 | + '7.2' => false, |
|
| 562 | + '7.3' => true, |
|
| 563 | + ), |
|
| 564 | + 'JsonException' => array( |
|
| 565 | + '7.2' => false, |
|
| 566 | + '7.3' => true, |
|
| 567 | + ), |
|
| 568 | + |
|
| 569 | + 'ReflectionReference' => array( |
|
| 570 | + '7.3' => false, |
|
| 571 | + '7.4' => true, |
|
| 572 | + ), |
|
| 573 | + ); |
|
| 574 | + |
|
| 575 | + |
|
| 576 | + /** |
|
| 577 | + * Returns an array of tokens this test wants to listen for. |
|
| 578 | + * |
|
| 579 | + * @return array |
|
| 580 | + */ |
|
| 581 | + public function register() |
|
| 582 | + { |
|
| 583 | + // Handle case-insensitivity of class names. |
|
| 584 | + $this->newClasses = $this->arrayKeysToLowercase($this->newClasses); |
|
| 585 | + $this->newExceptions = $this->arrayKeysToLowercase($this->newExceptions); |
|
| 586 | + |
|
| 587 | + // Add the Exception classes to the Classes list. |
|
| 588 | + $this->newClasses = array_merge($this->newClasses, $this->newExceptions); |
|
| 589 | + |
|
| 590 | + $targets = array( |
|
| 591 | + \T_NEW, |
|
| 592 | + \T_CLASS, |
|
| 593 | + \T_DOUBLE_COLON, |
|
| 594 | + \T_FUNCTION, |
|
| 595 | + \T_CLOSURE, |
|
| 596 | + \T_CATCH, |
|
| 597 | + ); |
|
| 598 | + |
|
| 599 | + if (\defined('T_ANON_CLASS')) { |
|
| 600 | + $targets[] = \T_ANON_CLASS; |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + if (\defined('T_RETURN_TYPE')) { |
|
| 604 | + $targets[] = \T_RETURN_TYPE; |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + return $targets; |
|
| 608 | + } |
|
| 609 | + |
|
| 610 | + |
|
| 611 | + /** |
|
| 612 | + * Processes this test, when one of its tokens is encountered. |
|
| 613 | + * |
|
| 614 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 615 | + * @param int $stackPtr The position of the current token in |
|
| 616 | + * the stack passed in $tokens. |
|
| 617 | + * |
|
| 618 | + * @return void |
|
| 619 | + */ |
|
| 620 | + public function process(File $phpcsFile, $stackPtr) |
|
| 621 | + { |
|
| 622 | + $tokens = $phpcsFile->getTokens(); |
|
| 623 | + |
|
| 624 | + switch ($tokens[$stackPtr]['type']) { |
|
| 625 | + case 'T_FUNCTION': |
|
| 626 | + case 'T_CLOSURE': |
|
| 627 | + $this->processFunctionToken($phpcsFile, $stackPtr); |
|
| 628 | + |
|
| 629 | + // Deal with older PHPCS version which don't recognize return type hints |
|
| 630 | + // as well as newer PHPCS versions (3.3.0+) where the tokenization has changed. |
|
| 631 | + $returnTypeHint = $this->getReturnTypeHintToken($phpcsFile, $stackPtr); |
|
| 632 | + if ($returnTypeHint !== false) { |
|
| 633 | + $this->processReturnTypeToken($phpcsFile, $returnTypeHint); |
|
| 634 | + } |
|
| 635 | + break; |
|
| 636 | + |
|
| 637 | + case 'T_CATCH': |
|
| 638 | + $this->processCatchToken($phpcsFile, $stackPtr); |
|
| 639 | + break; |
|
| 640 | + |
|
| 641 | + case 'T_RETURN_TYPE': |
|
| 642 | + $this->processReturnTypeToken($phpcsFile, $stackPtr); |
|
| 643 | + break; |
|
| 644 | + |
|
| 645 | + default: |
|
| 646 | + $this->processSingularToken($phpcsFile, $stackPtr); |
|
| 647 | + break; |
|
| 648 | + } |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + |
|
| 652 | + /** |
|
| 653 | + * Processes this test for when a token resulting in a singular class name is encountered. |
|
| 654 | + * |
|
| 655 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 656 | + * @param int $stackPtr The position of the current token in |
|
| 657 | + * the stack passed in $tokens. |
|
| 658 | + * |
|
| 659 | + * @return void |
|
| 660 | + */ |
|
| 661 | + private function processSingularToken(File $phpcsFile, $stackPtr) |
|
| 662 | + { |
|
| 663 | + $tokens = $phpcsFile->getTokens(); |
|
| 664 | + $FQClassName = ''; |
|
| 665 | + |
|
| 666 | + if ($tokens[$stackPtr]['type'] === 'T_NEW') { |
|
| 667 | + $FQClassName = $this->getFQClassNameFromNewToken($phpcsFile, $stackPtr); |
|
| 668 | + |
|
| 669 | + } elseif ($tokens[$stackPtr]['type'] === 'T_CLASS' || $tokens[$stackPtr]['type'] === 'T_ANON_CLASS') { |
|
| 670 | + $FQClassName = $this->getFQExtendedClassName($phpcsFile, $stackPtr); |
|
| 671 | + |
|
| 672 | + } elseif ($tokens[$stackPtr]['type'] === 'T_DOUBLE_COLON') { |
|
| 673 | + $FQClassName = $this->getFQClassNameFromDoubleColonToken($phpcsFile, $stackPtr); |
|
| 674 | + } |
|
| 675 | + |
|
| 676 | + if ($FQClassName === '') { |
|
| 677 | + return; |
|
| 678 | + } |
|
| 679 | + |
|
| 680 | + $className = substr($FQClassName, 1); // Remove global namespace indicator. |
|
| 681 | + $classNameLc = strtolower($className); |
|
| 682 | + |
|
| 683 | + if (isset($this->newClasses[$classNameLc]) === false) { |
|
| 684 | + return; |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + $itemInfo = array( |
|
| 688 | + 'name' => $className, |
|
| 689 | + 'nameLc' => $classNameLc, |
|
| 690 | + ); |
|
| 691 | + $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + |
|
| 695 | + /** |
|
| 696 | + * Processes this test for when a function token is encountered. |
|
| 697 | + * |
|
| 698 | + * - Detect new classes when used as a type hint. |
|
| 699 | + * |
|
| 700 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 701 | + * @param int $stackPtr The position of the current token in |
|
| 702 | + * the stack passed in $tokens. |
|
| 703 | + * |
|
| 704 | + * @return void |
|
| 705 | + */ |
|
| 706 | + private function processFunctionToken(File $phpcsFile, $stackPtr) |
|
| 707 | + { |
|
| 708 | + // Retrieve typehints stripped of global NS indicator and/or nullable indicator. |
|
| 709 | + $typeHints = $this->getTypeHintsFromFunctionDeclaration($phpcsFile, $stackPtr); |
|
| 710 | + if (empty($typeHints) || \is_array($typeHints) === false) { |
|
| 711 | + return; |
|
| 712 | + } |
|
| 713 | + |
|
| 714 | + foreach ($typeHints as $hint) { |
|
| 715 | + |
|
| 716 | + $typeHintLc = strtolower($hint); |
|
| 717 | + |
|
| 718 | + if (isset($this->newClasses[$typeHintLc]) === true) { |
|
| 719 | + $itemInfo = array( |
|
| 720 | + 'name' => $hint, |
|
| 721 | + 'nameLc' => $typeHintLc, |
|
| 722 | + ); |
|
| 723 | + $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
| 724 | + } |
|
| 725 | + } |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + |
|
| 729 | + /** |
|
| 730 | + * Processes this test for when a catch token is encountered. |
|
| 731 | + * |
|
| 732 | + * - Detect exceptions when used in a catch statement. |
|
| 733 | + * |
|
| 734 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 735 | + * @param int $stackPtr The position of the current token in |
|
| 736 | + * the stack passed in $tokens. |
|
| 737 | + * |
|
| 738 | + * @return void |
|
| 739 | + */ |
|
| 740 | + private function processCatchToken(File $phpcsFile, $stackPtr) |
|
| 741 | + { |
|
| 742 | + $tokens = $phpcsFile->getTokens(); |
|
| 743 | + |
|
| 744 | + // Bow out during live coding. |
|
| 745 | + if (isset($tokens[$stackPtr]['parenthesis_opener'], $tokens[$stackPtr]['parenthesis_closer']) === false) { |
|
| 746 | + return; |
|
| 747 | + } |
|
| 748 | + |
|
| 749 | + $opener = $tokens[$stackPtr]['parenthesis_opener']; |
|
| 750 | + $closer = ($tokens[$stackPtr]['parenthesis_closer'] + 1); |
|
| 751 | + $name = ''; |
|
| 752 | + $listen = array( |
|
| 753 | + // Parts of a (namespaced) class name. |
|
| 754 | + \T_STRING => true, |
|
| 755 | + \T_NS_SEPARATOR => true, |
|
| 756 | + // End/split tokens. |
|
| 757 | + \T_VARIABLE => false, |
|
| 758 | + \T_BITWISE_OR => false, |
|
| 759 | + \T_CLOSE_CURLY_BRACKET => false, // Shouldn't be needed as we expect a var before this. |
|
| 760 | + ); |
|
| 761 | + |
|
| 762 | + for ($i = ($opener + 1); $i < $closer; $i++) { |
|
| 763 | + if (isset($listen[$tokens[$i]['code']]) === false) { |
|
| 764 | + continue; |
|
| 765 | + } |
|
| 766 | + |
|
| 767 | + if ($listen[$tokens[$i]['code']] === true) { |
|
| 768 | + $name .= $tokens[$i]['content']; |
|
| 769 | + continue; |
|
| 770 | + } else { |
|
| 771 | + if (empty($name) === true) { |
|
| 772 | + // Weird, we should have a name by the time we encounter a variable or |. |
|
| 773 | + // So this may be the closer. |
|
| 774 | + continue; |
|
| 775 | + } |
|
| 776 | + |
|
| 777 | + $name = ltrim($name, '\\'); |
|
| 778 | + $nameLC = strtolower($name); |
|
| 779 | + |
|
| 780 | + if (isset($this->newExceptions[$nameLC]) === true) { |
|
| 781 | + $itemInfo = array( |
|
| 782 | + 'name' => $name, |
|
| 783 | + 'nameLc' => $nameLC, |
|
| 784 | + ); |
|
| 785 | + $this->handleFeature($phpcsFile, $i, $itemInfo); |
|
| 786 | + } |
|
| 787 | + |
|
| 788 | + // Reset for a potential multi-catch. |
|
| 789 | + $name = ''; |
|
| 790 | + } |
|
| 791 | + } |
|
| 792 | + } |
|
| 793 | + |
|
| 794 | + |
|
| 795 | + /** |
|
| 796 | + * Processes this test for when a return type token is encountered. |
|
| 797 | + * |
|
| 798 | + * - Detect new classes when used as a return type declaration. |
|
| 799 | + * |
|
| 800 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 801 | + * @param int $stackPtr The position of the current token in |
|
| 802 | + * the stack passed in $tokens. |
|
| 803 | + * |
|
| 804 | + * @return void |
|
| 805 | + */ |
|
| 806 | + private function processReturnTypeToken(File $phpcsFile, $stackPtr) |
|
| 807 | + { |
|
| 808 | + $returnTypeHint = $this->getReturnTypeHintName($phpcsFile, $stackPtr); |
|
| 809 | + $returnTypeHint = ltrim($returnTypeHint, '\\'); |
|
| 810 | + $returnTypeHintLc = strtolower($returnTypeHint); |
|
| 811 | + |
|
| 812 | + if (isset($this->newClasses[$returnTypeHintLc]) === false) { |
|
| 813 | + return; |
|
| 814 | + } |
|
| 815 | + |
|
| 816 | + // Still here ? Then this is a return type declaration using a new class. |
|
| 817 | + $itemInfo = array( |
|
| 818 | + 'name' => $returnTypeHint, |
|
| 819 | + 'nameLc' => $returnTypeHintLc, |
|
| 820 | + ); |
|
| 821 | + $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
| 822 | + } |
|
| 823 | + |
|
| 824 | + |
|
| 825 | + /** |
|
| 826 | + * Get the relevant sub-array for a specific item from a multi-dimensional array. |
|
| 827 | + * |
|
| 828 | + * @param array $itemInfo Base information about the item. |
|
| 829 | + * |
|
| 830 | + * @return array Version and other information about the item. |
|
| 831 | + */ |
|
| 832 | + public function getItemArray(array $itemInfo) |
|
| 833 | + { |
|
| 834 | + return $this->newClasses[$itemInfo['nameLc']]; |
|
| 835 | + } |
|
| 836 | + |
|
| 837 | + |
|
| 838 | + /** |
|
| 839 | + * Get the error message template for this sniff. |
|
| 840 | + * |
|
| 841 | + * @return string |
|
| 842 | + */ |
|
| 843 | + protected function getErrorMsgTemplate() |
|
| 844 | + { |
|
| 845 | + return 'The built-in class ' . parent::getErrorMsgTemplate(); |
|
| 846 | + } |
|
| 847 | 847 | } |
@@ -581,11 +581,11 @@ discard block |
||
| 581 | 581 | public function register() |
| 582 | 582 | { |
| 583 | 583 | // Handle case-insensitivity of class names. |
| 584 | - $this->newClasses = $this->arrayKeysToLowercase($this->newClasses); |
|
| 585 | - $this->newExceptions = $this->arrayKeysToLowercase($this->newExceptions); |
|
| 584 | + $this->newClasses = $this->arrayKeysToLowercase( $this->newClasses ); |
|
| 585 | + $this->newExceptions = $this->arrayKeysToLowercase( $this->newExceptions ); |
|
| 586 | 586 | |
| 587 | 587 | // Add the Exception classes to the Classes list. |
| 588 | - $this->newClasses = array_merge($this->newClasses, $this->newExceptions); |
|
| 588 | + $this->newClasses = array_merge( $this->newClasses, $this->newExceptions ); |
|
| 589 | 589 | |
| 590 | 590 | $targets = array( |
| 591 | 591 | \T_NEW, |
@@ -596,12 +596,12 @@ discard block |
||
| 596 | 596 | \T_CATCH, |
| 597 | 597 | ); |
| 598 | 598 | |
| 599 | - if (\defined('T_ANON_CLASS')) { |
|
| 600 | - $targets[] = \T_ANON_CLASS; |
|
| 599 | + if ( \defined( 'T_ANON_CLASS' ) ) { |
|
| 600 | + $targets[ ] = \T_ANON_CLASS; |
|
| 601 | 601 | } |
| 602 | 602 | |
| 603 | - if (\defined('T_RETURN_TYPE')) { |
|
| 604 | - $targets[] = \T_RETURN_TYPE; |
|
| 603 | + if ( \defined( 'T_RETURN_TYPE' ) ) { |
|
| 604 | + $targets[ ] = \T_RETURN_TYPE; |
|
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | return $targets; |
@@ -617,33 +617,33 @@ discard block |
||
| 617 | 617 | * |
| 618 | 618 | * @return void |
| 619 | 619 | */ |
| 620 | - public function process(File $phpcsFile, $stackPtr) |
|
| 620 | + public function process( File $phpcsFile, $stackPtr ) |
|
| 621 | 621 | { |
| 622 | 622 | $tokens = $phpcsFile->getTokens(); |
| 623 | 623 | |
| 624 | - switch ($tokens[$stackPtr]['type']) { |
|
| 624 | + switch ( $tokens[ $stackPtr ][ 'type' ] ) { |
|
| 625 | 625 | case 'T_FUNCTION': |
| 626 | 626 | case 'T_CLOSURE': |
| 627 | - $this->processFunctionToken($phpcsFile, $stackPtr); |
|
| 627 | + $this->processFunctionToken( $phpcsFile, $stackPtr ); |
|
| 628 | 628 | |
| 629 | 629 | // Deal with older PHPCS version which don't recognize return type hints |
| 630 | 630 | // as well as newer PHPCS versions (3.3.0+) where the tokenization has changed. |
| 631 | - $returnTypeHint = $this->getReturnTypeHintToken($phpcsFile, $stackPtr); |
|
| 632 | - if ($returnTypeHint !== false) { |
|
| 633 | - $this->processReturnTypeToken($phpcsFile, $returnTypeHint); |
|
| 631 | + $returnTypeHint = $this->getReturnTypeHintToken( $phpcsFile, $stackPtr ); |
|
| 632 | + if ( $returnTypeHint !== false ) { |
|
| 633 | + $this->processReturnTypeToken( $phpcsFile, $returnTypeHint ); |
|
| 634 | 634 | } |
| 635 | 635 | break; |
| 636 | 636 | |
| 637 | 637 | case 'T_CATCH': |
| 638 | - $this->processCatchToken($phpcsFile, $stackPtr); |
|
| 638 | + $this->processCatchToken( $phpcsFile, $stackPtr ); |
|
| 639 | 639 | break; |
| 640 | 640 | |
| 641 | 641 | case 'T_RETURN_TYPE': |
| 642 | - $this->processReturnTypeToken($phpcsFile, $stackPtr); |
|
| 642 | + $this->processReturnTypeToken( $phpcsFile, $stackPtr ); |
|
| 643 | 643 | break; |
| 644 | 644 | |
| 645 | 645 | default: |
| 646 | - $this->processSingularToken($phpcsFile, $stackPtr); |
|
| 646 | + $this->processSingularToken( $phpcsFile, $stackPtr ); |
|
| 647 | 647 | break; |
| 648 | 648 | } |
| 649 | 649 | } |
@@ -658,29 +658,29 @@ discard block |
||
| 658 | 658 | * |
| 659 | 659 | * @return void |
| 660 | 660 | */ |
| 661 | - private function processSingularToken(File $phpcsFile, $stackPtr) |
|
| 661 | + private function processSingularToken( File $phpcsFile, $stackPtr ) |
|
| 662 | 662 | { |
| 663 | 663 | $tokens = $phpcsFile->getTokens(); |
| 664 | 664 | $FQClassName = ''; |
| 665 | 665 | |
| 666 | - if ($tokens[$stackPtr]['type'] === 'T_NEW') { |
|
| 667 | - $FQClassName = $this->getFQClassNameFromNewToken($phpcsFile, $stackPtr); |
|
| 666 | + if ( $tokens[ $stackPtr ][ 'type' ] === 'T_NEW' ) { |
|
| 667 | + $FQClassName = $this->getFQClassNameFromNewToken( $phpcsFile, $stackPtr ); |
|
| 668 | 668 | |
| 669 | - } elseif ($tokens[$stackPtr]['type'] === 'T_CLASS' || $tokens[$stackPtr]['type'] === 'T_ANON_CLASS') { |
|
| 670 | - $FQClassName = $this->getFQExtendedClassName($phpcsFile, $stackPtr); |
|
| 669 | + } elseif ( $tokens[ $stackPtr ][ 'type' ] === 'T_CLASS' || $tokens[ $stackPtr ][ 'type' ] === 'T_ANON_CLASS' ) { |
|
| 670 | + $FQClassName = $this->getFQExtendedClassName( $phpcsFile, $stackPtr ); |
|
| 671 | 671 | |
| 672 | - } elseif ($tokens[$stackPtr]['type'] === 'T_DOUBLE_COLON') { |
|
| 673 | - $FQClassName = $this->getFQClassNameFromDoubleColonToken($phpcsFile, $stackPtr); |
|
| 672 | + } elseif ( $tokens[ $stackPtr ][ 'type' ] === 'T_DOUBLE_COLON' ) { |
|
| 673 | + $FQClassName = $this->getFQClassNameFromDoubleColonToken( $phpcsFile, $stackPtr ); |
|
| 674 | 674 | } |
| 675 | 675 | |
| 676 | - if ($FQClassName === '') { |
|
| 676 | + if ( $FQClassName === '' ) { |
|
| 677 | 677 | return; |
| 678 | 678 | } |
| 679 | 679 | |
| 680 | - $className = substr($FQClassName, 1); // Remove global namespace indicator. |
|
| 681 | - $classNameLc = strtolower($className); |
|
| 680 | + $className = substr( $FQClassName, 1 ); // Remove global namespace indicator. |
|
| 681 | + $classNameLc = strtolower( $className ); |
|
| 682 | 682 | |
| 683 | - if (isset($this->newClasses[$classNameLc]) === false) { |
|
| 683 | + if ( isset( $this->newClasses[ $classNameLc ] ) === false ) { |
|
| 684 | 684 | return; |
| 685 | 685 | } |
| 686 | 686 | |
@@ -688,7 +688,7 @@ discard block |
||
| 688 | 688 | 'name' => $className, |
| 689 | 689 | 'nameLc' => $classNameLc, |
| 690 | 690 | ); |
| 691 | - $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
| 691 | + $this->handleFeature( $phpcsFile, $stackPtr, $itemInfo ); |
|
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | |
@@ -703,24 +703,24 @@ discard block |
||
| 703 | 703 | * |
| 704 | 704 | * @return void |
| 705 | 705 | */ |
| 706 | - private function processFunctionToken(File $phpcsFile, $stackPtr) |
|
| 706 | + private function processFunctionToken( File $phpcsFile, $stackPtr ) |
|
| 707 | 707 | { |
| 708 | 708 | // Retrieve typehints stripped of global NS indicator and/or nullable indicator. |
| 709 | - $typeHints = $this->getTypeHintsFromFunctionDeclaration($phpcsFile, $stackPtr); |
|
| 710 | - if (empty($typeHints) || \is_array($typeHints) === false) { |
|
| 709 | + $typeHints = $this->getTypeHintsFromFunctionDeclaration( $phpcsFile, $stackPtr ); |
|
| 710 | + if ( empty( $typeHints ) || \is_array( $typeHints ) === false ) { |
|
| 711 | 711 | return; |
| 712 | 712 | } |
| 713 | 713 | |
| 714 | - foreach ($typeHints as $hint) { |
|
| 714 | + foreach ( $typeHints as $hint ) { |
|
| 715 | 715 | |
| 716 | - $typeHintLc = strtolower($hint); |
|
| 716 | + $typeHintLc = strtolower( $hint ); |
|
| 717 | 717 | |
| 718 | - if (isset($this->newClasses[$typeHintLc]) === true) { |
|
| 718 | + if ( isset( $this->newClasses[ $typeHintLc ] ) === true ) { |
|
| 719 | 719 | $itemInfo = array( |
| 720 | 720 | 'name' => $hint, |
| 721 | 721 | 'nameLc' => $typeHintLc, |
| 722 | 722 | ); |
| 723 | - $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
| 723 | + $this->handleFeature( $phpcsFile, $stackPtr, $itemInfo ); |
|
| 724 | 724 | } |
| 725 | 725 | } |
| 726 | 726 | } |
@@ -737,17 +737,17 @@ discard block |
||
| 737 | 737 | * |
| 738 | 738 | * @return void |
| 739 | 739 | */ |
| 740 | - private function processCatchToken(File $phpcsFile, $stackPtr) |
|
| 740 | + private function processCatchToken( File $phpcsFile, $stackPtr ) |
|
| 741 | 741 | { |
| 742 | 742 | $tokens = $phpcsFile->getTokens(); |
| 743 | 743 | |
| 744 | 744 | // Bow out during live coding. |
| 745 | - if (isset($tokens[$stackPtr]['parenthesis_opener'], $tokens[$stackPtr]['parenthesis_closer']) === false) { |
|
| 745 | + if ( isset( $tokens[ $stackPtr ][ 'parenthesis_opener' ], $tokens[ $stackPtr ][ 'parenthesis_closer' ] ) === false ) { |
|
| 746 | 746 | return; |
| 747 | 747 | } |
| 748 | 748 | |
| 749 | - $opener = $tokens[$stackPtr]['parenthesis_opener']; |
|
| 750 | - $closer = ($tokens[$stackPtr]['parenthesis_closer'] + 1); |
|
| 749 | + $opener = $tokens[ $stackPtr ][ 'parenthesis_opener' ]; |
|
| 750 | + $closer = ( $tokens[ $stackPtr ][ 'parenthesis_closer' ] + 1 ); |
|
| 751 | 751 | $name = ''; |
| 752 | 752 | $listen = array( |
| 753 | 753 | // Parts of a (namespaced) class name. |
@@ -759,30 +759,30 @@ discard block |
||
| 759 | 759 | \T_CLOSE_CURLY_BRACKET => false, // Shouldn't be needed as we expect a var before this. |
| 760 | 760 | ); |
| 761 | 761 | |
| 762 | - for ($i = ($opener + 1); $i < $closer; $i++) { |
|
| 763 | - if (isset($listen[$tokens[$i]['code']]) === false) { |
|
| 762 | + for ( $i = ( $opener + 1 ); $i < $closer; $i++ ) { |
|
| 763 | + if ( isset( $listen[ $tokens[ $i ][ 'code' ] ] ) === false ) { |
|
| 764 | 764 | continue; |
| 765 | 765 | } |
| 766 | 766 | |
| 767 | - if ($listen[$tokens[$i]['code']] === true) { |
|
| 768 | - $name .= $tokens[$i]['content']; |
|
| 767 | + if ( $listen[ $tokens[ $i ][ 'code' ] ] === true ) { |
|
| 768 | + $name .= $tokens[ $i ][ 'content' ]; |
|
| 769 | 769 | continue; |
| 770 | 770 | } else { |
| 771 | - if (empty($name) === true) { |
|
| 771 | + if ( empty( $name ) === true ) { |
|
| 772 | 772 | // Weird, we should have a name by the time we encounter a variable or |. |
| 773 | 773 | // So this may be the closer. |
| 774 | 774 | continue; |
| 775 | 775 | } |
| 776 | 776 | |
| 777 | - $name = ltrim($name, '\\'); |
|
| 778 | - $nameLC = strtolower($name); |
|
| 777 | + $name = ltrim( $name, '\\' ); |
|
| 778 | + $nameLC = strtolower( $name ); |
|
| 779 | 779 | |
| 780 | - if (isset($this->newExceptions[$nameLC]) === true) { |
|
| 780 | + if ( isset( $this->newExceptions[ $nameLC ] ) === true ) { |
|
| 781 | 781 | $itemInfo = array( |
| 782 | 782 | 'name' => $name, |
| 783 | 783 | 'nameLc' => $nameLC, |
| 784 | 784 | ); |
| 785 | - $this->handleFeature($phpcsFile, $i, $itemInfo); |
|
| 785 | + $this->handleFeature( $phpcsFile, $i, $itemInfo ); |
|
| 786 | 786 | } |
| 787 | 787 | |
| 788 | 788 | // Reset for a potential multi-catch. |
@@ -803,13 +803,13 @@ discard block |
||
| 803 | 803 | * |
| 804 | 804 | * @return void |
| 805 | 805 | */ |
| 806 | - private function processReturnTypeToken(File $phpcsFile, $stackPtr) |
|
| 806 | + private function processReturnTypeToken( File $phpcsFile, $stackPtr ) |
|
| 807 | 807 | { |
| 808 | - $returnTypeHint = $this->getReturnTypeHintName($phpcsFile, $stackPtr); |
|
| 809 | - $returnTypeHint = ltrim($returnTypeHint, '\\'); |
|
| 810 | - $returnTypeHintLc = strtolower($returnTypeHint); |
|
| 808 | + $returnTypeHint = $this->getReturnTypeHintName( $phpcsFile, $stackPtr ); |
|
| 809 | + $returnTypeHint = ltrim( $returnTypeHint, '\\' ); |
|
| 810 | + $returnTypeHintLc = strtolower( $returnTypeHint ); |
|
| 811 | 811 | |
| 812 | - if (isset($this->newClasses[$returnTypeHintLc]) === false) { |
|
| 812 | + if ( isset( $this->newClasses[ $returnTypeHintLc ] ) === false ) { |
|
| 813 | 813 | return; |
| 814 | 814 | } |
| 815 | 815 | |
@@ -818,7 +818,7 @@ discard block |
||
| 818 | 818 | 'name' => $returnTypeHint, |
| 819 | 819 | 'nameLc' => $returnTypeHintLc, |
| 820 | 820 | ); |
| 821 | - $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
| 821 | + $this->handleFeature( $phpcsFile, $stackPtr, $itemInfo ); |
|
| 822 | 822 | } |
| 823 | 823 | |
| 824 | 824 | |
@@ -829,9 +829,9 @@ discard block |
||
| 829 | 829 | * |
| 830 | 830 | * @return array Version and other information about the item. |
| 831 | 831 | */ |
| 832 | - public function getItemArray(array $itemInfo) |
|
| 832 | + public function getItemArray( array $itemInfo ) |
|
| 833 | 833 | { |
| 834 | - return $this->newClasses[$itemInfo['nameLc']]; |
|
| 834 | + return $this->newClasses[ $itemInfo[ 'nameLc' ] ]; |
|
| 835 | 835 | } |
| 836 | 836 | |
| 837 | 837 | |
@@ -21,8 +21,7 @@ discard block |
||
| 21 | 21 | * @author Wim Godden <[email protected]> |
| 22 | 22 | * @copyright 2013 Cu.be Solutions bvba |
| 23 | 23 | */ |
| 24 | -class NewClassesSniff extends AbstractNewFeatureSniff |
|
| 25 | -{ |
|
| 24 | +class NewClassesSniff extends AbstractNewFeatureSniff { |
|
| 26 | 25 | |
| 27 | 26 | /** |
| 28 | 27 | * A list of new classes, not present in older versions. |
@@ -578,8 +577,7 @@ discard block |
||
| 578 | 577 | * |
| 579 | 578 | * @return array |
| 580 | 579 | */ |
| 581 | - public function register() |
|
| 582 | - { |
|
| 580 | + public function register() { |
|
| 583 | 581 | // Handle case-insensitivity of class names. |
| 584 | 582 | $this->newClasses = $this->arrayKeysToLowercase($this->newClasses); |
| 585 | 583 | $this->newExceptions = $this->arrayKeysToLowercase($this->newExceptions); |
@@ -617,8 +615,7 @@ discard block |
||
| 617 | 615 | * |
| 618 | 616 | * @return void |
| 619 | 617 | */ |
| 620 | - public function process(File $phpcsFile, $stackPtr) |
|
| 621 | - { |
|
| 618 | + public function process(File $phpcsFile, $stackPtr) { |
|
| 622 | 619 | $tokens = $phpcsFile->getTokens(); |
| 623 | 620 | |
| 624 | 621 | switch ($tokens[$stackPtr]['type']) { |
@@ -658,8 +655,7 @@ discard block |
||
| 658 | 655 | * |
| 659 | 656 | * @return void |
| 660 | 657 | */ |
| 661 | - private function processSingularToken(File $phpcsFile, $stackPtr) |
|
| 662 | - { |
|
| 658 | + private function processSingularToken(File $phpcsFile, $stackPtr) { |
|
| 663 | 659 | $tokens = $phpcsFile->getTokens(); |
| 664 | 660 | $FQClassName = ''; |
| 665 | 661 | |
@@ -703,8 +699,7 @@ discard block |
||
| 703 | 699 | * |
| 704 | 700 | * @return void |
| 705 | 701 | */ |
| 706 | - private function processFunctionToken(File $phpcsFile, $stackPtr) |
|
| 707 | - { |
|
| 702 | + private function processFunctionToken(File $phpcsFile, $stackPtr) { |
|
| 708 | 703 | // Retrieve typehints stripped of global NS indicator and/or nullable indicator. |
| 709 | 704 | $typeHints = $this->getTypeHintsFromFunctionDeclaration($phpcsFile, $stackPtr); |
| 710 | 705 | if (empty($typeHints) || \is_array($typeHints) === false) { |
@@ -737,8 +732,7 @@ discard block |
||
| 737 | 732 | * |
| 738 | 733 | * @return void |
| 739 | 734 | */ |
| 740 | - private function processCatchToken(File $phpcsFile, $stackPtr) |
|
| 741 | - { |
|
| 735 | + private function processCatchToken(File $phpcsFile, $stackPtr) { |
|
| 742 | 736 | $tokens = $phpcsFile->getTokens(); |
| 743 | 737 | |
| 744 | 738 | // Bow out during live coding. |
@@ -803,8 +797,7 @@ discard block |
||
| 803 | 797 | * |
| 804 | 798 | * @return void |
| 805 | 799 | */ |
| 806 | - private function processReturnTypeToken(File $phpcsFile, $stackPtr) |
|
| 807 | - { |
|
| 800 | + private function processReturnTypeToken(File $phpcsFile, $stackPtr) { |
|
| 808 | 801 | $returnTypeHint = $this->getReturnTypeHintName($phpcsFile, $stackPtr); |
| 809 | 802 | $returnTypeHint = ltrim($returnTypeHint, '\\'); |
| 810 | 803 | $returnTypeHintLc = strtolower($returnTypeHint); |
@@ -829,8 +822,7 @@ discard block |
||
| 829 | 822 | * |
| 830 | 823 | * @return array Version and other information about the item. |
| 831 | 824 | */ |
| 832 | - public function getItemArray(array $itemInfo) |
|
| 833 | - { |
|
| 825 | + public function getItemArray(array $itemInfo) { |
|
| 834 | 826 | return $this->newClasses[$itemInfo['nameLc']]; |
| 835 | 827 | } |
| 836 | 828 | |
@@ -840,8 +832,7 @@ discard block |
||
| 840 | 832 | * |
| 841 | 833 | * @return string |
| 842 | 834 | */ |
| 843 | - protected function getErrorMsgTemplate() |
|
| 844 | - { |
|
| 835 | + protected function getErrorMsgTemplate() { |
|
| 845 | 836 | return 'The built-in class ' . parent::getErrorMsgTemplate(); |
| 846 | 837 | } |
| 847 | 838 | } |
@@ -26,100 +26,100 @@ |
||
| 26 | 26 | class NewTypedPropertiesSniff extends Sniff |
| 27 | 27 | { |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Valid property modifier keywords. |
|
| 31 | - * |
|
| 32 | - * @var array |
|
| 33 | - */ |
|
| 34 | - private $modifierKeywords = array( |
|
| 35 | - \T_PRIVATE => \T_PRIVATE, |
|
| 36 | - \T_PROTECTED => \T_PROTECTED, |
|
| 37 | - \T_PUBLIC => \T_PUBLIC, |
|
| 38 | - \T_STATIC => \T_STATIC, |
|
| 39 | - \T_VAR => \T_VAR, |
|
| 40 | - ); |
|
| 29 | + /** |
|
| 30 | + * Valid property modifier keywords. |
|
| 31 | + * |
|
| 32 | + * @var array |
|
| 33 | + */ |
|
| 34 | + private $modifierKeywords = array( |
|
| 35 | + \T_PRIVATE => \T_PRIVATE, |
|
| 36 | + \T_PROTECTED => \T_PROTECTED, |
|
| 37 | + \T_PUBLIC => \T_PUBLIC, |
|
| 38 | + \T_STATIC => \T_STATIC, |
|
| 39 | + \T_VAR => \T_VAR, |
|
| 40 | + ); |
|
| 41 | 41 | |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Returns an array of tokens this test wants to listen for. |
|
| 45 | - * |
|
| 46 | - * @return array |
|
| 47 | - */ |
|
| 48 | - public function register() |
|
| 49 | - { |
|
| 50 | - return array(\T_VARIABLE); |
|
| 51 | - } |
|
| 43 | + /** |
|
| 44 | + * Returns an array of tokens this test wants to listen for. |
|
| 45 | + * |
|
| 46 | + * @return array |
|
| 47 | + */ |
|
| 48 | + public function register() |
|
| 49 | + { |
|
| 50 | + return array(\T_VARIABLE); |
|
| 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 the |
|
| 58 | - * stack passed in $tokens. |
|
| 59 | - * |
|
| 60 | - * @return int|void Integer stack pointer to skip forward or void to continue |
|
| 61 | - * normal file processing. |
|
| 62 | - */ |
|
| 63 | - public function process(File $phpcsFile, $stackPtr) |
|
| 64 | - { |
|
| 65 | - if ($this->isClassProperty($phpcsFile, $stackPtr) === false) { |
|
| 66 | - return; |
|
| 67 | - } |
|
| 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 the |
|
| 58 | + * stack passed in $tokens. |
|
| 59 | + * |
|
| 60 | + * @return int|void Integer stack pointer to skip forward or void to continue |
|
| 61 | + * normal file processing. |
|
| 62 | + */ |
|
| 63 | + public function process(File $phpcsFile, $stackPtr) |
|
| 64 | + { |
|
| 65 | + if ($this->isClassProperty($phpcsFile, $stackPtr) === false) { |
|
| 66 | + return; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - $find = $this->modifierKeywords; |
|
| 70 | - $find += array( |
|
| 71 | - \T_SEMICOLON => \T_SEMICOLON, |
|
| 72 | - \T_OPEN_CURLY_BRACKET => \T_OPEN_CURLY_BRACKET, |
|
| 73 | - ); |
|
| 69 | + $find = $this->modifierKeywords; |
|
| 70 | + $find += array( |
|
| 71 | + \T_SEMICOLON => \T_SEMICOLON, |
|
| 72 | + \T_OPEN_CURLY_BRACKET => \T_OPEN_CURLY_BRACKET, |
|
| 73 | + ); |
|
| 74 | 74 | |
| 75 | - $tokens = $phpcsFile->getTokens(); |
|
| 76 | - $modifier = $phpcsFile->findPrevious($find, ($stackPtr - 1)); |
|
| 77 | - if ($modifier === false |
|
| 78 | - || $tokens[$modifier]['code'] === \T_SEMICOLON |
|
| 79 | - || $tokens[$modifier]['code'] === \T_OPEN_CURLY_BRACKET |
|
| 80 | - ) { |
|
| 81 | - // Parse error. Ignore. |
|
| 82 | - return; |
|
| 83 | - } |
|
| 75 | + $tokens = $phpcsFile->getTokens(); |
|
| 76 | + $modifier = $phpcsFile->findPrevious($find, ($stackPtr - 1)); |
|
| 77 | + if ($modifier === false |
|
| 78 | + || $tokens[$modifier]['code'] === \T_SEMICOLON |
|
| 79 | + || $tokens[$modifier]['code'] === \T_OPEN_CURLY_BRACKET |
|
| 80 | + ) { |
|
| 81 | + // Parse error. Ignore. |
|
| 82 | + return; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - $type = $phpcsFile->findNext(Tokens::$emptyTokens, ($modifier + 1), null, true); |
|
| 86 | - if ($tokens[$type]['code'] === \T_VARIABLE) { |
|
| 87 | - return; |
|
| 88 | - } |
|
| 85 | + $type = $phpcsFile->findNext(Tokens::$emptyTokens, ($modifier + 1), null, true); |
|
| 86 | + if ($tokens[$type]['code'] === \T_VARIABLE) { |
|
| 87 | + return; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - // Still here ? In that case, this will be a typed property. |
|
| 91 | - if ($this->supportsBelow('7.3') === true) { |
|
| 92 | - $phpcsFile->addError( |
|
| 93 | - 'Typed properties are not supported in PHP 7.3 or earlier', |
|
| 94 | - $type, |
|
| 95 | - 'Found' |
|
| 96 | - ); |
|
| 97 | - } |
|
| 90 | + // Still here ? In that case, this will be a typed property. |
|
| 91 | + if ($this->supportsBelow('7.3') === true) { |
|
| 92 | + $phpcsFile->addError( |
|
| 93 | + 'Typed properties are not supported in PHP 7.3 or earlier', |
|
| 94 | + $type, |
|
| 95 | + 'Found' |
|
| 96 | + ); |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - if ($this->supportsAbove('7.4') === true) { |
|
| 100 | - // Examine the type to verify it's valid. |
|
| 101 | - if ($tokens[$type]['type'] === 'T_NULLABLE' |
|
| 102 | - // Needed to support PHPCS < 3.5.0 which doesn't correct to the nullable token type yet. |
|
| 103 | - || $tokens[$type]['code'] === \T_INLINE_THEN |
|
| 104 | - ) { |
|
| 105 | - $type = $phpcsFile->findNext(Tokens::$emptyTokens, ($type + 1), null, true); |
|
| 106 | - } |
|
| 99 | + if ($this->supportsAbove('7.4') === true) { |
|
| 100 | + // Examine the type to verify it's valid. |
|
| 101 | + if ($tokens[$type]['type'] === 'T_NULLABLE' |
|
| 102 | + // Needed to support PHPCS < 3.5.0 which doesn't correct to the nullable token type yet. |
|
| 103 | + || $tokens[$type]['code'] === \T_INLINE_THEN |
|
| 104 | + ) { |
|
| 105 | + $type = $phpcsFile->findNext(Tokens::$emptyTokens, ($type + 1), null, true); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - $content = $tokens[$type]['content']; |
|
| 109 | - if ($content === 'void' || $content === 'callable') { |
|
| 110 | - $phpcsFile->addError( |
|
| 111 | - '%s is not supported as a type declaration for properties', |
|
| 112 | - $type, |
|
| 113 | - 'InvalidType', |
|
| 114 | - array($content) |
|
| 115 | - ); |
|
| 116 | - } |
|
| 117 | - } |
|
| 108 | + $content = $tokens[$type]['content']; |
|
| 109 | + if ($content === 'void' || $content === 'callable') { |
|
| 110 | + $phpcsFile->addError( |
|
| 111 | + '%s is not supported as a type declaration for properties', |
|
| 112 | + $type, |
|
| 113 | + 'InvalidType', |
|
| 114 | + array($content) |
|
| 115 | + ); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - $endOfStatement = $phpcsFile->findNext(\T_SEMICOLON, ($stackPtr + 1)); |
|
| 120 | - if ($endOfStatement !== false) { |
|
| 121 | - // Don't throw the same error multiple times for multi-property declarations. |
|
| 122 | - return ($endOfStatement + 1); |
|
| 123 | - } |
|
| 124 | - } |
|
| 119 | + $endOfStatement = $phpcsFile->findNext(\T_SEMICOLON, ($stackPtr + 1)); |
|
| 120 | + if ($endOfStatement !== false) { |
|
| 121 | + // Don't throw the same error multiple times for multi-property declarations. |
|
| 122 | + return ($endOfStatement + 1); |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | 125 | } |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | */ |
| 48 | 48 | public function register() |
| 49 | 49 | { |
| 50 | - return array(\T_VARIABLE); |
|
| 50 | + return array( \T_VARIABLE ); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -60,9 +60,9 @@ discard block |
||
| 60 | 60 | * @return int|void Integer stack pointer to skip forward or void to continue |
| 61 | 61 | * normal file processing. |
| 62 | 62 | */ |
| 63 | - public function process(File $phpcsFile, $stackPtr) |
|
| 63 | + public function process( File $phpcsFile, $stackPtr ) |
|
| 64 | 64 | { |
| 65 | - if ($this->isClassProperty($phpcsFile, $stackPtr) === false) { |
|
| 65 | + if ( $this->isClassProperty( $phpcsFile, $stackPtr ) === false ) { |
|
| 66 | 66 | return; |
| 67 | 67 | } |
| 68 | 68 | |
@@ -73,22 +73,22 @@ discard block |
||
| 73 | 73 | ); |
| 74 | 74 | |
| 75 | 75 | $tokens = $phpcsFile->getTokens(); |
| 76 | - $modifier = $phpcsFile->findPrevious($find, ($stackPtr - 1)); |
|
| 77 | - if ($modifier === false |
|
| 78 | - || $tokens[$modifier]['code'] === \T_SEMICOLON |
|
| 79 | - || $tokens[$modifier]['code'] === \T_OPEN_CURLY_BRACKET |
|
| 76 | + $modifier = $phpcsFile->findPrevious( $find, ( $stackPtr - 1 ) ); |
|
| 77 | + if ( $modifier === false |
|
| 78 | + || $tokens[ $modifier ][ 'code' ] === \T_SEMICOLON |
|
| 79 | + || $tokens[ $modifier ][ 'code' ] === \T_OPEN_CURLY_BRACKET |
|
| 80 | 80 | ) { |
| 81 | 81 | // Parse error. Ignore. |
| 82 | 82 | return; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - $type = $phpcsFile->findNext(Tokens::$emptyTokens, ($modifier + 1), null, true); |
|
| 86 | - if ($tokens[$type]['code'] === \T_VARIABLE) { |
|
| 85 | + $type = $phpcsFile->findNext( Tokens::$emptyTokens, ( $modifier + 1 ), null, true ); |
|
| 86 | + if ( $tokens[ $type ][ 'code' ] === \T_VARIABLE ) { |
|
| 87 | 87 | return; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | // Still here ? In that case, this will be a typed property. |
| 91 | - if ($this->supportsBelow('7.3') === true) { |
|
| 91 | + if ( $this->supportsBelow( '7.3' ) === true ) { |
|
| 92 | 92 | $phpcsFile->addError( |
| 93 | 93 | 'Typed properties are not supported in PHP 7.3 or earlier', |
| 94 | 94 | $type, |
@@ -96,30 +96,30 @@ discard block |
||
| 96 | 96 | ); |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - if ($this->supportsAbove('7.4') === true) { |
|
| 99 | + if ( $this->supportsAbove( '7.4' ) === true ) { |
|
| 100 | 100 | // Examine the type to verify it's valid. |
| 101 | - if ($tokens[$type]['type'] === 'T_NULLABLE' |
|
| 101 | + if ( $tokens[ $type ][ 'type' ] === 'T_NULLABLE' |
|
| 102 | 102 | // Needed to support PHPCS < 3.5.0 which doesn't correct to the nullable token type yet. |
| 103 | - || $tokens[$type]['code'] === \T_INLINE_THEN |
|
| 103 | + || $tokens[ $type ][ 'code' ] === \T_INLINE_THEN |
|
| 104 | 104 | ) { |
| 105 | - $type = $phpcsFile->findNext(Tokens::$emptyTokens, ($type + 1), null, true); |
|
| 105 | + $type = $phpcsFile->findNext( Tokens::$emptyTokens, ( $type + 1 ), null, true ); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - $content = $tokens[$type]['content']; |
|
| 109 | - if ($content === 'void' || $content === 'callable') { |
|
| 108 | + $content = $tokens[ $type ][ 'content' ]; |
|
| 109 | + if ( $content === 'void' || $content === 'callable' ) { |
|
| 110 | 110 | $phpcsFile->addError( |
| 111 | 111 | '%s is not supported as a type declaration for properties', |
| 112 | 112 | $type, |
| 113 | 113 | 'InvalidType', |
| 114 | - array($content) |
|
| 114 | + array( $content ) |
|
| 115 | 115 | ); |
| 116 | 116 | } |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - $endOfStatement = $phpcsFile->findNext(\T_SEMICOLON, ($stackPtr + 1)); |
|
| 120 | - if ($endOfStatement !== false) { |
|
| 119 | + $endOfStatement = $phpcsFile->findNext( \T_SEMICOLON, ( $stackPtr + 1 ) ); |
|
| 120 | + if ( $endOfStatement !== false ) { |
|
| 121 | 121 | // Don't throw the same error multiple times for multi-property declarations. |
| 122 | - return ($endOfStatement + 1); |
|
| 122 | + return ( $endOfStatement + 1 ); |
|
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | } |
@@ -23,8 +23,7 @@ discard block |
||
| 23 | 23 | * |
| 24 | 24 | * @since 9.2.0 |
| 25 | 25 | */ |
| 26 | -class NewTypedPropertiesSniff extends Sniff |
|
| 27 | -{ |
|
| 26 | +class NewTypedPropertiesSniff extends Sniff { |
|
| 28 | 27 | |
| 29 | 28 | /** |
| 30 | 29 | * Valid property modifier keywords. |
@@ -45,8 +44,7 @@ discard block |
||
| 45 | 44 | * |
| 46 | 45 | * @return array |
| 47 | 46 | */ |
| 48 | - public function register() |
|
| 49 | - { |
|
| 47 | + public function register() { |
|
| 50 | 48 | return array(\T_VARIABLE); |
| 51 | 49 | } |
| 52 | 50 | |
@@ -60,8 +58,7 @@ discard block |
||
| 60 | 58 | * @return int|void Integer stack pointer to skip forward or void to continue |
| 61 | 59 | * normal file processing. |
| 62 | 60 | */ |
| 63 | - public function process(File $phpcsFile, $stackPtr) |
|
| 64 | - { |
|
| 61 | + public function process(File $phpcsFile, $stackPtr) { |
|
| 65 | 62 | if ($this->isClassProperty($phpcsFile, $stackPtr) === false) { |
| 66 | 63 | return; |
| 67 | 64 | } |
@@ -65,7 +65,7 @@ |
||
| 65 | 65 | /** |
| 66 | 66 | * Returns an array of tokens this test wants to listen for. |
| 67 | 67 | * |
| 68 | - * @return array |
|
| 68 | + * @return integer[] |
|
| 69 | 69 | */ |
| 70 | 70 | public function register() |
| 71 | 71 | { |
@@ -26,54 +26,54 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | class NewLateStaticBindingSniff extends Sniff |
| 28 | 28 | { |
| 29 | - /** |
|
| 30 | - * Returns an array of tokens this test wants to listen for. |
|
| 31 | - * |
|
| 32 | - * @return array |
|
| 33 | - */ |
|
| 34 | - public function register() |
|
| 35 | - { |
|
| 36 | - return array(\T_STATIC); |
|
| 37 | - } |
|
| 29 | + /** |
|
| 30 | + * Returns an array of tokens this test wants to listen for. |
|
| 31 | + * |
|
| 32 | + * @return array |
|
| 33 | + */ |
|
| 34 | + public function register() |
|
| 35 | + { |
|
| 36 | + return array(\T_STATIC); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Processes this test, when one of its tokens is encountered. |
|
| 42 | - * |
|
| 43 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 44 | - * @param int $stackPtr The position of the current token in the |
|
| 45 | - * stack passed in $tokens. |
|
| 46 | - * |
|
| 47 | - * @return void |
|
| 48 | - */ |
|
| 49 | - public function process(File $phpcsFile, $stackPtr) |
|
| 50 | - { |
|
| 51 | - $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true); |
|
| 52 | - if ($nextNonEmpty === false) { |
|
| 53 | - return; |
|
| 54 | - } |
|
| 40 | + /** |
|
| 41 | + * Processes this test, when one of its tokens is encountered. |
|
| 42 | + * |
|
| 43 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 44 | + * @param int $stackPtr The position of the current token in the |
|
| 45 | + * stack passed in $tokens. |
|
| 46 | + * |
|
| 47 | + * @return void |
|
| 48 | + */ |
|
| 49 | + public function process(File $phpcsFile, $stackPtr) |
|
| 50 | + { |
|
| 51 | + $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true); |
|
| 52 | + if ($nextNonEmpty === false) { |
|
| 53 | + return; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - $tokens = $phpcsFile->getTokens(); |
|
| 57 | - if ($tokens[$nextNonEmpty]['code'] !== \T_DOUBLE_COLON) { |
|
| 58 | - return; |
|
| 59 | - } |
|
| 56 | + $tokens = $phpcsFile->getTokens(); |
|
| 57 | + if ($tokens[$nextNonEmpty]['code'] !== \T_DOUBLE_COLON) { |
|
| 58 | + return; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - $inClass = $this->inClassScope($phpcsFile, $stackPtr, false); |
|
| 61 | + $inClass = $this->inClassScope($phpcsFile, $stackPtr, false); |
|
| 62 | 62 | |
| 63 | - if ($inClass === true && $this->supportsBelow('5.2') === true) { |
|
| 64 | - $phpcsFile->addError( |
|
| 65 | - 'Late static binding is not supported in PHP 5.2 or earlier.', |
|
| 66 | - $stackPtr, |
|
| 67 | - 'Found' |
|
| 68 | - ); |
|
| 69 | - } |
|
| 63 | + if ($inClass === true && $this->supportsBelow('5.2') === true) { |
|
| 64 | + $phpcsFile->addError( |
|
| 65 | + 'Late static binding is not supported in PHP 5.2 or earlier.', |
|
| 66 | + $stackPtr, |
|
| 67 | + 'Found' |
|
| 68 | + ); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - if ($inClass === false) { |
|
| 72 | - $phpcsFile->addError( |
|
| 73 | - 'Late static binding is not supported outside of class scope.', |
|
| 74 | - $stackPtr, |
|
| 75 | - 'OutsideClassScope' |
|
| 76 | - ); |
|
| 77 | - } |
|
| 78 | - } |
|
| 71 | + if ($inClass === false) { |
|
| 72 | + $phpcsFile->addError( |
|
| 73 | + 'Late static binding is not supported outside of class scope.', |
|
| 74 | + $stackPtr, |
|
| 75 | + 'OutsideClassScope' |
|
| 76 | + ); |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | 79 | } |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | public function register() |
| 35 | 35 | { |
| 36 | - return array(\T_STATIC); |
|
| 36 | + return array( \T_STATIC ); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | |
@@ -46,21 +46,21 @@ discard block |
||
| 46 | 46 | * |
| 47 | 47 | * @return void |
| 48 | 48 | */ |
| 49 | - public function process(File $phpcsFile, $stackPtr) |
|
| 49 | + public function process( File $phpcsFile, $stackPtr ) |
|
| 50 | 50 | { |
| 51 | - $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true); |
|
| 52 | - if ($nextNonEmpty === false) { |
|
| 51 | + $nextNonEmpty = $phpcsFile->findNext( Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true ); |
|
| 52 | + if ( $nextNonEmpty === false ) { |
|
| 53 | 53 | return; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | $tokens = $phpcsFile->getTokens(); |
| 57 | - if ($tokens[$nextNonEmpty]['code'] !== \T_DOUBLE_COLON) { |
|
| 57 | + if ( $tokens[ $nextNonEmpty ][ 'code' ] !== \T_DOUBLE_COLON ) { |
|
| 58 | 58 | return; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - $inClass = $this->inClassScope($phpcsFile, $stackPtr, false); |
|
| 61 | + $inClass = $this->inClassScope( $phpcsFile, $stackPtr, false ); |
|
| 62 | 62 | |
| 63 | - if ($inClass === true && $this->supportsBelow('5.2') === true) { |
|
| 63 | + if ( $inClass === true && $this->supportsBelow( '5.2' ) === true ) { |
|
| 64 | 64 | $phpcsFile->addError( |
| 65 | 65 | 'Late static binding is not supported in PHP 5.2 or earlier.', |
| 66 | 66 | $stackPtr, |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | ); |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - if ($inClass === false) { |
|
| 71 | + if ( $inClass === false ) { |
|
| 72 | 72 | $phpcsFile->addError( |
| 73 | 73 | 'Late static binding is not supported outside of class scope.', |
| 74 | 74 | $stackPtr, |
@@ -24,15 +24,13 @@ discard block |
||
| 24 | 24 | * @package PHPCompatibility |
| 25 | 25 | * @author Juliette Reinders Folmer <[email protected]> |
| 26 | 26 | */ |
| 27 | -class NewLateStaticBindingSniff extends Sniff |
|
| 28 | -{ |
|
| 27 | +class NewLateStaticBindingSniff extends Sniff { |
|
| 29 | 28 | /** |
| 30 | 29 | * Returns an array of tokens this test wants to listen for. |
| 31 | 30 | * |
| 32 | 31 | * @return array |
| 33 | 32 | */ |
| 34 | - public function register() |
|
| 35 | - { |
|
| 33 | + public function register() { |
|
| 36 | 34 | return array(\T_STATIC); |
| 37 | 35 | } |
| 38 | 36 | |
@@ -46,8 +44,7 @@ discard block |
||
| 46 | 44 | * |
| 47 | 45 | * @return void |
| 48 | 46 | */ |
| 49 | - public function process(File $phpcsFile, $stackPtr) |
|
| 50 | - { |
|
| 47 | + public function process(File $phpcsFile, $stackPtr) { |
|
| 51 | 48 | $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true); |
| 52 | 49 | if ($nextNonEmpty === false) { |
| 53 | 50 | return; |
@@ -65,7 +65,7 @@ |
||
| 65 | 65 | /** |
| 66 | 66 | * Returns an array of tokens this test wants to listen for. |
| 67 | 67 | * |
| 68 | - * @return array |
|
| 68 | + * @return integer[] |
|
| 69 | 69 | */ |
| 70 | 70 | public function register() |
| 71 | 71 | { |
@@ -29,83 +29,83 @@ |
||
| 29 | 29 | class ForbiddenEmptyListAssignmentSniff extends Sniff |
| 30 | 30 | { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * List of tokens to disregard when determining whether the list() is empty. |
|
| 34 | - * |
|
| 35 | - * @var array |
|
| 36 | - */ |
|
| 37 | - protected $ignoreTokens = array(); |
|
| 32 | + /** |
|
| 33 | + * List of tokens to disregard when determining whether the list() is empty. |
|
| 34 | + * |
|
| 35 | + * @var array |
|
| 36 | + */ |
|
| 37 | + protected $ignoreTokens = array(); |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Returns an array of tokens this test wants to listen for. |
|
| 41 | - * |
|
| 42 | - * @return array |
|
| 43 | - */ |
|
| 44 | - public function register() |
|
| 45 | - { |
|
| 46 | - // Set up a list of tokens to disregard when determining whether the list() is empty. |
|
| 47 | - // Only needs to be set up once. |
|
| 48 | - $this->ignoreTokens = Tokens::$emptyTokens; |
|
| 49 | - $this->ignoreTokens[\T_COMMA] = \T_COMMA; |
|
| 50 | - $this->ignoreTokens[\T_OPEN_PARENTHESIS] = \T_OPEN_PARENTHESIS; |
|
| 51 | - $this->ignoreTokens[\T_CLOSE_PARENTHESIS] = \T_CLOSE_PARENTHESIS; |
|
| 39 | + /** |
|
| 40 | + * Returns an array of tokens this test wants to listen for. |
|
| 41 | + * |
|
| 42 | + * @return array |
|
| 43 | + */ |
|
| 44 | + public function register() |
|
| 45 | + { |
|
| 46 | + // Set up a list of tokens to disregard when determining whether the list() is empty. |
|
| 47 | + // Only needs to be set up once. |
|
| 48 | + $this->ignoreTokens = Tokens::$emptyTokens; |
|
| 49 | + $this->ignoreTokens[\T_COMMA] = \T_COMMA; |
|
| 50 | + $this->ignoreTokens[\T_OPEN_PARENTHESIS] = \T_OPEN_PARENTHESIS; |
|
| 51 | + $this->ignoreTokens[\T_CLOSE_PARENTHESIS] = \T_CLOSE_PARENTHESIS; |
|
| 52 | 52 | |
| 53 | - return array( |
|
| 54 | - \T_LIST, |
|
| 55 | - \T_OPEN_SHORT_ARRAY, |
|
| 56 | - ); |
|
| 57 | - } |
|
| 53 | + return array( |
|
| 54 | + \T_LIST, |
|
| 55 | + \T_OPEN_SHORT_ARRAY, |
|
| 56 | + ); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Processes this test, when one of its tokens is encountered. |
|
| 61 | - * |
|
| 62 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 63 | - * @param int $stackPtr The position of the current token in the |
|
| 64 | - * stack passed in $tokens. |
|
| 65 | - * |
|
| 66 | - * @return void |
|
| 67 | - */ |
|
| 68 | - public function process(File $phpcsFile, $stackPtr) |
|
| 69 | - { |
|
| 70 | - if ($this->supportsAbove('7.0') === false) { |
|
| 71 | - return; |
|
| 72 | - } |
|
| 59 | + /** |
|
| 60 | + * Processes this test, when one of its tokens is encountered. |
|
| 61 | + * |
|
| 62 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 63 | + * @param int $stackPtr The position of the current token in the |
|
| 64 | + * stack passed in $tokens. |
|
| 65 | + * |
|
| 66 | + * @return void |
|
| 67 | + */ |
|
| 68 | + public function process(File $phpcsFile, $stackPtr) |
|
| 69 | + { |
|
| 70 | + if ($this->supportsAbove('7.0') === false) { |
|
| 71 | + return; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - $tokens = $phpcsFile->getTokens(); |
|
| 74 | + $tokens = $phpcsFile->getTokens(); |
|
| 75 | 75 | |
| 76 | - if ($tokens[$stackPtr]['code'] === \T_OPEN_SHORT_ARRAY) { |
|
| 77 | - if ($this->isShortList($phpcsFile, $stackPtr) === false) { |
|
| 78 | - return; |
|
| 79 | - } |
|
| 76 | + if ($tokens[$stackPtr]['code'] === \T_OPEN_SHORT_ARRAY) { |
|
| 77 | + if ($this->isShortList($phpcsFile, $stackPtr) === false) { |
|
| 78 | + return; |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - $open = $stackPtr; |
|
| 82 | - $close = $tokens[$stackPtr]['bracket_closer']; |
|
| 83 | - } else { |
|
| 84 | - // T_LIST. |
|
| 85 | - $open = $phpcsFile->findNext(\T_OPEN_PARENTHESIS, $stackPtr, null, false, null, true); |
|
| 86 | - if ($open === false || isset($tokens[$open]['parenthesis_closer']) === false) { |
|
| 87 | - return; |
|
| 88 | - } |
|
| 81 | + $open = $stackPtr; |
|
| 82 | + $close = $tokens[$stackPtr]['bracket_closer']; |
|
| 83 | + } else { |
|
| 84 | + // T_LIST. |
|
| 85 | + $open = $phpcsFile->findNext(\T_OPEN_PARENTHESIS, $stackPtr, null, false, null, true); |
|
| 86 | + if ($open === false || isset($tokens[$open]['parenthesis_closer']) === false) { |
|
| 87 | + return; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - $close = $tokens[$open]['parenthesis_closer']; |
|
| 91 | - } |
|
| 90 | + $close = $tokens[$open]['parenthesis_closer']; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - $error = true; |
|
| 94 | - if (($close - $open) > 1) { |
|
| 95 | - for ($cnt = $open + 1; $cnt < $close; $cnt++) { |
|
| 96 | - if (isset($this->ignoreTokens[$tokens[$cnt]['code']]) === false) { |
|
| 97 | - $error = false; |
|
| 98 | - break; |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - } |
|
| 93 | + $error = true; |
|
| 94 | + if (($close - $open) > 1) { |
|
| 95 | + for ($cnt = $open + 1; $cnt < $close; $cnt++) { |
|
| 96 | + if (isset($this->ignoreTokens[$tokens[$cnt]['code']]) === false) { |
|
| 97 | + $error = false; |
|
| 98 | + break; |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - if ($error === true) { |
|
| 104 | - $phpcsFile->addError( |
|
| 105 | - 'Empty list() assignments are not allowed since PHP 7.0', |
|
| 106 | - $stackPtr, |
|
| 107 | - 'Found' |
|
| 108 | - ); |
|
| 109 | - } |
|
| 110 | - } |
|
| 103 | + if ($error === true) { |
|
| 104 | + $phpcsFile->addError( |
|
| 105 | + 'Empty list() assignments are not allowed since PHP 7.0', |
|
| 106 | + $stackPtr, |
|
| 107 | + 'Found' |
|
| 108 | + ); |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | 111 | } |
@@ -46,9 +46,9 @@ discard block |
||
| 46 | 46 | // Set up a list of tokens to disregard when determining whether the list() is empty. |
| 47 | 47 | // Only needs to be set up once. |
| 48 | 48 | $this->ignoreTokens = Tokens::$emptyTokens; |
| 49 | - $this->ignoreTokens[\T_COMMA] = \T_COMMA; |
|
| 50 | - $this->ignoreTokens[\T_OPEN_PARENTHESIS] = \T_OPEN_PARENTHESIS; |
|
| 51 | - $this->ignoreTokens[\T_CLOSE_PARENTHESIS] = \T_CLOSE_PARENTHESIS; |
|
| 49 | + $this->ignoreTokens[ \T_COMMA ] = \T_COMMA; |
|
| 50 | + $this->ignoreTokens[ \T_OPEN_PARENTHESIS ] = \T_OPEN_PARENTHESIS; |
|
| 51 | + $this->ignoreTokens[ \T_CLOSE_PARENTHESIS ] = \T_CLOSE_PARENTHESIS; |
|
| 52 | 52 | |
| 53 | 53 | return array( |
| 54 | 54 | \T_LIST, |
@@ -65,42 +65,42 @@ discard block |
||
| 65 | 65 | * |
| 66 | 66 | * @return void |
| 67 | 67 | */ |
| 68 | - public function process(File $phpcsFile, $stackPtr) |
|
| 68 | + public function process( File $phpcsFile, $stackPtr ) |
|
| 69 | 69 | { |
| 70 | - if ($this->supportsAbove('7.0') === false) { |
|
| 70 | + if ( $this->supportsAbove( '7.0' ) === false ) { |
|
| 71 | 71 | return; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | $tokens = $phpcsFile->getTokens(); |
| 75 | 75 | |
| 76 | - if ($tokens[$stackPtr]['code'] === \T_OPEN_SHORT_ARRAY) { |
|
| 77 | - if ($this->isShortList($phpcsFile, $stackPtr) === false) { |
|
| 76 | + if ( $tokens[ $stackPtr ][ 'code' ] === \T_OPEN_SHORT_ARRAY ) { |
|
| 77 | + if ( $this->isShortList( $phpcsFile, $stackPtr ) === false ) { |
|
| 78 | 78 | return; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | $open = $stackPtr; |
| 82 | - $close = $tokens[$stackPtr]['bracket_closer']; |
|
| 82 | + $close = $tokens[ $stackPtr ][ 'bracket_closer' ]; |
|
| 83 | 83 | } else { |
| 84 | 84 | // T_LIST. |
| 85 | - $open = $phpcsFile->findNext(\T_OPEN_PARENTHESIS, $stackPtr, null, false, null, true); |
|
| 86 | - if ($open === false || isset($tokens[$open]['parenthesis_closer']) === false) { |
|
| 85 | + $open = $phpcsFile->findNext( \T_OPEN_PARENTHESIS, $stackPtr, null, false, null, true ); |
|
| 86 | + if ( $open === false || isset( $tokens[ $open ][ 'parenthesis_closer' ] ) === false ) { |
|
| 87 | 87 | return; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - $close = $tokens[$open]['parenthesis_closer']; |
|
| 90 | + $close = $tokens[ $open ][ 'parenthesis_closer' ]; |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | $error = true; |
| 94 | - if (($close - $open) > 1) { |
|
| 95 | - for ($cnt = $open + 1; $cnt < $close; $cnt++) { |
|
| 96 | - if (isset($this->ignoreTokens[$tokens[$cnt]['code']]) === false) { |
|
| 94 | + if ( ( $close - $open ) > 1 ) { |
|
| 95 | + for ( $cnt = $open + 1; $cnt < $close; $cnt++ ) { |
|
| 96 | + if ( isset( $this->ignoreTokens[ $tokens[ $cnt ][ 'code' ] ] ) === false ) { |
|
| 97 | 97 | $error = false; |
| 98 | 98 | break; |
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - if ($error === true) { |
|
| 103 | + if ( $error === true ) { |
|
| 104 | 104 | $phpcsFile->addError( |
| 105 | 105 | 'Empty list() assignments are not allowed since PHP 7.0', |
| 106 | 106 | $stackPtr, |
@@ -26,8 +26,7 @@ discard block |
||
| 26 | 26 | * @package PHPCompatibility |
| 27 | 27 | * @author Wim Godden <[email protected]> |
| 28 | 28 | */ |
| 29 | -class ForbiddenEmptyListAssignmentSniff extends Sniff |
|
| 30 | -{ |
|
| 29 | +class ForbiddenEmptyListAssignmentSniff extends Sniff { |
|
| 31 | 30 | |
| 32 | 31 | /** |
| 33 | 32 | * List of tokens to disregard when determining whether the list() is empty. |
@@ -41,8 +40,7 @@ discard block |
||
| 41 | 40 | * |
| 42 | 41 | * @return array |
| 43 | 42 | */ |
| 44 | - public function register() |
|
| 45 | - { |
|
| 43 | + public function register() { |
|
| 46 | 44 | // Set up a list of tokens to disregard when determining whether the list() is empty. |
| 47 | 45 | // Only needs to be set up once. |
| 48 | 46 | $this->ignoreTokens = Tokens::$emptyTokens; |
@@ -65,8 +63,7 @@ discard block |
||
| 65 | 63 | * |
| 66 | 64 | * @return void |
| 67 | 65 | */ |
| 68 | - public function process(File $phpcsFile, $stackPtr) |
|
| 69 | - { |
|
| 66 | + public function process(File $phpcsFile, $stackPtr) { |
|
| 70 | 67 | if ($this->supportsAbove('7.0') === false) { |
| 71 | 68 | return; |
| 72 | 69 | } |
@@ -28,184 +28,184 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | class NewKeyedListSniff extends Sniff |
| 30 | 30 | { |
| 31 | - /** |
|
| 32 | - * Tokens which represent the start of a list construct. |
|
| 33 | - * |
|
| 34 | - * @var array |
|
| 35 | - */ |
|
| 36 | - protected $sniffTargets = array( |
|
| 37 | - \T_LIST => \T_LIST, |
|
| 38 | - \T_OPEN_SHORT_ARRAY => \T_OPEN_SHORT_ARRAY, |
|
| 39 | - ); |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * The token(s) within the list construct which is being targeted. |
|
| 43 | - * |
|
| 44 | - * @var array |
|
| 45 | - */ |
|
| 46 | - protected $targetsInList = array( |
|
| 47 | - \T_DOUBLE_ARROW => \T_DOUBLE_ARROW, |
|
| 48 | - ); |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * All tokens needed to walk through the list construct and |
|
| 52 | - * determine whether the target token is contained within. |
|
| 53 | - * |
|
| 54 | - * Set by the setUpAllTargets() method which is called from within register(). |
|
| 55 | - * |
|
| 56 | - * @var array |
|
| 57 | - */ |
|
| 58 | - protected $allTargets; |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Returns an array of tokens this test wants to listen for. |
|
| 63 | - * |
|
| 64 | - * @return array |
|
| 65 | - */ |
|
| 66 | - public function register() |
|
| 67 | - { |
|
| 68 | - $this->setUpAllTargets(); |
|
| 69 | - |
|
| 70 | - return $this->sniffTargets; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Prepare the $allTargets array only once. |
|
| 75 | - * |
|
| 76 | - * @return array |
|
| 77 | - */ |
|
| 78 | - public function setUpAllTargets() |
|
| 79 | - { |
|
| 80 | - $this->allTargets = $this->sniffTargets + $this->targetsInList; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Do a version check to determine if this sniff needs to run at all. |
|
| 85 | - * |
|
| 86 | - * @return bool |
|
| 87 | - */ |
|
| 88 | - protected function bowOutEarly() |
|
| 89 | - { |
|
| 90 | - return ($this->supportsBelow('7.0') === false); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Processes this test, when one of its tokens is encountered. |
|
| 95 | - * |
|
| 96 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 97 | - * @param int $stackPtr The position of the current token in the |
|
| 98 | - * stack passed in $tokens. |
|
| 99 | - * |
|
| 100 | - * @return void |
|
| 101 | - */ |
|
| 102 | - public function process(File $phpcsFile, $stackPtr) |
|
| 103 | - { |
|
| 104 | - if ($this->bowOutEarly() === true) { |
|
| 105 | - return; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - $tokens = $phpcsFile->getTokens(); |
|
| 109 | - |
|
| 110 | - if ($tokens[$stackPtr]['code'] === \T_OPEN_SHORT_ARRAY |
|
| 111 | - && $this->isShortList($phpcsFile, $stackPtr) === false |
|
| 112 | - ) { |
|
| 113 | - // Short array, not short list. |
|
| 114 | - return; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - if ($tokens[$stackPtr]['code'] === \T_LIST) { |
|
| 118 | - $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); |
|
| 119 | - if ($nextNonEmpty === false |
|
| 120 | - || $tokens[$nextNonEmpty]['code'] !== \T_OPEN_PARENTHESIS |
|
| 121 | - || isset($tokens[$nextNonEmpty]['parenthesis_closer']) === false |
|
| 122 | - ) { |
|
| 123 | - // Parse error or live coding. |
|
| 124 | - return; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - $opener = $nextNonEmpty; |
|
| 128 | - $closer = $tokens[$nextNonEmpty]['parenthesis_closer']; |
|
| 129 | - } else { |
|
| 130 | - // Short list syntax. |
|
| 131 | - $opener = $stackPtr; |
|
| 132 | - |
|
| 133 | - if (isset($tokens[$stackPtr]['bracket_closer'])) { |
|
| 134 | - $closer = $tokens[$stackPtr]['bracket_closer']; |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - if (isset($opener, $closer) === false) { |
|
| 139 | - return; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - $this->examineList($phpcsFile, $opener, $closer); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * Examine the contents of a list construct to determine whether an error needs to be thrown. |
|
| 148 | - * |
|
| 149 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 150 | - * @param int $opener The position of the list open token. |
|
| 151 | - * @param int $closer The position of the list close token. |
|
| 152 | - * |
|
| 153 | - * @return void |
|
| 154 | - */ |
|
| 155 | - protected function examineList(File $phpcsFile, $opener, $closer) |
|
| 156 | - { |
|
| 157 | - $start = $opener; |
|
| 158 | - while (($start = $this->hasTargetInList($phpcsFile, $start, $closer)) !== false) { |
|
| 159 | - $phpcsFile->addError( |
|
| 160 | - 'Specifying keys in list constructs is not supported in PHP 7.0 or earlier.', |
|
| 161 | - $start, |
|
| 162 | - 'Found' |
|
| 163 | - ); |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Check whether a certain target token exists within a list construct. |
|
| 170 | - * |
|
| 171 | - * Skips past nested list constructs, so these can be examined based on their own token. |
|
| 172 | - * |
|
| 173 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 174 | - * @param int $start The position of the list open token or a token |
|
| 175 | - * within the list to start (resume) the examination from. |
|
| 176 | - * @param int $closer The position of the list close token. |
|
| 177 | - * |
|
| 178 | - * @return int|bool Stack pointer to the target token if encountered. False otherwise. |
|
| 179 | - */ |
|
| 180 | - protected function hasTargetInList(File $phpcsFile, $start, $closer) |
|
| 181 | - { |
|
| 182 | - $tokens = $phpcsFile->getTokens(); |
|
| 183 | - |
|
| 184 | - for ($i = ($start + 1); $i < $closer; $i++) { |
|
| 185 | - if (isset($this->allTargets[$tokens[$i]['code']]) === false) { |
|
| 186 | - continue; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - if (isset($this->targetsInList[$tokens[$i]['code']]) === true) { |
|
| 190 | - return $i; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - // Skip past nested list constructs. |
|
| 194 | - if ($tokens[$i]['code'] === \T_LIST) { |
|
| 195 | - $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($i + 1), null, true); |
|
| 196 | - if ($nextNonEmpty !== false |
|
| 197 | - && $tokens[$nextNonEmpty]['code'] === \T_OPEN_PARENTHESIS |
|
| 198 | - && isset($tokens[$nextNonEmpty]['parenthesis_closer']) === true |
|
| 199 | - ) { |
|
| 200 | - $i = $tokens[$nextNonEmpty]['parenthesis_closer']; |
|
| 201 | - } |
|
| 202 | - } elseif ($tokens[$i]['code'] === \T_OPEN_SHORT_ARRAY |
|
| 203 | - && isset($tokens[$i]['bracket_closer']) |
|
| 204 | - ) { |
|
| 205 | - $i = $tokens[$i]['bracket_closer']; |
|
| 206 | - } |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - return false; |
|
| 210 | - } |
|
| 31 | + /** |
|
| 32 | + * Tokens which represent the start of a list construct. |
|
| 33 | + * |
|
| 34 | + * @var array |
|
| 35 | + */ |
|
| 36 | + protected $sniffTargets = array( |
|
| 37 | + \T_LIST => \T_LIST, |
|
| 38 | + \T_OPEN_SHORT_ARRAY => \T_OPEN_SHORT_ARRAY, |
|
| 39 | + ); |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * The token(s) within the list construct which is being targeted. |
|
| 43 | + * |
|
| 44 | + * @var array |
|
| 45 | + */ |
|
| 46 | + protected $targetsInList = array( |
|
| 47 | + \T_DOUBLE_ARROW => \T_DOUBLE_ARROW, |
|
| 48 | + ); |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * All tokens needed to walk through the list construct and |
|
| 52 | + * determine whether the target token is contained within. |
|
| 53 | + * |
|
| 54 | + * Set by the setUpAllTargets() method which is called from within register(). |
|
| 55 | + * |
|
| 56 | + * @var array |
|
| 57 | + */ |
|
| 58 | + protected $allTargets; |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Returns an array of tokens this test wants to listen for. |
|
| 63 | + * |
|
| 64 | + * @return array |
|
| 65 | + */ |
|
| 66 | + public function register() |
|
| 67 | + { |
|
| 68 | + $this->setUpAllTargets(); |
|
| 69 | + |
|
| 70 | + return $this->sniffTargets; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Prepare the $allTargets array only once. |
|
| 75 | + * |
|
| 76 | + * @return array |
|
| 77 | + */ |
|
| 78 | + public function setUpAllTargets() |
|
| 79 | + { |
|
| 80 | + $this->allTargets = $this->sniffTargets + $this->targetsInList; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Do a version check to determine if this sniff needs to run at all. |
|
| 85 | + * |
|
| 86 | + * @return bool |
|
| 87 | + */ |
|
| 88 | + protected function bowOutEarly() |
|
| 89 | + { |
|
| 90 | + return ($this->supportsBelow('7.0') === false); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Processes this test, when one of its tokens is encountered. |
|
| 95 | + * |
|
| 96 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 97 | + * @param int $stackPtr The position of the current token in the |
|
| 98 | + * stack passed in $tokens. |
|
| 99 | + * |
|
| 100 | + * @return void |
|
| 101 | + */ |
|
| 102 | + public function process(File $phpcsFile, $stackPtr) |
|
| 103 | + { |
|
| 104 | + if ($this->bowOutEarly() === true) { |
|
| 105 | + return; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + $tokens = $phpcsFile->getTokens(); |
|
| 109 | + |
|
| 110 | + if ($tokens[$stackPtr]['code'] === \T_OPEN_SHORT_ARRAY |
|
| 111 | + && $this->isShortList($phpcsFile, $stackPtr) === false |
|
| 112 | + ) { |
|
| 113 | + // Short array, not short list. |
|
| 114 | + return; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + if ($tokens[$stackPtr]['code'] === \T_LIST) { |
|
| 118 | + $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); |
|
| 119 | + if ($nextNonEmpty === false |
|
| 120 | + || $tokens[$nextNonEmpty]['code'] !== \T_OPEN_PARENTHESIS |
|
| 121 | + || isset($tokens[$nextNonEmpty]['parenthesis_closer']) === false |
|
| 122 | + ) { |
|
| 123 | + // Parse error or live coding. |
|
| 124 | + return; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + $opener = $nextNonEmpty; |
|
| 128 | + $closer = $tokens[$nextNonEmpty]['parenthesis_closer']; |
|
| 129 | + } else { |
|
| 130 | + // Short list syntax. |
|
| 131 | + $opener = $stackPtr; |
|
| 132 | + |
|
| 133 | + if (isset($tokens[$stackPtr]['bracket_closer'])) { |
|
| 134 | + $closer = $tokens[$stackPtr]['bracket_closer']; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + if (isset($opener, $closer) === false) { |
|
| 139 | + return; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + $this->examineList($phpcsFile, $opener, $closer); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * Examine the contents of a list construct to determine whether an error needs to be thrown. |
|
| 148 | + * |
|
| 149 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 150 | + * @param int $opener The position of the list open token. |
|
| 151 | + * @param int $closer The position of the list close token. |
|
| 152 | + * |
|
| 153 | + * @return void |
|
| 154 | + */ |
|
| 155 | + protected function examineList(File $phpcsFile, $opener, $closer) |
|
| 156 | + { |
|
| 157 | + $start = $opener; |
|
| 158 | + while (($start = $this->hasTargetInList($phpcsFile, $start, $closer)) !== false) { |
|
| 159 | + $phpcsFile->addError( |
|
| 160 | + 'Specifying keys in list constructs is not supported in PHP 7.0 or earlier.', |
|
| 161 | + $start, |
|
| 162 | + 'Found' |
|
| 163 | + ); |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Check whether a certain target token exists within a list construct. |
|
| 170 | + * |
|
| 171 | + * Skips past nested list constructs, so these can be examined based on their own token. |
|
| 172 | + * |
|
| 173 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 174 | + * @param int $start The position of the list open token or a token |
|
| 175 | + * within the list to start (resume) the examination from. |
|
| 176 | + * @param int $closer The position of the list close token. |
|
| 177 | + * |
|
| 178 | + * @return int|bool Stack pointer to the target token if encountered. False otherwise. |
|
| 179 | + */ |
|
| 180 | + protected function hasTargetInList(File $phpcsFile, $start, $closer) |
|
| 181 | + { |
|
| 182 | + $tokens = $phpcsFile->getTokens(); |
|
| 183 | + |
|
| 184 | + for ($i = ($start + 1); $i < $closer; $i++) { |
|
| 185 | + if (isset($this->allTargets[$tokens[$i]['code']]) === false) { |
|
| 186 | + continue; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + if (isset($this->targetsInList[$tokens[$i]['code']]) === true) { |
|
| 190 | + return $i; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + // Skip past nested list constructs. |
|
| 194 | + if ($tokens[$i]['code'] === \T_LIST) { |
|
| 195 | + $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($i + 1), null, true); |
|
| 196 | + if ($nextNonEmpty !== false |
|
| 197 | + && $tokens[$nextNonEmpty]['code'] === \T_OPEN_PARENTHESIS |
|
| 198 | + && isset($tokens[$nextNonEmpty]['parenthesis_closer']) === true |
|
| 199 | + ) { |
|
| 200 | + $i = $tokens[$nextNonEmpty]['parenthesis_closer']; |
|
| 201 | + } |
|
| 202 | + } elseif ($tokens[$i]['code'] === \T_OPEN_SHORT_ARRAY |
|
| 203 | + && isset($tokens[$i]['bracket_closer']) |
|
| 204 | + ) { |
|
| 205 | + $i = $tokens[$i]['bracket_closer']; |
|
| 206 | + } |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + return false; |
|
| 210 | + } |
|
| 211 | 211 | } |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * |
| 34 | 34 | * @var array |
| 35 | 35 | */ |
| 36 | - protected $sniffTargets = array( |
|
| 36 | + protected $sniffTargets = array( |
|
| 37 | 37 | \T_LIST => \T_LIST, |
| 38 | 38 | \T_OPEN_SHORT_ARRAY => \T_OPEN_SHORT_ARRAY, |
| 39 | 39 | ); |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | */ |
| 88 | 88 | protected function bowOutEarly() |
| 89 | 89 | { |
| 90 | - return ($this->supportsBelow('7.0') === false); |
|
| 90 | + return ( $this->supportsBelow( '7.0' ) === false ); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | /** |
@@ -99,47 +99,47 @@ discard block |
||
| 99 | 99 | * |
| 100 | 100 | * @return void |
| 101 | 101 | */ |
| 102 | - public function process(File $phpcsFile, $stackPtr) |
|
| 102 | + public function process( File $phpcsFile, $stackPtr ) |
|
| 103 | 103 | { |
| 104 | - if ($this->bowOutEarly() === true) { |
|
| 104 | + if ( $this->bowOutEarly() === true ) { |
|
| 105 | 105 | return; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | $tokens = $phpcsFile->getTokens(); |
| 109 | 109 | |
| 110 | - if ($tokens[$stackPtr]['code'] === \T_OPEN_SHORT_ARRAY |
|
| 111 | - && $this->isShortList($phpcsFile, $stackPtr) === false |
|
| 110 | + if ( $tokens[ $stackPtr ][ 'code' ] === \T_OPEN_SHORT_ARRAY |
|
| 111 | + && $this->isShortList( $phpcsFile, $stackPtr ) === false |
|
| 112 | 112 | ) { |
| 113 | 113 | // Short array, not short list. |
| 114 | 114 | return; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - if ($tokens[$stackPtr]['code'] === \T_LIST) { |
|
| 118 | - $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); |
|
| 119 | - if ($nextNonEmpty === false |
|
| 120 | - || $tokens[$nextNonEmpty]['code'] !== \T_OPEN_PARENTHESIS |
|
| 121 | - || isset($tokens[$nextNonEmpty]['parenthesis_closer']) === false |
|
| 117 | + if ( $tokens[ $stackPtr ][ 'code' ] === \T_LIST ) { |
|
| 118 | + $nextNonEmpty = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true ); |
|
| 119 | + if ( $nextNonEmpty === false |
|
| 120 | + || $tokens[ $nextNonEmpty ][ 'code' ] !== \T_OPEN_PARENTHESIS |
|
| 121 | + || isset( $tokens[ $nextNonEmpty ][ 'parenthesis_closer' ] ) === false |
|
| 122 | 122 | ) { |
| 123 | 123 | // Parse error or live coding. |
| 124 | 124 | return; |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | $opener = $nextNonEmpty; |
| 128 | - $closer = $tokens[$nextNonEmpty]['parenthesis_closer']; |
|
| 128 | + $closer = $tokens[ $nextNonEmpty ][ 'parenthesis_closer' ]; |
|
| 129 | 129 | } else { |
| 130 | 130 | // Short list syntax. |
| 131 | 131 | $opener = $stackPtr; |
| 132 | 132 | |
| 133 | - if (isset($tokens[$stackPtr]['bracket_closer'])) { |
|
| 134 | - $closer = $tokens[$stackPtr]['bracket_closer']; |
|
| 133 | + if ( isset( $tokens[ $stackPtr ][ 'bracket_closer' ] ) ) { |
|
| 134 | + $closer = $tokens[ $stackPtr ][ 'bracket_closer' ]; |
|
| 135 | 135 | } |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - if (isset($opener, $closer) === false) { |
|
| 138 | + if ( isset( $opener, $closer ) === false ) { |
|
| 139 | 139 | return; |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - $this->examineList($phpcsFile, $opener, $closer); |
|
| 142 | + $this->examineList( $phpcsFile, $opener, $closer ); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | |
@@ -152,10 +152,10 @@ discard block |
||
| 152 | 152 | * |
| 153 | 153 | * @return void |
| 154 | 154 | */ |
| 155 | - protected function examineList(File $phpcsFile, $opener, $closer) |
|
| 155 | + protected function examineList( File $phpcsFile, $opener, $closer ) |
|
| 156 | 156 | { |
| 157 | 157 | $start = $opener; |
| 158 | - while (($start = $this->hasTargetInList($phpcsFile, $start, $closer)) !== false) { |
|
| 158 | + while ( ( $start = $this->hasTargetInList( $phpcsFile, $start, $closer ) ) !== false ) { |
|
| 159 | 159 | $phpcsFile->addError( |
| 160 | 160 | 'Specifying keys in list constructs is not supported in PHP 7.0 or earlier.', |
| 161 | 161 | $start, |
@@ -177,32 +177,32 @@ discard block |
||
| 177 | 177 | * |
| 178 | 178 | * @return int|bool Stack pointer to the target token if encountered. False otherwise. |
| 179 | 179 | */ |
| 180 | - protected function hasTargetInList(File $phpcsFile, $start, $closer) |
|
| 180 | + protected function hasTargetInList( File $phpcsFile, $start, $closer ) |
|
| 181 | 181 | { |
| 182 | 182 | $tokens = $phpcsFile->getTokens(); |
| 183 | 183 | |
| 184 | - for ($i = ($start + 1); $i < $closer; $i++) { |
|
| 185 | - if (isset($this->allTargets[$tokens[$i]['code']]) === false) { |
|
| 184 | + for ( $i = ( $start + 1 ); $i < $closer; $i++ ) { |
|
| 185 | + if ( isset( $this->allTargets[ $tokens[ $i ][ 'code' ] ] ) === false ) { |
|
| 186 | 186 | continue; |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - if (isset($this->targetsInList[$tokens[$i]['code']]) === true) { |
|
| 189 | + if ( isset( $this->targetsInList[ $tokens[ $i ][ 'code' ] ] ) === true ) { |
|
| 190 | 190 | return $i; |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | // Skip past nested list constructs. |
| 194 | - if ($tokens[$i]['code'] === \T_LIST) { |
|
| 195 | - $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($i + 1), null, true); |
|
| 196 | - if ($nextNonEmpty !== false |
|
| 197 | - && $tokens[$nextNonEmpty]['code'] === \T_OPEN_PARENTHESIS |
|
| 198 | - && isset($tokens[$nextNonEmpty]['parenthesis_closer']) === true |
|
| 194 | + if ( $tokens[ $i ][ 'code' ] === \T_LIST ) { |
|
| 195 | + $nextNonEmpty = $phpcsFile->findNext( Tokens::$emptyTokens, ( $i + 1 ), null, true ); |
|
| 196 | + if ( $nextNonEmpty !== false |
|
| 197 | + && $tokens[ $nextNonEmpty ][ 'code' ] === \T_OPEN_PARENTHESIS |
|
| 198 | + && isset( $tokens[ $nextNonEmpty ][ 'parenthesis_closer' ] ) === true |
|
| 199 | 199 | ) { |
| 200 | - $i = $tokens[$nextNonEmpty]['parenthesis_closer']; |
|
| 200 | + $i = $tokens[ $nextNonEmpty ][ 'parenthesis_closer' ]; |
|
| 201 | 201 | } |
| 202 | - } elseif ($tokens[$i]['code'] === \T_OPEN_SHORT_ARRAY |
|
| 203 | - && isset($tokens[$i]['bracket_closer']) |
|
| 202 | + } elseif ( $tokens[ $i ][ 'code' ] === \T_OPEN_SHORT_ARRAY |
|
| 203 | + && isset( $tokens[ $i ][ 'bracket_closer' ] ) |
|
| 204 | 204 | ) { |
| 205 | - $i = $tokens[$i]['bracket_closer']; |
|
| 205 | + $i = $tokens[ $i ][ 'bracket_closer' ]; |
|
| 206 | 206 | } |
| 207 | 207 | } |
| 208 | 208 | |
@@ -26,8 +26,7 @@ discard block |
||
| 26 | 26 | * @package PHPCompatibility |
| 27 | 27 | * @author Juliette Reinders Folmer <[email protected]> |
| 28 | 28 | */ |
| 29 | -class NewKeyedListSniff extends Sniff |
|
| 30 | -{ |
|
| 29 | +class NewKeyedListSniff extends Sniff { |
|
| 31 | 30 | /** |
| 32 | 31 | * Tokens which represent the start of a list construct. |
| 33 | 32 | * |
@@ -63,8 +62,7 @@ discard block |
||
| 63 | 62 | * |
| 64 | 63 | * @return array |
| 65 | 64 | */ |
| 66 | - public function register() |
|
| 67 | - { |
|
| 65 | + public function register() { |
|
| 68 | 66 | $this->setUpAllTargets(); |
| 69 | 67 | |
| 70 | 68 | return $this->sniffTargets; |
@@ -75,8 +73,7 @@ discard block |
||
| 75 | 73 | * |
| 76 | 74 | * @return array |
| 77 | 75 | */ |
| 78 | - public function setUpAllTargets() |
|
| 79 | - { |
|
| 76 | + public function setUpAllTargets() { |
|
| 80 | 77 | $this->allTargets = $this->sniffTargets + $this->targetsInList; |
| 81 | 78 | } |
| 82 | 79 | |
@@ -85,8 +82,7 @@ discard block |
||
| 85 | 82 | * |
| 86 | 83 | * @return bool |
| 87 | 84 | */ |
| 88 | - protected function bowOutEarly() |
|
| 89 | - { |
|
| 85 | + protected function bowOutEarly() { |
|
| 90 | 86 | return ($this->supportsBelow('7.0') === false); |
| 91 | 87 | } |
| 92 | 88 | |
@@ -99,8 +95,7 @@ discard block |
||
| 99 | 95 | * |
| 100 | 96 | * @return void |
| 101 | 97 | */ |
| 102 | - public function process(File $phpcsFile, $stackPtr) |
|
| 103 | - { |
|
| 98 | + public function process(File $phpcsFile, $stackPtr) { |
|
| 104 | 99 | if ($this->bowOutEarly() === true) { |
| 105 | 100 | return; |
| 106 | 101 | } |
@@ -152,8 +147,7 @@ discard block |
||
| 152 | 147 | * |
| 153 | 148 | * @return void |
| 154 | 149 | */ |
| 155 | - protected function examineList(File $phpcsFile, $opener, $closer) |
|
| 156 | - { |
|
| 150 | + protected function examineList(File $phpcsFile, $opener, $closer) { |
|
| 157 | 151 | $start = $opener; |
| 158 | 152 | while (($start = $this->hasTargetInList($phpcsFile, $start, $closer)) !== false) { |
| 159 | 153 | $phpcsFile->addError( |
@@ -177,8 +171,7 @@ discard block |
||
| 177 | 171 | * |
| 178 | 172 | * @return int|bool Stack pointer to the target token if encountered. False otherwise. |
| 179 | 173 | */ |
| 180 | - protected function hasTargetInList(File $phpcsFile, $start, $closer) |
|
| 181 | - { |
|
| 174 | + protected function hasTargetInList(File $phpcsFile, $start, $closer) { |
|
| 182 | 175 | $tokens = $phpcsFile->getTokens(); |
| 183 | 176 | |
| 184 | 177 | for ($i = ($start + 1); $i < $closer; $i++) { |