diff --git a/coder_sniffer/Drupal/Sniffs/Arrays/ArraySniff.php b/coder_sniffer/Drupal/Sniffs/Arrays/ArraySniff.php index e1edb9fb2b9922062d39d8513fad9300885323a7..3860fa2ff7d3c595a087e3aa37489c01fe7fe55f 100644 --- a/coder_sniffer/Drupal/Sniffs/Arrays/ArraySniff.php +++ b/coder_sniffer/Drupal/Sniffs/Arrays/ArraySniff.php @@ -35,10 +35,10 @@ class ArraySniff implements Sniff */ public function register() { - return array( - T_ARRAY, - T_OPEN_SHORT_ARRAY, - ); + return [ + T_ARRAY, + T_OPEN_SHORT_ARRAY, + ]; }//end register() @@ -57,33 +57,33 @@ class ArraySniff implements Sniff $tokens = $phpcsFile->getTokens(); // Support long and short syntax. - $parenthesis_opener = 'parenthesis_opener'; - $parenthesis_closer = 'parenthesis_closer'; + $parenthesisOpener = 'parenthesis_opener'; + $parenthesisCloser = 'parenthesis_closer'; if ($tokens[$stackPtr]['code'] === T_OPEN_SHORT_ARRAY) { - $parenthesis_opener = 'bracket_opener'; - $parenthesis_closer = 'bracket_closer'; + $parenthesisOpener = 'bracket_opener'; + $parenthesisCloser = 'bracket_closer'; } // Sanity check: this can sometimes be NULL if the array was not correctly // parsed. - if ($tokens[$stackPtr][$parenthesis_closer] === null) { + if ($tokens[$stackPtr][$parenthesisCloser] === null) { return; } $lastItem = $phpcsFile->findPrevious( Tokens::$emptyTokens, - ($tokens[$stackPtr][$parenthesis_closer] - 1), + ($tokens[$stackPtr][$parenthesisCloser] - 1), $stackPtr, true ); // Empty array. - if ($lastItem === $tokens[$stackPtr][$parenthesis_opener]) { + if ($lastItem === $tokens[$stackPtr][$parenthesisOpener]) { return; } // Inline array. - $isInlineArray = $tokens[$tokens[$stackPtr][$parenthesis_opener]]['line'] === $tokens[$tokens[$stackPtr][$parenthesis_closer]]['line']; + $isInlineArray = $tokens[$tokens[$stackPtr][$parenthesisOpener]]['line'] === $tokens[$tokens[$stackPtr][$parenthesisCloser]]['line']; // Check if the last item in a multiline array has a "closing" comma. if ($tokens[$lastItem]['code'] !== T_COMMA && $isInlineArray === false @@ -91,7 +91,7 @@ class ArraySniff implements Sniff && $tokens[($lastItem + 1)]['code'] !== T_CLOSE_SHORT_ARRAY && isset(Tokens::$heredocTokens[$tokens[$lastItem]['code']]) === false ) { - $data = array($tokens[$lastItem]['content']); + $data = [$tokens[$lastItem]['content']]; $fix = $phpcsFile->addFixableWarning('A comma should follow the last multiline array item. Found: %s', $lastItem, 'CommaLastItem', $data); if ($fix === true) { $phpcsFile->fixer->addContent($lastItem, ','); @@ -103,10 +103,10 @@ class ArraySniff implements Sniff if ($isInlineArray === true) { // Check if this array contains at least 3 elements and exceeds the 80 // character line length. - if ($tokens[$tokens[$stackPtr][$parenthesis_closer]]['column'] > 80) { - $comma1 = $phpcsFile->findNext(T_COMMA, ($stackPtr + 1), $tokens[$stackPtr][$parenthesis_closer]); + if ($tokens[$tokens[$stackPtr][$parenthesisCloser]]['column'] > 80) { + $comma1 = $phpcsFile->findNext(T_COMMA, ($stackPtr + 1), $tokens[$stackPtr][$parenthesisCloser]); if ($comma1 !== false) { - $comma2 = $phpcsFile->findNext(T_COMMA, ($comma1 + 1), $tokens[$stackPtr][$parenthesis_closer]); + $comma2 = $phpcsFile->findNext(T_COMMA, ($comma1 + 1), $tokens[$stackPtr][$parenthesisCloser]); if ($comma2 !== false) { $error = 'If the line declaring an array spans longer than 80 characters, each element should be broken into its own line'; $phpcsFile->addError($error, $stackPtr, 'LongLineDeclaration'); @@ -146,15 +146,15 @@ class ArraySniff implements Sniff $lineStart = $stackPtr; // Iterate over all lines of this array. - while ($lineStart < $tokens[$stackPtr][$parenthesis_closer]) { + while ($lineStart < $tokens[$stackPtr][$parenthesisCloser]) { // Find next line start. $newLineStart = $lineStart; - $current_line = $tokens[$newLineStart]['line']; - while ($current_line >= $tokens[$newLineStart]['line']) { + $currentLine = $tokens[$newLineStart]['line']; + while ($currentLine >= $tokens[$newLineStart]['line']) { $newLineStart = $phpcsFile->findNext( Tokens::$emptyTokens, ($newLineStart + 1), - ($tokens[$stackPtr][$parenthesis_closer] + 1), + ($tokens[$stackPtr][$parenthesisCloser] + 1), true ); @@ -166,32 +166,32 @@ class ArraySniff implements Sniff // run. if ($tokens[$newLineStart]['code'] === T_ARRAY) { $newLineStart = $tokens[$newLineStart]['parenthesis_closer']; - $current_line = $tokens[$newLineStart]['line']; + $currentLine = $tokens[$newLineStart]['line']; } // Short array syntax: Skip nested arrays, they are checked in a next // run. if ($tokens[$newLineStart]['code'] === T_OPEN_SHORT_ARRAY) { $newLineStart = $tokens[$newLineStart]['bracket_closer']; - $current_line = $tokens[$newLineStart]['line']; + $currentLine = $tokens[$newLineStart]['line']; } // Nested structures such as closures: skip those, they are checked // in other sniffs. If the conditions of a token are different it // means that it is in a different nesting level. if ($tokens[$newLineStart]['conditions'] !== $tokens[$stackPtr]['conditions']) { - $current_line++; + $currentLine++; } }//end while - if ($newLineStart === $tokens[$stackPtr][$parenthesis_closer]) { + if ($newLineStart === $tokens[$stackPtr][$parenthesisCloser]) { // End of the array reached. if ($tokens[$newLineStart]['column'] !== $firstLineColumn) { $error = 'Array closing indentation error, expected %s spaces but found %s'; - $data = array( - $firstLineColumn - 1, - $tokens[$newLineStart]['column'] - 1, - ); + $data = [ + ($firstLineColumn - 1), + ($tokens[$newLineStart]['column'] - 1), + ]; $fix = $phpcsFile->addFixableError($error, $newLineStart, 'ArrayClosingIndentation', $data); if ($fix === true) { if ($tokens[$newLineStart]['column'] === 1) { @@ -216,7 +216,7 @@ class ArraySniff implements Sniff // Skip lines in nested structures such as a function call within an // array, no defined coding standard for those. $innerNesting = empty($tokens[$newLineStart]['nested_parenthesis']) === false - && end($tokens[$newLineStart]['nested_parenthesis']) < $tokens[$stackPtr][$parenthesis_closer]; + && end($tokens[$newLineStart]['nested_parenthesis']) < $tokens[$stackPtr][$parenthesisCloser]; // Skip lines that are part of a multi-line string. $isMultiLineString = $tokens[($newLineStart - 1)]['code'] === T_CONSTANT_ENCAPSED_STRING && substr($tokens[($newLineStart - 1)]['content'], -1) === $phpcsFile->eolChar; @@ -224,10 +224,10 @@ class ArraySniff implements Sniff $nowDoc = isset(Tokens::$heredocTokens[$tokens[$newLineStart]['code']]); if ($innerNesting === false && $isMultiLineString === false && $nowDoc === false) { $error = 'Array indentation error, expected %s spaces but found %s'; - $data = array( - $expectedColumn - 1, - $tokens[$newLineStart]['column'] - 1, - ); + $data = [ + ($expectedColumn - 1), + ($tokens[$newLineStart]['column'] - 1), + ]; $fix = $phpcsFile->addFixableError($error, $newLineStart, 'ArrayIndentation', $data); if ($fix === true) { if ($tokens[$newLineStart]['column'] === 1) { diff --git a/coder_sniffer/Drupal/Sniffs/CSS/ClassDefinitionNameSpacingSniff.php b/coder_sniffer/Drupal/Sniffs/CSS/ClassDefinitionNameSpacingSniff.php index a3780c282d8bc4c8b3c3e4158cd3c9fe2b6ea0d7..fc55d2262441334bec94c0e077b4326a448e24c8 100644 --- a/coder_sniffer/Drupal/Sniffs/CSS/ClassDefinitionNameSpacingSniff.php +++ b/coder_sniffer/Drupal/Sniffs/CSS/ClassDefinitionNameSpacingSniff.php @@ -30,7 +30,7 @@ class ClassDefinitionNameSpacingSniff implements Sniff * * @var array */ - public $supportedTokenizers = array('CSS'); + public $supportedTokenizers = ['CSS']; /** @@ -40,7 +40,7 @@ class ClassDefinitionNameSpacingSniff implements Sniff */ public function register() { - return array(T_OPEN_CURLY_BRACKET); + return [T_OPEN_CURLY_BRACKET]; }//end register() @@ -66,11 +66,11 @@ class ClassDefinitionNameSpacingSniff implements Sniff // Find the first blank line before this opening brace, unless we get // to another style definition, comment or the start of the file. - $endTokens = array( - T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET, - T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, - T_OPEN_TAG => T_OPEN_TAG, - ); + $endTokens = [ + T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET, + T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, + T_OPEN_TAG => T_OPEN_TAG, + ]; $endTokens += Tokens::$commentTokens; $foundContent = false; @@ -95,7 +95,7 @@ class ClassDefinitionNameSpacingSniff implements Sniff if ($tokens[$i]['code'] === T_WHITESPACE && strpos($tokens[$i]['content'], $phpcsFile->eolChar) !== false && isset($endTokens[$tokens[($i - 1)]['code']]) === false - && in_array($tokens[($i - 1)]['code'], array(T_WHITESPACE, T_COMMA)) === false + && in_array($tokens[($i - 1)]['code'], [T_WHITESPACE, T_COMMA]) === false ) { $error = 'Selectors must be on a single line'; $fix = $phpcsFile->addFixableError($error, $i, 'SeletorSingleLine'); diff --git a/coder_sniffer/Drupal/Sniffs/CSS/ColourDefinitionSniff.php b/coder_sniffer/Drupal/Sniffs/CSS/ColourDefinitionSniff.php index be8f88898c36a0d3627b80bb4ab2b4965c528c93..8f622bfcf0c2dccc0e85230bfe6fc26a70a233ca 100644 --- a/coder_sniffer/Drupal/Sniffs/CSS/ColourDefinitionSniff.php +++ b/coder_sniffer/Drupal/Sniffs/CSS/ColourDefinitionSniff.php @@ -29,7 +29,7 @@ class ColourDefinitionSniff implements Sniff * * @var array */ - public $supportedTokenizers = array('CSS'); + public $supportedTokenizers = ['CSS']; /** @@ -39,7 +39,7 @@ class ColourDefinitionSniff implements Sniff */ public function register() { - return array(T_COLOUR); + return [T_COLOUR]; }//end register() @@ -61,10 +61,10 @@ class ColourDefinitionSniff implements Sniff $expected = strtolower($colour); if ($colour !== $expected) { $error = 'CSS colours must be defined in lowercase; expected %s but found %s'; - $data = array( - $expected, - $colour, - ); + $data = [ + $expected, + $colour, + ]; $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NotLower', $data); if ($fix === true) { $phpcsFile->fixer->replaceToken($stackPtr, $expected); diff --git a/coder_sniffer/Drupal/Sniffs/Classes/ClassCreateInstanceSniff.php b/coder_sniffer/Drupal/Sniffs/Classes/ClassCreateInstanceSniff.php index bb08722e7eb08beb35e26636b0284181a9cfb168..febe0110eeb57341b7f5bad5338a0ffbc5a1d86c 100644 --- a/coder_sniffer/Drupal/Sniffs/Classes/ClassCreateInstanceSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Classes/ClassCreateInstanceSniff.php @@ -33,7 +33,7 @@ class ClassCreateInstanceSniff implements Sniff */ public function register() { - return array(T_NEW); + return [T_NEW]; }//end register() diff --git a/coder_sniffer/Drupal/Sniffs/Classes/ClassDeclarationSniff.php b/coder_sniffer/Drupal/Sniffs/Classes/ClassDeclarationSniff.php index ea63234b7dafe275312b91c92cf665388962cfe6..b3a1da81b3cc05ca1c7a1b2f4f2c5046f38c7f2e 100644 --- a/coder_sniffer/Drupal/Sniffs/Classes/ClassDeclarationSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Classes/ClassDeclarationSniff.php @@ -33,11 +33,11 @@ class ClassDeclarationSniff extends PSR2ClassDeclarationSniff */ public function register() { - return array( - T_CLASS, - T_INTERFACE, - T_TRAIT, - ); + return [ + T_CLASS, + T_INTERFACE, + T_TRAIT, + ]; }//end register() @@ -54,7 +54,7 @@ class ClassDeclarationSniff extends PSR2ClassDeclarationSniff public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); - $errorData = array(strtolower($tokens[$stackPtr]['content'])); + $errorData = [strtolower($tokens[$stackPtr]['content'])]; if (isset($tokens[$stackPtr]['scope_opener']) === false) { $error = 'Possible parse error: %s missing opening or closing brace'; @@ -106,7 +106,7 @@ class ClassDeclarationSniff extends PSR2ClassDeclarationSniff if ($length !== 1) { $error = 'Expected 1 space before opening brace; found %s'; - $data = array($length); + $data = [$length]; $fix = $phpcsFile->addFixableError($error, $openingBrace, 'SpaceBeforeBrace', $data); if ($fix === true) { if ($length === 0) { @@ -152,7 +152,7 @@ class ClassDeclarationSniff extends PSR2ClassDeclarationSniff && isset(Tokens::$commentTokens[$tokens[$prevContent]['code']]) === false ) { $error = 'The closing brace for the %s must have an empty line before it'; - $data = array($tokens[$stackPtr]['content']); + $data = [$tokens[$stackPtr]['content']]; $fix = $phpcsFile->addFixableError($error, $closeBrace, 'CloseBraceAfterBody', $data); if ($fix === true) { @@ -175,7 +175,7 @@ class ClassDeclarationSniff extends PSR2ClassDeclarationSniff ) { $type = strtolower($tokens[$stackPtr]['content']); $error = 'Closing %s brace must be on a line by itself'; - $data = array($tokens[$stackPtr]['content']); + $data = [$tokens[$stackPtr]['content']]; $phpcsFile->addError($error, $closeBrace, 'CloseBraceSameLine', $data); } diff --git a/coder_sniffer/Drupal/Sniffs/Classes/FullyQualifiedNamespaceSniff.php b/coder_sniffer/Drupal/Sniffs/Classes/FullyQualifiedNamespaceSniff.php index 46f71ab8e93ff8cbbfb0d06172d5d5be519a45d0..ba81c73d920f57ec6f1cabc1aac59f8cfb504734 100644 --- a/coder_sniffer/Drupal/Sniffs/Classes/FullyQualifiedNamespaceSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Classes/FullyQualifiedNamespaceSniff.php @@ -30,7 +30,7 @@ class FullyQualifiedNamespaceSniff implements Sniff */ public function register() { - return array(T_NS_SEPARATOR); + return [T_NS_SEPARATOR]; }//end register() diff --git a/coder_sniffer/Drupal/Sniffs/Classes/InterfaceNameSniff.php b/coder_sniffer/Drupal/Sniffs/Classes/InterfaceNameSniff.php index 156ea060b6cdbb15e94fa58613be875e2db3bc2a..689f4ae11d1e1ce9523ba89727c0000629c0b49b 100644 --- a/coder_sniffer/Drupal/Sniffs/Classes/InterfaceNameSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Classes/InterfaceNameSniff.php @@ -30,7 +30,7 @@ class InterfaceNameSniff implements Sniff */ public function register() { - return array(T_INTERFACE); + return [T_INTERFACE]; }//end register() diff --git a/coder_sniffer/Drupal/Sniffs/Classes/PropertyDeclarationSniff.php b/coder_sniffer/Drupal/Sniffs/Classes/PropertyDeclarationSniff.php index ffd231d3d9e2167b01f59c6b2f82a8e8cf05fa2c..e4fd2427faa3a093b061f4a157df7f81b3fc16f0 100644 --- a/coder_sniffer/Drupal/Sniffs/Classes/PropertyDeclarationSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Classes/PropertyDeclarationSniff.php @@ -40,7 +40,7 @@ class PropertyDeclarationSniff extends AbstractVariableSniff if ($tokens[$stackPtr]['content'][1] === '_') { $error = 'Property name "%s" should not be prefixed with an underscore to indicate visibility'; - $data = array($tokens[$stackPtr]['content']); + $data = [$tokens[$stackPtr]['content']]; $phpcsFile->addWarning($error, $stackPtr, 'Underscore', $data); } @@ -48,7 +48,7 @@ class PropertyDeclarationSniff extends AbstractVariableSniff // for this, but also only process the first property in the list so we don't // repeat errors. $find = Tokens::$scopeModifiers; - $find = array_merge($find, array(T_VARIABLE, T_VAR, T_SEMICOLON)); + $find = array_merge($find, [T_VARIABLE, T_VAR, T_SEMICOLON]); $prev = $phpcsFile->findPrevious($find, ($stackPtr - 1)); if ($tokens[$prev]['code'] === T_VARIABLE) { return; @@ -62,7 +62,7 @@ class PropertyDeclarationSniff extends AbstractVariableSniff } } - $next = $phpcsFile->findNext(array(T_VARIABLE, T_SEMICOLON), ($stackPtr + 1)); + $next = $phpcsFile->findNext([T_VARIABLE, T_SEMICOLON], ($stackPtr + 1)); if ($tokens[$next]['code'] === T_VARIABLE) { $error = 'There must not be more than one property declared per statement'; $phpcsFile->addError($error, $stackPtr, 'Multiple'); @@ -71,7 +71,7 @@ class PropertyDeclarationSniff extends AbstractVariableSniff $modifier = $phpcsFile->findPrevious(Tokens::$scopeModifiers, $stackPtr); if (($modifier === false) || ($tokens[$modifier]['line'] !== $tokens[$stackPtr]['line'])) { $error = 'Visibility must be declared on property "%s"'; - $data = array($tokens[$stackPtr]['content']); + $data = [$tokens[$stackPtr]['content']]; $phpcsFile->addError($error, $stackPtr, 'ScopeMissing', $data); } diff --git a/coder_sniffer/Drupal/Sniffs/Classes/UnusedUseStatementSniff.php b/coder_sniffer/Drupal/Sniffs/Classes/UnusedUseStatementSniff.php index c3755a9ad5abda8a9e22c1d218c7bb176fc71659..7964d3a4216212234da58f064b38818ee34eaa25 100644 --- a/coder_sniffer/Drupal/Sniffs/Classes/UnusedUseStatementSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Classes/UnusedUseStatementSniff.php @@ -31,7 +31,7 @@ class UnusedUseStatementSniff implements Sniff */ public function register() { - return array(T_USE); + return [T_USE]; }//end register() @@ -87,9 +87,9 @@ class UnusedUseStatementSniff implements Sniff if ($namespacePtr !== false && $aliasUsed === false) { $nsEnd = $phpcsFile->findNext( [ - T_NS_SEPARATOR, - T_STRING, - T_WHITESPACE, + T_NS_SEPARATOR, + T_STRING, + T_WHITESPACE, ], ($namespacePtr + 1), null, @@ -100,16 +100,16 @@ class UnusedUseStatementSniff implements Sniff $useNamespacePtr = $phpcsFile->findNext([T_STRING], ($stackPtr + 1)); $useNamespaceEnd = $phpcsFile->findNext( [ - T_NS_SEPARATOR, - T_STRING, + T_NS_SEPARATOR, + T_STRING, ], ($useNamespacePtr + 1), null, true ); - $use_namespace = rtrim($phpcsFile->getTokensAsString($useNamespacePtr, ($useNamespaceEnd - $useNamespacePtr - 1)), '\\'); + $useNamespace = rtrim($phpcsFile->getTokensAsString($useNamespacePtr, ($useNamespaceEnd - $useNamespacePtr - 1)), '\\'); - if (strcasecmp($namespace, $use_namespace) === 0) { + if (strcasecmp($namespace, $useNamespace) === 0) { $classUsed = false; } }//end if @@ -133,16 +133,16 @@ class UnusedUseStatementSniff implements Sniff if (in_array( $tokens[$beforeUsage]['code'], [ - T_USE, - T_NS_SEPARATOR, + T_USE, + T_NS_SEPARATOR, // If an object operator is used then this is a method call // with the same name as the class name. Which means this is // not referring to the class. - T_OBJECT_OPERATOR, + T_OBJECT_OPERATOR, // Function definition, not class invocation. - T_FUNCTION, + T_FUNCTION, // Static method call, not class invocation. - T_DOUBLE_COLON, + T_DOUBLE_COLON, ] ) === false ) { @@ -182,8 +182,8 @@ class UnusedUseStatementSniff implements Sniff $useNamespacePtr = $phpcsFile->findNext([T_STRING], ($stackPtr + 1)); $useNamespaceEnd = $phpcsFile->findNext( [ - T_NS_SEPARATOR, - T_STRING, + T_NS_SEPARATOR, + T_STRING, ], ($useNamespacePtr + 1), null, diff --git a/coder_sniffer/Drupal/Sniffs/Classes/UseLeadingBackslashSniff.php b/coder_sniffer/Drupal/Sniffs/Classes/UseLeadingBackslashSniff.php index 9bc894a0d1ab0ce45e9dea5dad00cb6bd8aff33a..4979210bf10a40130778c9ed5bfc6fa32cfb5d3c 100644 --- a/coder_sniffer/Drupal/Sniffs/Classes/UseLeadingBackslashSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Classes/UseLeadingBackslashSniff.php @@ -31,7 +31,7 @@ class UseLeadingBackslashSniff implements Sniff */ public function register() { - return array(T_USE); + return [T_USE]; }//end register() diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/ClassCommentSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/ClassCommentSniff.php index 68bacb1b1be6ab41c954c95ea18e4c1e9320f588..8eaca41dcb52bf5e48d4e82caff01b23c9603a4e 100644 --- a/coder_sniffer/Drupal/Sniffs/Commenting/ClassCommentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Commenting/ClassCommentSniff.php @@ -36,11 +36,11 @@ class ClassCommentSniff implements Sniff */ public function register() { - return array( - T_CLASS, - T_INTERFACE, - T_TRAIT, - ); + return [ + T_CLASS, + T_INTERFACE, + T_TRAIT, + ]; }//end register() @@ -65,7 +65,7 @@ class ClassCommentSniff implements Sniff if ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG && $tokens[$commentEnd]['code'] !== T_COMMENT ) { - $fix = $phpcsFile->addFixableError('Missing %s doc comment', $stackPtr, 'Missing', array($name)); + $fix = $phpcsFile->addFixableError('Missing %s doc comment', $stackPtr, 'Missing', [$name]); if ($fix === true) { $phpcsFile->fixer->addContent($commentEnd, "\n/**\n *\n */"); } @@ -83,7 +83,7 @@ class ClassCommentSniff implements Sniff $fileTag = $phpcsFile->findNext(T_DOC_COMMENT_TAG, ($start + 1), $commentEnd, false, '@file'); if ($fileTag !== false) { // This is a file comment. - $fix = $phpcsFile->addFixableError('Missing %s doc comment', $stackPtr, 'Missing', array($name)); + $fix = $phpcsFile->addFixableError('Missing %s doc comment', $stackPtr, 'Missing', [$name]); if ($fix === true) { $phpcsFile->fixer->addContent($commentEnd, "\n/**\n *\n */"); } @@ -92,7 +92,7 @@ class ClassCommentSniff implements Sniff } if ($tokens[$commentEnd]['code'] === T_COMMENT) { - $fix = $phpcsFile->addFixableError('You must use "/**" style comments for a %s comment', $stackPtr, 'WrongStyle', array($name)); + $fix = $phpcsFile->addFixableError('You must use "/**" style comments for a %s comment', $stackPtr, 'WrongStyle', [$name]); if ($fix === true) { // Convert the comment into a doc comment. $phpcsFile->fixer->beginChangeset(); @@ -111,7 +111,7 @@ class ClassCommentSniff implements Sniff if ($tokens[$commentEnd]['line'] !== ($tokens[$stackPtr]['line'] - 1)) { $error = 'There must be exactly one newline after the %s comment'; - $fix = $phpcsFile->addFixableError($error, $commentEnd, 'SpacingAfter', array($name)); + $fix = $phpcsFile->addFixableError($error, $commentEnd, 'SpacingAfter', [$name]); if ($fix === true) { $phpcsFile->fixer->beginChangeset(); for ($i = ($commentEnd + 1); $tokens[$i]['code'] === T_WHITESPACE && $i < $stackPtr; $i++) { diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/DataTypeNamespaceSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/DataTypeNamespaceSniff.php index 4634a8a275cab623d6b704f98939c577ab7462f2..a6c13b6e94276e0b7ea5889af4336fd4d672fa7f 100644 --- a/coder_sniffer/Drupal/Sniffs/Commenting/DataTypeNamespaceSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Commenting/DataTypeNamespaceSniff.php @@ -31,7 +31,7 @@ class DataTypeNamespaceSniff implements Sniff */ public function register() { - return array(T_USE); + return [T_USE]; }//end register() @@ -76,8 +76,8 @@ class DataTypeNamespaceSniff implements Sniff $useNamespacePtr = $phpcsFile->findNext([T_STRING], ($stackPtr + 1)); $useNamespaceEnd = $phpcsFile->findNext( [ - T_NS_SEPARATOR, - T_STRING, + T_NS_SEPARATOR, + T_STRING, ], ($useNamespacePtr + 1), null, diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/DeprecatedSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/DeprecatedSniff.php index 2ecd1c60545e672c540438a423758d84e1fe05d3..76cc05279739d5d867f5e41d3503591bafc8af69 100644 --- a/coder_sniffer/Drupal/Sniffs/Commenting/DeprecatedSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Commenting/DeprecatedSniff.php @@ -30,7 +30,7 @@ class DeprecatedSniff implements Sniff */ public function register() { - return array(T_DOC_COMMENT_TAG); + return [T_DOC_COMMENT_TAG]; }//end register() @@ -82,23 +82,23 @@ class DeprecatedSniff implements Sniff // Use (?U) 'ungreedy' before the version so that only the text up to // the first '. ' is matched, as there may be more than one sentence in // the extra-info part. - $matches = array(); + $matches = []; preg_match('/in (.+) and will be removed from (?U)(.+)\. (.+)$/', $depText, $matches); // There should be 4 items in $matches: 0 is full text, 1 = in-version, // 2 = removal-version, 3 = extra-info. if (count($matches) !== 4) { $error = "The deprecation text '@deprecated %s' does not match the standard format: @deprecated in %%in-version%% and will be removed from %%removal-version%%. %%extra-info%%."; - $phpcsFile->addError($error, $stackPtr, 'IncorrectTextLayout', array($depText)); + $phpcsFile->addError($error, $stackPtr, 'IncorrectTextLayout', [$depText]); } else { // The text follows the basic layout. Now check that the versions // match drupal:n.n.n or project:n.x-n.n. The text must be all lower // case and numbers can be one or two digits. - foreach (array('in-version' => $matches[1], 'removal-version' => $matches[2]) as $name => $version) { + foreach (['in-version' => $matches[1], 'removal-version' => $matches[2]] as $name => $version) { if (preg_match('/^drupal:\d{1,2}\.\d{1,2}\.\d{1,2}$/', $version) === 0 && preg_match('/^[a-z\d_]+:\d{1,2}\.x\-\d{1,2}\.\d{1,2}$/', $version) === 0 ) { $error = "The deprecation %s '%s' does not match the standard: drupal:n.n.n or project:n.x-n.n"; - $phpcsFile->addWarning($error, $stackPtr, 'DeprecatedVersionFormat', array($name, $version)); + $phpcsFile->addWarning($error, $stackPtr, 'DeprecatedVersionFormat', [$name, $version]); } } } @@ -112,19 +112,19 @@ class DeprecatedSniff implements Sniff } // Check the format of the @see url. - $string = $phpcsFile->findNext(T_DOC_COMMENT_STRING, ($seeTag + 1), $commentEnd); - $cr_link = $tokens[$string]['content']; + $string = $phpcsFile->findNext(T_DOC_COMMENT_STRING, ($seeTag + 1), $commentEnd); + $crLink = $tokens[$string]['content']; // Allow for the alternative 'node' or 'project/aaa/issues' format. - preg_match('[^http(s*)://www.drupal.org/(node|project/\w+/issues)/(\d+)(\.*)$]', $cr_link, $matches); + preg_match('[^http(s*)://www.drupal.org/(node|project/\w+/issues)/(\d+)(\.*)$]', $crLink, $matches); // If matches[4] is not blank it means that the url is correct but it // ends with a period. As this can be a common mistake give a specific // message to assist in fixing. if (isset($matches[4]) === true && empty($matches[4]) === false) { $error = "The @see url '%s' should not end with a period."; - $phpcsFile->addWarning($error, $seeTag, 'DeprecatedPeriodAfterSeeUrl', array($cr_link)); + $phpcsFile->addWarning($error, $seeTag, 'DeprecatedPeriodAfterSeeUrl', [$crLink]); } else if (empty($matches) === true) { $error = "The @see url '%s' does not match the standard: http(s)://www.drupal.org/node/n or http(s)://www.drupal.org/project/aaa/issues/n"; - $phpcsFile->addWarning($error, $seeTag, 'DeprecatedWrongSeeUrlFormat', array($cr_link)); + $phpcsFile->addWarning($error, $seeTag, 'DeprecatedWrongSeeUrlFormat', [$crLink]); } }//end process() diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentAlignmentSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentAlignmentSniff.php index 167b2def534baabf3af308349d6f735beb0696f2..8d4f034764004cc50560f7eb57aa414140922b15 100644 --- a/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentAlignmentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentAlignmentSniff.php @@ -34,7 +34,7 @@ class DocCommentAlignmentSniff implements Sniff */ public function register() { - return array(T_DOC_COMMENT_OPEN_TAG); + return [T_DOC_COMMENT_OPEN_TAG]; }//end register() @@ -61,20 +61,20 @@ class DocCommentAlignmentSniff implements Sniff } $nextToken = $phpcsFile->findNext($ignore, ($stackPtr + 1), null, true); - $ignore = array( - T_CLASS => true, - T_INTERFACE => true, - T_FUNCTION => true, - T_PUBLIC => true, - T_PRIVATE => true, - T_PROTECTED => true, - T_STATIC => true, - T_ABSTRACT => true, - T_PROPERTY => true, - T_OBJECT => true, - T_PROTOTYPE => true, - T_VAR => true, - ); + $ignore = [ + T_CLASS => true, + T_INTERFACE => true, + T_FUNCTION => true, + T_PUBLIC => true, + T_PRIVATE => true, + T_PROTECTED => true, + T_STATIC => true, + T_ABSTRACT => true, + T_PROPERTY => true, + T_OBJECT => true, + T_PROTOTYPE => true, + T_VAR => true, + ]; if (isset($ignore[$tokens[$nextToken]['code']]) === false) { // Could be a file comment. @@ -105,10 +105,10 @@ class DocCommentAlignmentSniff implements Sniff if ($tokens[$i]['column'] !== $requiredColumn) { $error = 'Expected %s space(s) before asterisk; %s found'; - $data = array( - ($requiredColumn - 1), - ($tokens[$i]['column'] - 1), - ); + $data = [ + ($requiredColumn - 1), + ($tokens[$i]['column'] - 1), + ]; $fix = $phpcsFile->addFixableError($error, $i, 'SpaceBeforeStar', $data); if ($fix === true) { $padding = str_repeat(' ', ($requiredColumn - 1)); @@ -139,7 +139,7 @@ class DocCommentAlignmentSniff implements Sniff && $tokens[($i + 1)]['content'] !== ' ' ) { $error = 'Expected 1 space after asterisk; %s found'; - $data = array(strlen($tokens[($i + 1)]['content'])); + $data = [strlen($tokens[($i + 1)]['content'])]; $fix = $phpcsFile->addFixableError($error, $i, 'SpaceAfterStar', $data); if ($fix === true) { $phpcsFile->fixer->replaceToken(($i + 1), ' '); diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentSniff.php index ecc948a99ef551ae08dfb7dab93a399de63985fd..d0d00755636f8c133aa6dd07543651510d15ee3f 100644 --- a/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentSniff.php @@ -31,10 +31,10 @@ class DocCommentSniff implements Sniff * * @var array */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); + public $supportedTokenizers = [ + 'PHP', + 'JS', + ]; /** @@ -44,7 +44,7 @@ class DocCommentSniff implements Sniff */ public function register() { - return array(T_DOC_COMMENT_OPEN_TAG); + return [T_DOC_COMMENT_OPEN_TAG]; }//end register() @@ -64,10 +64,10 @@ class DocCommentSniff implements Sniff $commentEnd = $phpcsFile->findNext(T_DOC_COMMENT_CLOSE_TAG, ($stackPtr + 1)); $commentStart = $tokens[$commentEnd]['comment_opener']; - $empty = array( - T_DOC_COMMENT_WHITESPACE, - T_DOC_COMMENT_STAR, - ); + $empty = [ + T_DOC_COMMENT_WHITESPACE, + T_DOC_COMMENT_STAR, + ]; $short = $phpcsFile->findNext($empty, ($stackPtr + 1), $commentEnd, true); if ($short === false) { @@ -99,7 +99,7 @@ class DocCommentSniff implements Sniff $prev = $phpcsFile->findPrevious($empty, ($commentEnd - 1), $stackPtr, true); if ($tokens[$commentEnd]['content'] !== '*/') { $error = 'Wrong function doc comment end; expected "*/", found "%s"'; - $phpcsFile->addError($error, $commentEnd, 'WrongEnd', array($tokens[$commentEnd]['content'])); + $phpcsFile->addError($error, $commentEnd, 'WrongEnd', [$tokens[$commentEnd]['content']]); } // Check for additional blank lines at the end of the comment. @@ -131,7 +131,7 @@ class DocCommentSniff implements Sniff // Do not check defgroup sections, they have no short description. Also don't // check PHPUnit tests doc blocks because they might not have a description. - if (in_array($tokens[$short]['content'], array('@defgroup', '@addtogroup', '@}', '@coversDefaultClass')) === true) { + if (in_array($tokens[$short]['content'], ['@defgroup', '@addtogroup', '@}', '@coversDefaultClass']) === true) { return; } @@ -235,7 +235,7 @@ class DocCommentSniff implements Sniff } $lastChar = substr($shortContent, -1); - if (in_array($lastChar, array('.', '!', '?', ')')) === false && $shortContent !== '{@inheritdoc}' + if (in_array($lastChar, ['.', '!', '?', ')']) === false && $shortContent !== '{@inheritdoc}' // Ignore Features module export files that just use the file name as // comment. && $shortContent !== basename($phpcsFile->getFilename()) @@ -335,7 +335,7 @@ class DocCommentSniff implements Sniff // This does not apply to @file, @code, @link and @endlink tags. if ($tokens[$firstTag]['line'] !== ($tokens[$prev]['line'] + 2) && isset($fileShort) === false - && in_array($tokens[$firstTag]['content'], array('@code', '@link', '@endlink')) === false + && in_array($tokens[$firstTag]['content'], ['@code', '@link', '@endlink']) === false ) { $error = 'There must be exactly one blank line before the tags in a doc comment'; $fix = $phpcsFile->addFixableError($error, $firstTag, 'SpacingBeforeTags'); @@ -358,7 +358,7 @@ class DocCommentSniff implements Sniff // Break out the tags into groups and check alignment within each. // A tag group is one where there are no blank lines between tags. // The param tag group is special as it requires all @param tags to be inside. - $tagGroups = array(); + $tagGroups = []; $groupid = 0; $paramGroupid = null; $currentTag = null; @@ -400,12 +400,12 @@ class DocCommentSniff implements Sniff // The @param, @return and @throws tag sections should be // separated by a blank line both before and after these sections. } else if ($isNewGroup === false - && (in_array($currentTag, array('@param', '@return', '@throws')) === true - || in_array($previousTag, array('@param', '@return', '@throws')) === true) + && (in_array($currentTag, ['@param', '@return', '@throws']) === true + || in_array($previousTag, ['@param', '@return', '@throws']) === true) && $previousTag !== $currentTag ) { $error = 'Separate the %s and %s sections by a blank line.'; - $fix = $phpcsFile->addFixableError($error, $tag, 'TagGroupSpacing', array($previousTag, $currentTag)); + $fix = $phpcsFile->addFixableError($error, $tag, 'TagGroupSpacing', [$previousTag, $currentTag]); if ($fix === true) { $phpcsFile->fixer->replaceToken(($tag - 1), "\n".str_repeat(' ', ($tokens[$tag]['column'] - 3)).'* '); } @@ -417,7 +417,7 @@ class DocCommentSniff implements Sniff foreach ($tagGroups as $group) { $maxLength = 0; - $paddings = array(); + $paddings = []; foreach ($group as $pos => $tag) { $tagLength = strlen($tokens[$tag]['content']); if ($tagLength > $maxLength) { @@ -436,7 +436,7 @@ class DocCommentSniff implements Sniff $lastTag = $group[$pos]; $next = $phpcsFile->findNext(T_DOC_COMMENT_TAG, ($lastTag + 3), $commentEnd); if ($next !== false) { - $prev = $phpcsFile->findPrevious(array(T_DOC_COMMENT_TAG, T_DOC_COMMENT_STRING), ($next - 1), $commentStart); + $prev = $phpcsFile->findPrevious([T_DOC_COMMENT_TAG, T_DOC_COMMENT_STRING], ($next - 1), $commentStart); if ($tokens[$next]['line'] !== ($tokens[$prev]['line'] + 2)) { $error = 'There must be a single blank line after a tag group'; $fix = $phpcsFile->addFixableError($error, $lastTag, 'SpacingAfterTagGroup'); @@ -461,7 +461,7 @@ class DocCommentSniff implements Sniff foreach ($paddings as $tag => $padding) { if ($padding !== 1) { $error = 'Tag value indented incorrectly; expected 1 space but found %s'; - $data = array($padding); + $data = [$padding]; $fix = $phpcsFile->addFixableError($error, ($tag + 1), 'TagValueIndent', $data); if ($fix === true) { @@ -474,7 +474,7 @@ class DocCommentSniff implements Sniff // If there is a param group, it needs to be first; with the exception of // @code, @todo and link tags. if ($paramGroupid !== null && $paramGroupid !== 0 - && in_array($tokens[$tokens[$commentStart]['comment_tags'][0]]['content'], array('@code', '@todo', '@link', '@endlink', '@codingStandardsIgnoreStart')) === false + && in_array($tokens[$tokens[$commentStart]['comment_tags'][0]]['content'], ['@code', '@todo', '@link', '@endlink', '@codingStandardsIgnoreStart']) === false // In JSDoc we can have many other valid tags like @function or // @constructor before the param tags. && $phpcsFile->tokenizerType !== 'JS' @@ -483,7 +483,7 @@ class DocCommentSniff implements Sniff $phpcsFile->addError($error, $tagGroups[$paramGroupid][0], 'ParamNotFirst'); } - $foundTags = array(); + $foundTags = []; foreach ($tokens[$stackPtr]['comment_tags'] as $pos => $tag) { $tagName = $tokens[$tag]['content']; if (isset($foundTags[$tagName]) === true) { diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentStarSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentStarSniff.php index f79108130ea586735def35dbed72b4c0747861b6..b3c99db0aaefdd6d477b9558043589b1d61aee05 100644 --- a/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentStarSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentStarSniff.php @@ -30,7 +30,7 @@ class DocCommentStarSniff implements Sniff */ public function register() { - return array(T_DOC_COMMENT_OPEN_TAG); + return [T_DOC_COMMENT_OPEN_TAG]; }//end register() diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/FileCommentSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/FileCommentSniff.php index 2fe5e944943fd544d26a4cbbdcdc89fdf772df78..3d8ef39c416f9248c2a9bcf21f27d982e2df513a 100644 --- a/coder_sniffer/Drupal/Sniffs/Commenting/FileCommentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Commenting/FileCommentSniff.php @@ -35,10 +35,10 @@ class FileCommentSniff implements Sniff * * @var array */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); + public $supportedTokenizers = [ + 'PHP', + 'JS', + ]; /** @@ -48,7 +48,7 @@ class FileCommentSniff implements Sniff */ public function register() { - return array(T_OPEN_TAG); + return [T_OPEN_TAG]; }//end register() @@ -189,8 +189,8 @@ class FileCommentSniff implements Sniff }//end if if ($fileTag === false || $tokens[$fileTag]['line'] !== ($tokens[$commentStart]['line'] + 1)) { - $second_line = $phpcsFile->findNext(array(T_DOC_COMMENT_STAR, T_DOC_COMMENT_CLOSE_TAG), ($commentStart + 1), $commentEnd); - $fix = $phpcsFile->addFixableError('The second line in the file doc comment must be "@file"', $second_line, 'FileTag'); + $secondLine = $phpcsFile->findNext([T_DOC_COMMENT_STAR, T_DOC_COMMENT_CLOSE_TAG], ($commentStart + 1), $commentEnd); + $fix = $phpcsFile->addFixableError('The second line in the file doc comment must be "@file"', $secondLine, 'FileTag'); if ($fix === true) { if ($fileTag === false) { $phpcsFile->fixer->addContent($commentStart, "\n * @file"); diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php index d92c8cb7cf95252f309e4c513b45f8195064cb41..55896ed4d80206089ad28b75fe12e602ccca32ba 100644 --- a/coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php @@ -29,38 +29,38 @@ class FunctionCommentSniff implements Sniff * * @var array */ - public static $invalidTypes = array( - 'Array' => 'array', - 'array()' => 'array', - '[]' => 'array', - 'boolean' => 'bool', - 'Boolean' => 'bool', - 'integer' => 'int', - 'str' => 'string', - 'stdClass' => 'object', - 'number' => 'int', - 'String' => 'string', - 'type' => 'mixed', - 'NULL' => 'null', - 'FALSE' => 'false', - 'TRUE' => 'true', - 'Bool' => 'bool', - 'Int' => 'int', - 'Integer' => 'int', - ); + public static $invalidTypes = [ + 'Array' => 'array', + 'array()' => 'array', + '[]' => 'array', + 'boolean' => 'bool', + 'Boolean' => 'bool', + 'integer' => 'int', + 'str' => 'string', + 'stdClass' => 'object', + 'number' => 'int', + 'String' => 'string', + 'type' => 'mixed', + 'NULL' => 'null', + 'FALSE' => 'false', + 'TRUE' => 'true', + 'Bool' => 'bool', + 'Int' => 'int', + 'Integer' => 'int', + ]; /** * An array of variable types for param/var we will check. * * @var array(string) */ - public $allowedTypes = array( - 'array', - 'mixed', - 'object', - 'resource', - 'callable', - ); + public $allowedTypes = [ + 'array', + 'mixed', + 'object', + 'resource', + 'callable', + ]; /** @@ -70,7 +70,7 @@ class FunctionCommentSniff implements Sniff */ public function register() { - return array(T_FUNCTION); + return [T_FUNCTION]; }//end register() @@ -221,7 +221,7 @@ class FunctionCommentSniff implements Sniff } else if (strpos($type, ' ') === false) { // Check return type (can be multiple, separated by '|'). $typeNames = explode('|', $type); - $suggestedNames = array(); + $suggestedNames = []; $hasNull = false; $hasMultiple = false; if (count($typeNames) > 0) { @@ -242,10 +242,10 @@ class FunctionCommentSniff implements Sniff $suggestedType = implode('|', $suggestedNames); if ($type !== $suggestedType) { $error = 'Expected "%s" but found "%s" for function return type'; - $data = array( - $suggestedType, - $type, - ); + $data = [ + $suggestedType, + $type, + ]; $fix = $phpcsFile->addFixableError($error, $return, 'InvalidReturn', $data); if ($fix === true) { $content = $suggestedType; @@ -265,7 +265,7 @@ class FunctionCommentSniff implements Sniff $searchStart = $stackPtr; $foundNonVoidReturn = false; do { - $returnToken = $phpcsFile->findNext(array(T_RETURN, T_YIELD), $searchStart, $endToken); + $returnToken = $phpcsFile->findNext([T_RETURN, T_YIELD], $searchStart, $endToken); if ($returnToken === false && $foundReturnToken === false) { $error = '@return doc comment specified, but function has no return statement'; $phpcsFile->addError($error, $return, 'InvalidNoReturn'); @@ -308,14 +308,14 @@ class FunctionCommentSniff implements Sniff } $comment .= ' '.$tokens[$i]['content']; - $commentLines[] = array( - 'comment' => $tokens[$i]['content'], - 'token' => $i, - 'indent' => $indent, - ); + $commentLines[] = [ + 'comment' => $tokens[$i]['content'], + 'token' => $i, + 'indent' => $indent, + ]; if ($indent < 3) { $error = 'Return comment indentation must be 3 spaces, found %s spaces'; - $fix = $phpcsFile->addFixableError($error, $i, 'ReturnCommentIndentation', array($indent)); + $fix = $phpcsFile->addFixableError($error, $i, 'ReturnCommentIndentation', [$indent]); if ($fix === true) { $phpcsFile->fixer->replaceToken(($i - 1), ' '); } @@ -328,7 +328,7 @@ class FunctionCommentSniff implements Sniff // line. if (empty($commentLines[0]['indent']) === false && $commentLines[0]['indent'] > 3) { $error = 'Return comment indentation must be 3 spaces, found %s spaces'; - $fix = $phpcsFile->addFixableError($error, ($commentLines[0]['token'] - 1), 'ReturnCommentIndentation', array($commentLines[0]['indent'])); + $fix = $phpcsFile->addFixableError($error, ($commentLines[0]['token'] - 1), 'ReturnCommentIndentation', [$commentLines[0]['indent']]); if ($fix === true) { $phpcsFile->fixer->replaceToken(($commentLines[0]['token'] - 1), ' '); } @@ -345,14 +345,14 @@ class FunctionCommentSniff implements Sniff } else if (strpos($type, ' ') !== false) { if (preg_match('/^([^\s]+)[\s]+(\$[^\s]+)[\s]*$/', $type, $matches) === 1) { $error = 'Return type must not contain variable name "%s"'; - $data = array($matches[2]); + $data = [$matches[2]]; $fix = $phpcsFile->addFixableError($error, ($return + 2), 'ReturnVarName', $data); if ($fix === true) { $phpcsFile->fixer->replaceToken(($return + 2), $matches[1]); } } else { $error = 'Return type "%s" must not contain spaces'; - $data = array($type); + $data = [$type]; $phpcsFile->addError($error, $return, 'ReturnTypeSpaces', $data); } }//end if @@ -414,7 +414,7 @@ class FunctionCommentSniff implements Sniff $comment .= ' '.$tokens[$i]['content']; if ($indent < 3) { $error = 'Throws comment indentation must be 3 spaces, found %s spaces'; - $phpcsFile->addError($error, $i, 'TrhowsCommentIndentation', array($indent)); + $phpcsFile->addError($error, $i, 'TrhowsCommentIndentation', [$indent]); } } } @@ -438,7 +438,7 @@ class FunctionCommentSniff implements Sniff } $lastChar = substr($comment, -1); - if (in_array($lastChar, array('.', '!', '?')) === false) { + if (in_array($lastChar, ['.', '!', '?']) === false) { $error = '@throws tag comment must end with a full stop'; $phpcsFile->addError($error, $throwStart, 'ThrowsNoFullStop'); } @@ -462,7 +462,7 @@ class FunctionCommentSniff implements Sniff { $tokens = $phpcsFile->getTokens(); - $params = array(); + $params = []; $maxType = 0; $maxVar = 0; foreach ($tokens[$commentStart]['comment_tags'] as $pos => $tag) { @@ -475,9 +475,9 @@ class FunctionCommentSniff implements Sniff $var = ''; $varSpace = 0; $comment = ''; - $commentLines = array(); + $commentLines = []; if ($tokens[($tag + 2)]['code'] === T_DOC_COMMENT_STRING) { - $matches = array(); + $matches = []; preg_match('/([^$&]*)(?:((?:\$|&)[^\s]+)(?:(\s+)(.*))?)?/', $tokens[($tag + 2)]['content'], $matches); $typeLen = strlen($matches[1]); @@ -543,14 +543,14 @@ class FunctionCommentSniff implements Sniff } $comment .= ' '.$tokens[$i]['content']; - $commentLines[] = array( - 'comment' => $tokens[$i]['content'], - 'token' => $i, - 'indent' => $indent, - ); + $commentLines[] = [ + 'comment' => $tokens[$i]['content'], + 'token' => $i, + 'indent' => $indent, + ]; if ($indent < 3) { $error = 'Parameter comment indentation must be 3 spaces, found %s spaces'; - $fix = $phpcsFile->addFixableError($error, $i, 'ParamCommentIndentation', array($indent)); + $fix = $phpcsFile->addFixableError($error, $i, 'ParamCommentIndentation', [$indent]); if ($fix === true) { $phpcsFile->fixer->replaceToken(($i - 1), ' '); } @@ -563,7 +563,7 @@ class FunctionCommentSniff implements Sniff // line. if (empty($commentLines[0]['indent']) === false && $commentLines[0]['indent'] > 3) { $error = 'Parameter comment indentation must be 3 spaces, found %s spaces'; - $fix = $phpcsFile->addFixableError($error, ($commentLines[0]['token'] - 1), 'ParamCommentIndentation', array($commentLines[0]['indent'])); + $fix = $phpcsFile->addFixableError($error, ($commentLines[0]['token'] - 1), 'ParamCommentIndentation', [$commentLines[0]['indent']]); if ($fix === true) { $phpcsFile->fixer->replaceToken(($commentLines[0]['token'] - 1), ' '); } @@ -572,7 +572,7 @@ class FunctionCommentSniff implements Sniff if ($comment === '') { $error = 'Missing parameter comment'; $phpcsFile->addError($error, $tag, 'MissingParamComment'); - $commentLines[] = array('comment' => ''); + $commentLines[] = ['comment' => '']; }//end if $variableArguments = false; @@ -610,19 +610,19 @@ class FunctionCommentSniff implements Sniff $phpcsFile->addError($error, $tag, 'MissingParamType'); }//end if - $params[] = array( - 'tag' => $tag, - 'type' => $type, - 'var' => $var, - 'comment' => $comment, - 'commentLines' => $commentLines, - 'type_space' => $typeSpace, - 'var_space' => $varSpace, - ); + $params[] = [ + 'tag' => $tag, + 'type' => $type, + 'var' => $var, + 'comment' => $comment, + 'commentLines' => $commentLines, + 'type_space' => $typeSpace, + 'var_space' => $varSpace, + ]; }//end foreach $realParams = $phpcsFile->getMethodParameters($stackPtr); - $foundParams = array(); + $foundParams = []; $checkPos = 0; foreach ($params as $pos => $param) { @@ -658,7 +658,7 @@ class FunctionCommentSniff implements Sniff // Check the param type value. This could also be multiple parameter // types separated by '|'. $typeNames = explode('|', $param['type']); - $suggestedNames = array(); + $suggestedNames = []; foreach ($typeNames as $i => $typeName) { $suggestedNames[] = static::suggestType($typeName); } @@ -666,14 +666,14 @@ class FunctionCommentSniff implements Sniff $suggestedType = implode('|', $suggestedNames); if (preg_match('/\s/', $param['type']) === 1) { $error = 'Parameter type "%s" must not contain spaces'; - $data = array($param['type']); + $data = [$param['type']]; $phpcsFile->addError($error, $param['tag'], 'ParamTypeSpaces', $data); } else if ($param['type'] !== $suggestedType) { $error = 'Expected "%s" but found "%s" for parameter type'; - $data = array( - $suggestedType, - $param['type'], - ); + $data = [ + $suggestedType, + $param['type'], + ]; $fix = $phpcsFile->addFixableError($error, $param['tag'], 'IncorrectParamVarName', $data); if ($fix === true) { $content = $suggestedType; @@ -710,23 +710,23 @@ class FunctionCommentSniff implements Sniff // Primitive type hints are allowed to be omitted. if ($typeHint === '' && in_array($suggestedTypeHint, ['string', 'int', 'float', 'bool']) === false) { $error = 'Type hint "%s" missing for %s'; - $data = array( - $suggestedTypeHint, - $param['var'], - ); + $data = [ + $suggestedTypeHint, + $param['var'], + ]; $phpcsFile->addError($error, $stackPtr, 'TypeHintMissing', $data); } else if ($typeHint !== $suggestedTypeHint && $typeHint !== '') { // The type hint could be fully namespaced, so we check // for the part after the last "\". - $name_parts = explode('\\', $suggestedTypeHint); - $last_part = end($name_parts); - if ($last_part !== $typeHint && $this->isAliasedType($typeHint, $suggestedTypeHint, $phpcsFile) === false) { + $nameParts = explode('\\', $suggestedTypeHint); + $lastPart = end($nameParts); + if ($lastPart !== $typeHint && $this->isAliasedType($typeHint, $suggestedTypeHint, $phpcsFile) === false) { $error = 'Expected type hint "%s"; found "%s" for %s'; - $data = array( - $last_part, - $typeHint, - $param['var'], - ); + $data = [ + $lastPart, + $typeHint, + $param['var'], + ]; $phpcsFile->addError($error, $stackPtr, 'IncorrectTypeHint', $data); } }//end if @@ -736,10 +736,10 @@ class FunctionCommentSniff implements Sniff $typeHint = $realParams[$checkPos]['type_hint']; if ($typeHint !== '' && $typeHint !== 'stdClass') { $error = 'Unknown type hint "%s" found for %s'; - $data = array( - $typeHint, - $param['var'], - ); + $data = [ + $typeHint, + $param['var'], + ]; $phpcsFile->addError($error, $stackPtr, 'InvalidTypeHint', $data); } }//end if @@ -749,10 +749,10 @@ class FunctionCommentSniff implements Sniff $spaces = 1; if ($param['type_space'] !== $spaces) { $error = 'Expected %s spaces after parameter type; %s found'; - $data = array( - $spaces, - $param['type_space'], - ); + $data = [ + $spaces, + $param['type_space'], + ]; $fix = $phpcsFile->addFixableError($error, $param['tag'], 'SpacingAfterParamType', $data); if ($fix === true) { @@ -788,10 +788,10 @@ class FunctionCommentSniff implements Sniff if ($matched === false) { if ($checkPos >= $pos) { $code = 'ParamNameNoMatch'; - $data = array( - $param['var'], - $realName, - ); + $data = [ + $param['var'], + $realName, + ]; $error = 'Doc comment for parameter %s does not match '; if (strtolower($param['var']) === strtolower($realName)) { @@ -837,7 +837,7 @@ class FunctionCommentSniff implements Sniff } $lastChar = substr($param['comment'], -1); - if (in_array($lastChar, array('.', '!', '?', ')')) === false) { + if (in_array($lastChar, ['.', '!', '?', ')']) === false) { $error = 'Parameter comment must end with a full stop'; if (empty($param['commentLines']) === true) { $commentToken = ($param['tag'] + 2); @@ -979,7 +979,7 @@ class FunctionCommentSniff implements Sniff } $originalClassName = ''; - while (in_array($tokens[$originalClass]['code'], array(T_STRING, T_NS_SEPARATOR)) === true) { + while (in_array($tokens[$originalClass]['code'], [T_STRING, T_NS_SEPARATOR]) === true) { $originalClassName .= $tokens[$originalClass]['content']; $originalClass++; } diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/GenderNeutralCommentSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/GenderNeutralCommentSniff.php index dc63445a7c6d55f6abf897f332c5501fccb100f2..324ada5a8c008eda4363325c82d6d243a66c1897 100644 --- a/coder_sniffer/Drupal/Sniffs/Commenting/GenderNeutralCommentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Commenting/GenderNeutralCommentSniff.php @@ -30,10 +30,10 @@ class GenderNeutralCommentSniff implements Sniff */ public function register() { - return array( - T_COMMENT, - T_DOC_COMMENT_STRING, - ); + return [ + T_COMMENT, + T_DOC_COMMENT_STRING, + ]; }//end register() diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/HookCommentSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/HookCommentSniff.php index cbfa51dddc66d4e07a5c7db000567122690f0778..434be4aa5ce9bd7a0a8ccacbfea1b1dcdcc60e80 100644 --- a/coder_sniffer/Drupal/Sniffs/Commenting/HookCommentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Commenting/HookCommentSniff.php @@ -31,7 +31,7 @@ class HookCommentSniff implements Sniff */ public function register() { - return array(T_FUNCTION); + return [T_FUNCTION]; }//end register() @@ -64,10 +64,10 @@ class HookCommentSniff implements Sniff $commentStart = $tokens[$commentEnd]['comment_opener']; - $empty = array( - T_DOC_COMMENT_WHITESPACE, - T_DOC_COMMENT_STAR, - ); + $empty = [ + T_DOC_COMMENT_WHITESPACE, + T_DOC_COMMENT_STAR, + ]; $short = $phpcsFile->findNext($empty, ($commentStart + 1), $commentEnd, true); if ($short === false) { diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/InlineCommentSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/InlineCommentSniff.php index cbdfc708bdd415b5692be03a6ba37aa396ccb4f1..0bd69eb992aa90523aa46ef4da45b9c13e01b4a1 100644 --- a/coder_sniffer/Drupal/Sniffs/Commenting/InlineCommentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Commenting/InlineCommentSniff.php @@ -33,10 +33,10 @@ class InlineCommentSniff implements Sniff * * @var array */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); + public $supportedTokenizers = [ + 'PHP', + 'JS', + ]; /** @@ -46,10 +46,10 @@ class InlineCommentSniff implements Sniff */ public function register() { - return array( - T_COMMENT, - T_DOC_COMMENT_OPEN_TAG, - ); + return [ + T_COMMENT, + T_DOC_COMMENT_OPEN_TAG, + ]; }//end register() @@ -78,22 +78,22 @@ class InlineCommentSniff implements Sniff true ); - $ignore = array( - T_CLASS, - T_INTERFACE, - T_TRAIT, - T_FUNCTION, - T_CLOSURE, - T_PUBLIC, - T_PRIVATE, - T_PROTECTED, - T_FINAL, - T_STATIC, - T_ABSTRACT, - T_CONST, - T_PROPERTY, - T_VAR, - ); + $ignore = [ + T_CLASS, + T_INTERFACE, + T_TRAIT, + T_FUNCTION, + T_CLOSURE, + T_PUBLIC, + T_PRIVATE, + T_PROTECTED, + T_FINAL, + T_STATIC, + T_ABSTRACT, + T_CONST, + T_PROPERTY, + T_VAR, + ]; // Also ignore all doc blocks defined in the outer scope (no scope // conditions are set). @@ -195,7 +195,7 @@ class InlineCommentSniff implements Sniff // The below section determines if a comment block is correctly capitalised, // and ends in a full-stop. It will find the last comment in a block, and // work its way up. - $nextComment = $phpcsFile->findNext(array(T_COMMENT), ($stackPtr + 1), null, false); + $nextComment = $phpcsFile->findNext([T_COMMENT], ($stackPtr + 1), null, false); if (($nextComment !== false) && (($tokens[$nextComment]['line']) === ($tokens[$stackPtr]['line'] + 1)) // A tag such as @todo means a separate comment block. @@ -206,7 +206,7 @@ class InlineCommentSniff implements Sniff $topComment = $stackPtr; $lastComment = $stackPtr; - while (($topComment = $phpcsFile->findPrevious(array(T_COMMENT), ($lastComment - 1), null, false)) !== false) { + while (($topComment = $phpcsFile->findPrevious([T_COMMENT], ($lastComment - 1), null, false)) !== false) { if ($tokens[$topComment]['line'] !== ($tokens[$lastComment]['line'] - 1)) { break; } @@ -237,7 +237,7 @@ class InlineCommentSniff implements Sniff if (preg_match('|\p{Lu}|u', $commentText[0]) === 0 && $commentText[0] !== '@') { // Allow special lower cased words that contain non-alpha characters // (function references, machine names with underscores etc.). - $matches = array(); + $matches = []; preg_match('/[a-z]+/', $words[0], $matches); if (isset($matches[0]) === true && $matches[0] === $words[0]) { $error = 'Inline comments must start with a capital letter'; @@ -250,20 +250,20 @@ class InlineCommentSniff implements Sniff } $commentCloser = $commentText[(strlen($commentText) - 1)]; - $acceptedClosers = array( - 'full-stops' => '.', - 'exclamation marks' => '!', - 'colons' => ':', - 'question marks' => '?', - 'or closing parentheses' => ')', - ); + $acceptedClosers = [ + 'full-stops' => '.', + 'exclamation marks' => '!', + 'colons' => ':', + 'question marks' => '?', + 'or closing parentheses' => ')', + ]; // Allow @tag style comments without punctuation. if (in_array($commentCloser, $acceptedClosers) === false && $commentText[0] !== '@') { // Allow special last words like URLs or function references // without punctuation. $lastWord = $words[(count($words) - 1)]; - $matches = array(); + $matches = []; preg_match('/https?:\/\/.+/', $lastWord, $matches); $isUrl = isset($matches[0]) === true; preg_match('/[$a-zA-Z_]+\([$a-zA-Z_]*\)/', $lastWord, $matches); @@ -280,7 +280,7 @@ class InlineCommentSniff implements Sniff } $ender = trim($ender, ' ,'); - $data = array($ender); + $data = [$ender]; $fix = $phpcsFile->addFixableError($error, $stackPtr, 'InvalidEndChar', $data); if ($fix === true) { $newContent = preg_replace('/(\s+)$/', '.$1', $tokens[$stackPtr]['content']); @@ -341,7 +341,7 @@ class InlineCommentSniff implements Sniff $tokens = $phpcsFile->getTokens(); $prevComment = $stackPtr; $lastComment = $stackPtr; - while (($prevComment = $phpcsFile->findPrevious(array(T_COMMENT), ($lastComment - 1), null, false)) !== false) { + while (($prevComment = $phpcsFile->findPrevious([T_COMMENT], ($lastComment - 1), null, false)) !== false) { if ($tokens[$prevComment]['line'] !== ($tokens[$lastComment]['line'] - 1)) { return false; } @@ -395,17 +395,17 @@ class InlineCommentSniff implements Sniff $fix = false; if ($tabFound === true) { $error = 'Tab found before comment text; expected "// %s" but found "%s"'; - $data = array( - ltrim(substr($comment, 2)), - $comment, - ); + $data = [ + ltrim(substr($comment, 2)), + $comment, + ]; $fix = $phpcsFile->addFixableError($error, $stackPtr, 'TabBefore', $data); } else if ($spaceCount === 0 && strlen($comment) > 2) { $error = 'No space found before comment text; expected "// %s" but found "%s"'; - $data = array( - substr($comment, 2), - $comment, - ); + $data = [ + substr($comment, 2), + $comment, + ]; $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NoSpaceBefore', $data); }//end if @@ -417,7 +417,7 @@ class InlineCommentSniff implements Sniff if ($spaceCount > 1) { // Check if there is a comment on the previous line that justifies the // indentation. - $prevComment = $phpcsFile->findPrevious(array(T_COMMENT), ($stackPtr - 1), null, false); + $prevComment = $phpcsFile->findPrevious([T_COMMENT], ($stackPtr - 1), null, false); if (($prevComment !== false) && (($tokens[$prevComment]['line']) === ($tokens[$stackPtr]['line'] - 1))) { $prevCommentText = rtrim($tokens[$prevComment]['content']); $prevSpaceCount = 0; @@ -431,16 +431,16 @@ class InlineCommentSniff implements Sniff if ($spaceCount > $prevSpaceCount && $prevSpaceCount > 0) { // A previous comment could be a list item or @todo. - $indentationStarters = array( - '-', - '@todo', - ); + $indentationStarters = [ + '-', + '@todo', + ]; $words = preg_split('/\s+/', $prevCommentText); $numberedList = (bool) preg_match('/^[0-9]+\./', $words[1]); if (in_array($words[1], $indentationStarters) === true) { if ($spaceCount !== ($prevSpaceCount + 2)) { $error = 'Comment indentation error after %s element, expected %s spaces'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingBefore', array($words[1], $prevSpaceCount + 2)); + $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingBefore', [$words[1], ($prevSpaceCount + 2)]); if ($fix === true) { $newComment = '//'.str_repeat(' ', ($prevSpaceCount + 2)).ltrim($tokens[$stackPtr]['content'], "/\t "); $phpcsFile->fixer->replaceToken($stackPtr, $newComment); @@ -450,7 +450,7 @@ class InlineCommentSniff implements Sniff $expectedSpaceCount = ($prevSpaceCount + strlen($words[1]) + 1); if ($spaceCount !== $expectedSpaceCount) { $error = 'Comment indentation error, expected %s spaces'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingBefore', array($expectedSpaceCount)); + $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingBefore', [$expectedSpaceCount]); if ($fix === true) { $newComment = '//'.str_repeat(' ', $expectedSpaceCount).ltrim($tokens[$stackPtr]['content'], "/\t "); $phpcsFile->fixer->replaceToken($stackPtr, $newComment); @@ -458,16 +458,16 @@ class InlineCommentSniff implements Sniff } } else { $error = 'Comment indentation error, expected only %s spaces'; - $phpcsFile->addError($error, $stackPtr, 'SpacingBefore', array($prevSpaceCount)); + $phpcsFile->addError($error, $stackPtr, 'SpacingBefore', [$prevSpaceCount]); }//end if }//end if } else { $error = '%s spaces found before inline comment; expected "// %s" but found "%s"'; - $data = array( - $spaceCount, - substr($comment, (2 + $spaceCount)), - $comment, - ); + $data = [ + $spaceCount, + substr($comment, (2 + $spaceCount)), + $comment, + ]; $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingBefore', $data); if ($fix === true) { $phpcsFile->fixer->replaceToken($stackPtr, '// '.substr($comment, (2 + $spaceCount)).$phpcsFile->eolChar); diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/PostStatementCommentSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/PostStatementCommentSniff.php index 57b2091d746215cc5ca140e2264c775248fc7789..ea16f665dbbd7563a9a1be6c4bb16c4d72f92733 100644 --- a/coder_sniffer/Drupal/Sniffs/Commenting/PostStatementCommentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Commenting/PostStatementCommentSniff.php @@ -29,7 +29,7 @@ class PostStatementCommentSniff implements Sniff * * @var array */ - public $supportedTokenizers = array('PHP'); + public $supportedTokenizers = ['PHP']; /** @@ -39,7 +39,7 @@ class PostStatementCommentSniff implements Sniff */ public function register() { - return array(T_COMMENT); + return [T_COMMENT]; }//end register() diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/VariableCommentSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/VariableCommentSniff.php index 9649f5b22653e6a532d2f89275d20d1f69d88e61..c8a6d2761bd576af2bbe4c1c642813ed0782a1d9 100644 --- a/coder_sniffer/Drupal/Sniffs/Commenting/VariableCommentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Commenting/VariableCommentSniff.php @@ -40,10 +40,10 @@ class VariableCommentSniff extends AbstractVariableSniff public function processMemberVar(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); - $commentToken = array( - T_COMMENT, - T_DOC_COMMENT_CLOSE_TAG, - ); + $commentToken = [ + T_COMMENT, + T_DOC_COMMENT_CLOSE_TAG, + ]; $commentEnd = $phpcsFile->findPrevious($commentToken, $stackPtr); if ($commentEnd === false) { @@ -70,7 +70,7 @@ class VariableCommentSniff extends AbstractVariableSniff return; } else { // Make sure the comment we have found belongs to us. - $commentFor = $phpcsFile->findNext(array(T_VARIABLE, T_CLASS, T_INTERFACE), ($commentEnd + 1)); + $commentFor = $phpcsFile->findNext([T_VARIABLE, T_CLASS, T_INTERFACE], ($commentEnd + 1)); if ($commentFor !== $stackPtr) { return; } @@ -126,7 +126,7 @@ class VariableCommentSniff extends AbstractVariableSniff $varType = $tokens[($foundVar + 2)]['content']; // There may be multiple types separated by pipes. - $suggestedTypes = array(); + $suggestedTypes = []; foreach (explode('|', $varType) as $type) { $suggestedTypes[] = FunctionCommentSniff::suggestType($type); } @@ -135,22 +135,22 @@ class VariableCommentSniff extends AbstractVariableSniff // Detect and auto-fix the common mistake that the variable name is // appended to the type declaration. - $matches = array(); + $matches = []; if (preg_match('/^([^\s]+)(\s+\$.+)$/', $varType, $matches) === 1) { $error = 'Do not append variable name "%s" to the type declaration in a member variable comment'; - $data = array( - trim($matches[2]), - ); + $data = [ + trim($matches[2]), + ]; $fix = $phpcsFile->addFixableError($error, ($foundVar + 2), 'InlineVariableName', $data); if ($fix === true) { $phpcsFile->fixer->replaceToken(($foundVar + 2), $matches[1]); } } else if ($varType !== $suggestedType) { $error = 'Expected "%s" but found "%s" for @var tag in member variable comment'; - $data = array( - $suggestedType, - $varType, - ); + $data = [ + $suggestedType, + $varType, + ]; $fix = $phpcsFile->addFixableError($error, ($foundVar + 2), 'IncorrectVarType', $data); if ($fix === true) { $phpcsFile->fixer->replaceToken(($foundVar + 2), $suggestedType); diff --git a/coder_sniffer/Drupal/Sniffs/ControlStructures/ControlSignatureSniff.php b/coder_sniffer/Drupal/Sniffs/ControlStructures/ControlSignatureSniff.php index ab74cdbeb2e620e2c55443ee88412124a0704631..8b651727863c4d9be19b7e9be0f6d806cdb8a516 100644 --- a/coder_sniffer/Drupal/Sniffs/ControlStructures/ControlSignatureSniff.php +++ b/coder_sniffer/Drupal/Sniffs/ControlStructures/ControlSignatureSniff.php @@ -32,10 +32,10 @@ class ControlSignatureSniff implements Sniff * * @var array */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); + public $supportedTokenizers = [ + 'PHP', + 'JS', + ]; /** @@ -45,18 +45,18 @@ class ControlSignatureSniff implements Sniff */ public function register() { - return array( - T_TRY, - T_CATCH, - T_DO, - T_WHILE, - T_FOR, - T_IF, - T_FOREACH, - T_ELSE, - T_ELSEIF, - T_SWITCH, - ); + return [ + T_TRY, + T_CATCH, + T_DO, + T_WHILE, + T_FOR, + T_IF, + T_FOREACH, + T_ELSE, + T_ELSEIF, + T_SWITCH, + ]; }//end register() @@ -92,10 +92,10 @@ class ControlSignatureSniff implements Sniff if ($found !== 1) { $error = 'Expected 1 space after %s keyword; %s found'; - $data = array( - strtoupper($tokens[$stackPtr]['content']), - $found, - ); + $data = [ + strtoupper($tokens[$stackPtr]['content']), + $found, + ]; $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceAfterKeyword', $data); if ($fix === true) { @@ -123,7 +123,7 @@ class ControlSignatureSniff implements Sniff $found = '"'.str_replace($phpcsFile->eolChar, '\n', $content).'"'; } - $fix = $phpcsFile->addFixableError($error, $closer, 'SpaceAfterCloseParenthesis', array($found)); + $fix = $phpcsFile->addFixableError($error, $closer, 'SpaceAfterCloseParenthesis', [$found]); if ($fix === true) { if ($closer === ($opener - 1)) { $phpcsFile->fixer->addContent($closer, ' '); @@ -205,7 +205,7 @@ class ControlSignatureSniff implements Sniff if ($found !== 0) { $error = 'Expected 0 spaces before semicolon; %s found'; - $data = array($found); + $data = [$found]; $fix = $phpcsFile->addFixableError($error, $closer, 'SpaceBeforeSemicolon', $data); if ($fix === true) { $phpcsFile->fixer->replaceToken(($closer + 1), ''); @@ -278,7 +278,7 @@ class ControlSignatureSniff implements Sniff if ($found !== 1) { $error = 'Expected 1 space after closing brace; %s found'; - $data = array($found); + $data = [$found]; $fix = $phpcsFile->addFixableError($error, $closer, 'SpaceAfterCloseBrace', $data); if ($fix === true) { if ($found === 0) { diff --git a/coder_sniffer/Drupal/Sniffs/ControlStructures/ElseIfSniff.php b/coder_sniffer/Drupal/Sniffs/ControlStructures/ElseIfSniff.php index aabc01676bd9f0f00eb889e1458ec16f0777a479..6455a070dec84594e17a25ad9a79f097615d8ea0 100644 --- a/coder_sniffer/Drupal/Sniffs/ControlStructures/ElseIfSniff.php +++ b/coder_sniffer/Drupal/Sniffs/ControlStructures/ElseIfSniff.php @@ -30,7 +30,7 @@ class ElseIfSniff implements Sniff */ public function register() { - return array(T_ELSE); + return [T_ELSE]; }//end register() diff --git a/coder_sniffer/Drupal/Sniffs/Files/EndFileNewlineSniff.php b/coder_sniffer/Drupal/Sniffs/Files/EndFileNewlineSniff.php index d829cda3e425835a7e8bd5d7e0fd577e8335b865..0b308e4ca2a9f152fe0c6cf6a6bf7a0a8d3eab94 100644 --- a/coder_sniffer/Drupal/Sniffs/Files/EndFileNewlineSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Files/EndFileNewlineSniff.php @@ -31,11 +31,11 @@ class EndFileNewlineSniff implements Sniff * * @var array */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - 'CSS', - ); + public $supportedTokenizers = [ + 'PHP', + 'JS', + 'CSS', + ]; /** @@ -45,10 +45,10 @@ class EndFileNewlineSniff implements Sniff */ public function register() { - return array( - T_OPEN_TAG, - T_INLINE_HTML, - ); + return [ + T_OPEN_TAG, + T_INLINE_HTML, + ]; }//end register() @@ -106,7 +106,7 @@ class EndFileNewlineSniff implements Sniff if ($blankLines > 1) { $error = 'Expected 1 newline at end of file; %s found'; - $data = array($blankLines); + $data = [$blankLines]; $fix = $phpcsFile->addFixableError($error, $lastCode, 'TooMany', $data); if ($fix === true) { diff --git a/coder_sniffer/Drupal/Sniffs/Files/FileEncodingSniff.php b/coder_sniffer/Drupal/Sniffs/Files/FileEncodingSniff.php index 26a08da1a905d53342f69ba0535982b38dcc1680..0e8b712a2c61075ce3d9333b05ac6150c63e4f08 100644 --- a/coder_sniffer/Drupal/Sniffs/Files/FileEncodingSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Files/FileEncodingSniff.php @@ -38,7 +38,7 @@ class FileEncodingSniff implements Sniff * * @var array */ - public $allowedEncodings = array('UTF-8'); + public $allowedEncodings = ['UTF-8']; /** @@ -48,10 +48,10 @@ class FileEncodingSniff implements Sniff */ public function register() { - return array( - T_INLINE_HTML, - T_OPEN_TAG, - ); + return [ + T_INLINE_HTML, + T_OPEN_TAG, + ]; }//end register() @@ -83,7 +83,7 @@ class FileEncodingSniff implements Sniff if ($validEncodingFound === false) { $warning = 'File encoding is invalid, expected %s'; - $data = array(implode(' or ', $this->allowedEncodings)); + $data = [implode(' or ', $this->allowedEncodings)]; $phpcsFile->addWarning($warning, $stackPtr, 'InvalidEncoding', $data); } diff --git a/coder_sniffer/Drupal/Sniffs/Files/LineLengthSniff.php b/coder_sniffer/Drupal/Sniffs/Files/LineLengthSniff.php index 90abba08a65bb24224bf727dd21677b763986d72..4584088363ea65e2559fbbd848a274a503e9b065 100644 --- a/coder_sniffer/Drupal/Sniffs/Files/LineLengthSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Files/LineLengthSniff.php @@ -27,7 +27,7 @@ class LineLengthSniff extends GenericLineLengthSniff /** * The limit that the length of a line should not exceed. * - * @var int + * @var integer */ public $lineLimit = 80; @@ -37,7 +37,7 @@ class LineLengthSniff extends GenericLineLengthSniff * * Set to zero (0) to disable. * - * @var int + * @var integer */ public $absoluteLineLimit = 0; @@ -54,8 +54,8 @@ class LineLengthSniff extends GenericLineLengthSniff protected function checkLineLength($phpcsFile, $tokens, $stackPtr) { if (isset(Tokens::$commentTokens[$tokens[($stackPtr - 1)]['code']]) === true) { - $doc_comment_tag = $phpcsFile->findFirstOnLine(T_DOC_COMMENT_TAG, ($stackPtr - 1)); - if ($doc_comment_tag !== false) { + $docCommentTag = $phpcsFile->findFirstOnLine(T_DOC_COMMENT_TAG, ($stackPtr - 1)); + if ($docCommentTag !== false) { // Allow doc comment tags such as long @param tags to exceed the 80 // character limit. return; @@ -75,7 +75,7 @@ class LineLengthSniff extends GenericLineLengthSniff // Code examples between @code and @endcode are allowed to exceed 80 // characters. if (isset($tokens[$stackPtr]) === true && $tokens[$stackPtr]['code'] === T_DOC_COMMENT_WHITESPACE) { - $tag = $phpcsFile->findPrevious(array(T_DOC_COMMENT_TAG, T_DOC_COMMENT_OPEN_TAG), ($stackPtr - 1)); + $tag = $phpcsFile->findPrevious([T_DOC_COMMENT_TAG, T_DOC_COMMENT_OPEN_TAG], ($stackPtr - 1)); if ($tokens[$tag]['content'] === '@code') { return; } diff --git a/coder_sniffer/Drupal/Sniffs/Files/TxtFileLineLengthSniff.php b/coder_sniffer/Drupal/Sniffs/Files/TxtFileLineLengthSniff.php index 803a9e011ed0fb4e0c3247da5cb745157701e8ba..46ef960c2beda3c411c45afb9cc4386e5044ebeb 100644 --- a/coder_sniffer/Drupal/Sniffs/Files/TxtFileLineLengthSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Files/TxtFileLineLengthSniff.php @@ -33,7 +33,7 @@ class TxtFileLineLengthSniff implements Sniff */ public function register() { - return array(T_INLINE_HTML); + return [T_INLINE_HTML]; }//end register() @@ -62,10 +62,10 @@ class TxtFileLineLengthSniff implements Sniff // - containing URLs (https://) // - starting with | (tables). if ($lineLength > 80 && preg_match('/^([^ ]+$|#|.*https?:\/\/|\|)/', $content) === 0) { - $data = array( - 80, - $lineLength, - ); + $data = [ + 80, + $lineLength, + ]; $warning = 'Line exceeds %s characters; contains %s characters'; $phpcsFile->addWarning($warning, $stackPtr, 'TooLong', $data); } diff --git a/coder_sniffer/Drupal/Sniffs/Formatting/MultiLineAssignmentSniff.php b/coder_sniffer/Drupal/Sniffs/Formatting/MultiLineAssignmentSniff.php index 4b5c1c9154c601bfa2394e09e6c7b1ac1329ff2b..0ad7c73c2042c72befda4411502c8cdd5ebdd623 100644 --- a/coder_sniffer/Drupal/Sniffs/Formatting/MultiLineAssignmentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Formatting/MultiLineAssignmentSniff.php @@ -36,7 +36,7 @@ class MultiLineAssignmentSniff implements Sniff */ public function register() { - return array(T_EQUAL); + return [T_EQUAL]; }//end register() diff --git a/coder_sniffer/Drupal/Sniffs/Formatting/MultipleStatementAlignmentSniff.php b/coder_sniffer/Drupal/Sniffs/Formatting/MultipleStatementAlignmentSniff.php index c54cfe8ff851a9909ff918a2a8276a7d54982259..ecdf2cad4b7e31458a8cfce8aa80397fa060adb8 100644 --- a/coder_sniffer/Drupal/Sniffs/Formatting/MultipleStatementAlignmentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Formatting/MultipleStatementAlignmentSniff.php @@ -29,7 +29,7 @@ class MultipleStatementAlignmentSniff extends GenericMultipleStatementAlignmentS /** * If true, an error will be thrown; otherwise a warning. * - * @var bool + * @var boolean */ public $error = true; @@ -49,7 +49,7 @@ class MultipleStatementAlignmentSniff extends GenericMultipleStatementAlignmentS { $tokens = $phpcsFile->getTokens(); - $assignments = array(); + $assignments = []; $prevAssign = null; $lastLine = $tokens[$stackPtr]['line']; $maxPadding = null; @@ -176,13 +176,13 @@ class MultipleStatementAlignmentSniff extends GenericMultipleStatementAlignmentS } } - $assignments[$assign] = array( - 'var_end' => $varEnd, - 'assign_len' => $assignLen, - 'assign_col' => $assignColumn, - 'expected' => $padding, - 'found' => $found, - ); + $assignments[$assign] = [ + 'var_end' => $varEnd, + 'assign_len' => $assignLen, + 'assign_col' => $assignColumn, + 'expected' => $padding, + 'found' => $found, + ]; $lastLine = $tokens[$assign]['line']; $prevAssign = $assign; @@ -242,10 +242,10 @@ class MultipleStatementAlignmentSniff extends GenericMultipleStatementAlignmentS $error = 'Equals sign not aligned with surrounding assignments; expected %s but found %s'; } - $errorData = array( - $expectedText, - $foundText, - ); + $errorData = [ + $expectedText, + $foundText, + ]; if ($this->error === true) { $fix = $phpcsFile->addFixableError($error, $assignment, $type, $errorData); diff --git a/coder_sniffer/Drupal/Sniffs/Formatting/SpaceInlineIfSniff.php b/coder_sniffer/Drupal/Sniffs/Formatting/SpaceInlineIfSniff.php index 8634c59574b9cae2aec987539ab587e5808b0e05..5cd202425639ff4580c782e5bcf618c10ed84998 100644 --- a/coder_sniffer/Drupal/Sniffs/Formatting/SpaceInlineIfSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Formatting/SpaceInlineIfSniff.php @@ -30,7 +30,7 @@ class SpaceInlineIfSniff implements Sniff */ public function register() { - return array(T_INLINE_ELSE); + return [T_INLINE_ELSE]; }//end register() diff --git a/coder_sniffer/Drupal/Sniffs/Formatting/SpaceUnaryOperatorSniff.php b/coder_sniffer/Drupal/Sniffs/Formatting/SpaceUnaryOperatorSniff.php index 6fb7e18a0f3b956cb36ef2abe8d7e9eea80c3d17..ada0c0a9428ae4f9176e2b527e84eaf107bab21d 100644 --- a/coder_sniffer/Drupal/Sniffs/Formatting/SpaceUnaryOperatorSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Formatting/SpaceUnaryOperatorSniff.php @@ -34,13 +34,13 @@ class SpaceUnaryOperatorSniff implements Sniff */ public function register() { - return array( - T_DEC, - T_INC, - T_MINUS, - T_PLUS, - T_BOOLEAN_NOT, - ); + return [ + T_DEC, + T_INC, + T_MINUS, + T_PLUS, + T_BOOLEAN_NOT, + ]; }//end register() @@ -63,12 +63,12 @@ class SpaceUnaryOperatorSniff implements Sniff $previous = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); $modifyLeft = in_array( $tokens[$previous]['code'], - array( - T_VARIABLE, - T_CLOSE_SQUARE_BRACKET, - T_CLOSE_PARENTHESIS, - T_STRING, - ) + [ + T_VARIABLE, + T_CLOSE_SQUARE_BRACKET, + T_CLOSE_PARENTHESIS, + T_STRING, + ] ); if ($modifyLeft === true && $tokens[($stackPtr - 1)]['code'] === T_WHITESPACE) { @@ -105,7 +105,7 @@ class SpaceUnaryOperatorSniff implements Sniff // Find the last syntax item to determine if this is an unary operator. $lastSyntaxItem = $phpcsFile->findPrevious( - array(T_WHITESPACE), + [T_WHITESPACE], ($stackPtr - 1), (($tokens[$stackPtr]['column']) * -1), true, @@ -114,16 +114,16 @@ class SpaceUnaryOperatorSniff implements Sniff ); $operatorSuffixAllowed = in_array( $tokens[$lastSyntaxItem]['code'], - array( - T_LNUMBER, - T_DNUMBER, - T_CLOSE_PARENTHESIS, - T_CLOSE_CURLY_BRACKET, - T_CLOSE_SQUARE_BRACKET, - T_CLOSE_SHORT_ARRAY, - T_VARIABLE, - T_STRING, - ) + [ + T_LNUMBER, + T_DNUMBER, + T_CLOSE_PARENTHESIS, + T_CLOSE_CURLY_BRACKET, + T_CLOSE_SQUARE_BRACKET, + T_CLOSE_SHORT_ARRAY, + T_VARIABLE, + T_STRING, + ] ); // Check plus / minus value assignments or comparisons. diff --git a/coder_sniffer/Drupal/Sniffs/Functions/DiscouragedFunctionsSniff.php b/coder_sniffer/Drupal/Sniffs/Functions/DiscouragedFunctionsSniff.php index d23f809e682c96afa108634870d8ebe57e61fdba..30bb1b683bd3894bdc29348fd24376d4f53f7728 100644 --- a/coder_sniffer/Drupal/Sniffs/Functions/DiscouragedFunctionsSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Functions/DiscouragedFunctionsSniff.php @@ -27,38 +27,38 @@ class DiscouragedFunctionsSniff extends ForbiddenFunctionsSniff * The value is NULL if no alternative exists, i.e., the function should * just not be used. * - * @var array(string => string|null) + * @var array|null) */ - public $forbiddenFunctions = array( + public $forbiddenFunctions = [ // Devel module debugging functions. - 'dargs' => null, - 'dcp' => null, - 'dd' => null, - 'dfb' => null, - 'dfbt' => null, - 'dpm' => null, - 'dpq' => null, - 'dpr' => null, - 'dprint_r' => null, - 'drupal_debug' => null, - 'dsm' => null, - 'dvm' => null, - 'dvr' => null, - 'kdevel_print_object' => null, - 'kpr' => null, - 'kprint_r' => null, - 'sdpm' => null, + 'dargs' => null, + 'dcp' => null, + 'dd' => null, + 'dfb' => null, + 'dfbt' => null, + 'dpm' => null, + 'dpq' => null, + 'dpr' => null, + 'dprint_r' => null, + 'drupal_debug' => null, + 'dsm' => null, + 'dvm' => null, + 'dvr' => null, + 'kdevel_print_object' => null, + 'kpr' => null, + 'kprint_r' => null, + 'sdpm' => null, // Functions which are not available on all // PHP builds. - 'fnmatch' => null, + 'fnmatch' => null, // Functions which are a security risk. - 'eval' => null, - ); + 'eval' => null, + ]; /** * If true, an error will be thrown; otherwise a warning. * - * @var bool + * @var boolean */ public $error = false; diff --git a/coder_sniffer/Drupal/Sniffs/Functions/FunctionDeclarationSniff.php b/coder_sniffer/Drupal/Sniffs/Functions/FunctionDeclarationSniff.php index c4d26a0d372e5b100d02a57ea81443b2f8287995..a3cea5c7614d9ff22b8d575051d80f455240288b 100644 --- a/coder_sniffer/Drupal/Sniffs/Functions/FunctionDeclarationSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Functions/FunctionDeclarationSniff.php @@ -34,7 +34,7 @@ class FunctionDeclarationSniff implements Sniff */ public function register() { - return array(T_FUNCTION); + return [T_FUNCTION]; }//end register() diff --git a/coder_sniffer/Drupal/Sniffs/InfoFiles/AutoAddedKeysSniff.php b/coder_sniffer/Drupal/Sniffs/InfoFiles/AutoAddedKeysSniff.php index 98e474e4517dd4587c6728bbe5bfba2e108e61f7..1d274ec5ce65760fb09923772fb10ff981386429 100644 --- a/coder_sniffer/Drupal/Sniffs/InfoFiles/AutoAddedKeysSniff.php +++ b/coder_sniffer/Drupal/Sniffs/InfoFiles/AutoAddedKeysSniff.php @@ -32,7 +32,7 @@ class AutoAddedKeysSniff implements Sniff */ public function register() { - return array(T_INLINE_HTML); + return [T_INLINE_HTML]; }//end register() diff --git a/coder_sniffer/Drupal/Sniffs/InfoFiles/ClassFilesSniff.php b/coder_sniffer/Drupal/Sniffs/InfoFiles/ClassFilesSniff.php index 681e19893e79e10568976a69e3038d998379b166..e0a7465d9b41fea99cba52ed97cbc455612f1589 100644 --- a/coder_sniffer/Drupal/Sniffs/InfoFiles/ClassFilesSniff.php +++ b/coder_sniffer/Drupal/Sniffs/InfoFiles/ClassFilesSniff.php @@ -31,7 +31,7 @@ class ClassFilesSniff implements Sniff */ public function register() { - return array(T_INLINE_HTML); + return [T_INLINE_HTML]; }//end register() @@ -72,7 +72,7 @@ class ClassFilesSniff implements Sniff $searchTokens = token_get_all(file_get_contents($fileName)); foreach ($searchTokens as $token) { if (is_array($token) === true - && in_array($token[0], array(T_CLASS, T_INTERFACE, T_TRAIT)) === true + && in_array($token[0], [T_CLASS, T_INTERFACE, T_TRAIT]) === true ) { continue 2; } @@ -121,7 +121,7 @@ class ClassFilesSniff implements Sniff */ public static function drupalParseInfoFormat($data) { - $info = array(); + $info = []; $constants = get_defined_constants(); if (preg_match_all( @@ -146,7 +146,7 @@ class ClassFilesSniff implements Sniff foreach ($matches as $match) { // Fetch the key and value string. $i = 0; - foreach (array('key', 'value1', 'value2', 'value3') as $var) { + foreach (['key', 'value1', 'value2', 'value3'] as $var) { if (isset($match[++$i]) === true) { $$var = $match[$i]; } else { @@ -168,7 +168,7 @@ class ClassFilesSniff implements Sniff } if (isset($parent[$key]) === false || is_array($parent[$key]) === false) { - $parent[$key] = array(); + $parent[$key] = []; } $parent = &$parent[$key]; diff --git a/coder_sniffer/Drupal/Sniffs/InfoFiles/DuplicateEntrySniff.php b/coder_sniffer/Drupal/Sniffs/InfoFiles/DuplicateEntrySniff.php index a6d52858bfdf7211283ef9c7c6a93d921b6a6bdc..5be538738612bc090333803a259040ec56f3260a 100644 --- a/coder_sniffer/Drupal/Sniffs/InfoFiles/DuplicateEntrySniff.php +++ b/coder_sniffer/Drupal/Sniffs/InfoFiles/DuplicateEntrySniff.php @@ -30,7 +30,7 @@ class DuplicateEntrySniff implements Sniff */ public function register() { - return array(T_INLINE_HTML); + return [T_INLINE_HTML]; }//end register() @@ -57,7 +57,7 @@ class DuplicateEntrySniff implements Sniff if (empty($duplicates) === false) { foreach ($duplicates as $duplicate) { $error = 'Duplicate entry for "%s" in info file'; - $phpcsFile->addError($error, $stackPtr, 'DuplicateEntry', array($duplicate)); + $phpcsFile->addError($error, $stackPtr, 'DuplicateEntry', [$duplicate]); } } @@ -75,8 +75,8 @@ class DuplicateEntrySniff implements Sniff */ protected function findDuplicateInfoFileEntries($data) { - $info = array(); - $duplicates = array(); + $info = []; + $duplicates = []; $constants = get_defined_constants(); if (preg_match_all( @@ -101,7 +101,7 @@ class DuplicateEntrySniff implements Sniff foreach ($matches as $match) { // Fetch the key and value string. $i = 0; - foreach (array('key', 'value1', 'value2', 'value3') as $var) { + foreach (['key', 'value1', 'value2', 'value3'] as $var) { if (isset($match[++$i]) === true) { $$var = $match[$i]; } else { @@ -123,7 +123,7 @@ class DuplicateEntrySniff implements Sniff } if (isset($parent[$key]) === false || is_array($parent[$key]) === false) { - $parent[$key] = array(); + $parent[$key] = []; } $parent = &$parent[$key]; diff --git a/coder_sniffer/Drupal/Sniffs/InfoFiles/RequiredSniff.php b/coder_sniffer/Drupal/Sniffs/InfoFiles/RequiredSniff.php index 67a03c56767186b698042c3d738ac3d8ef70f86c..e1f93231cbdd9f2b3f082ebe4f5e62043ebfc55e 100644 --- a/coder_sniffer/Drupal/Sniffs/InfoFiles/RequiredSniff.php +++ b/coder_sniffer/Drupal/Sniffs/InfoFiles/RequiredSniff.php @@ -32,7 +32,7 @@ class RequiredSniff implements Sniff */ public function register() { - return array(T_INLINE_HTML); + return [T_INLINE_HTML]; }//end register() diff --git a/coder_sniffer/Drupal/Sniffs/Methods/MethodDeclarationSniff.php b/coder_sniffer/Drupal/Sniffs/Methods/MethodDeclarationSniff.php index d36b32db17f1a7bb226c6b03b8897474f7d85646..a5ebcb284faf886ed767664dfba4d09a16d5f3b7 100644 --- a/coder_sniffer/Drupal/Sniffs/Methods/MethodDeclarationSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Methods/MethodDeclarationSniff.php @@ -32,7 +32,7 @@ class MethodDeclarationSniff extends PSR2MethodDeclarationSniff */ public function __construct() { - AbstractScopeSniff::__construct(array(T_CLASS, T_INTERFACE, T_TRAIT), array(T_FUNCTION)); + AbstractScopeSniff::__construct([T_CLASS, T_INTERFACE, T_TRAIT], [T_FUNCTION]); }//end __construct() diff --git a/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidClassNameSniff.php b/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidClassNameSniff.php index 5f3ca71b8d0c768e64a2cf6fd4aaade77c85cc61..0eb621fd3d8b0f3ecaa11190251e510f72c54689 100644 --- a/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidClassNameSniff.php +++ b/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidClassNameSniff.php @@ -42,10 +42,10 @@ class ValidClassNameSniff implements Sniff */ public function register() { - return array( - T_CLASS, - T_INTERFACE, - ); + return [ + T_CLASS, + T_INTERFACE, + ]; }//end register() @@ -65,7 +65,7 @@ class ValidClassNameSniff implements Sniff $className = $phpcsFile->findNext(T_STRING, $stackPtr); $name = trim($tokens[$className]['content']); - $errorData = array(ucfirst($tokens[$stackPtr]['content'])); + $errorData = [ucfirst($tokens[$stackPtr]['content'])]; // Make sure the first letter is a capital. if (preg_match('|^[A-Z]|', $name) === 0) { diff --git a/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidFunctionNameSniff.php b/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidFunctionNameSniff.php index 5f6b1ab70071a3f1fbd5759d719807d194c7a4fb..0b2d9d1fa645711b1ff34368ae8496f9fa062830 100644 --- a/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidFunctionNameSniff.php +++ b/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidFunctionNameSniff.php @@ -48,7 +48,7 @@ class ValidFunctionNameSniff extends CamelCapsFunctionNameSniff } $className = $phpcsFile->getDeclarationName($currScope); - $errorData = array($className.'::'.$methodName); + $errorData = [$className.'::'.$methodName]; // Is this a magic method. i.e., is prefixed with "__" ? if (preg_match('|^__|', $methodName) !== 0) { @@ -67,10 +67,10 @@ class ValidFunctionNameSniff extends CamelCapsFunctionNameSniff if (Common::isCamelCaps($methodName, false, true, $this->strict) === false) { if ($methodProps['scope_specified'] === true) { $error = '%s method name "%s" is not in lowerCamel format'; - $data = array( - ucfirst($methodProps['scope']), - $errorData[0], - ); + $data = [ + ucfirst($methodProps['scope']), + $errorData[0], + ]; $phpcsFile->addError($error, $stackPtr, 'ScopeNotCamelCaps', $data); } else { $error = 'Method name "%s" is not in lowerCamel format'; @@ -114,10 +114,10 @@ class ValidFunctionNameSniff extends CamelCapsFunctionNameSniff if ($functionName !== strtolower($functionName)) { $expected = strtolower(preg_replace('/([^_])([A-Z])/', '$1_$2', $functionName)); $error = 'Invalid function name, expected %s but found %s'; - $data = array( - $expected, - $functionName, - ); + $data = [ + $expected, + $functionName, + ]; $phpcsFile->addError($error, $stackPtr, 'InvalidName', $data); } diff --git a/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidGlobalSniff.php b/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidGlobalSniff.php index 884a60cfa1d4a0c5b1e2980a978a90d8fc839c27..ea04e89fbea8ac3fd69b45320e56dd3b30ded851 100644 --- a/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidGlobalSniff.php +++ b/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidGlobalSniff.php @@ -23,56 +23,61 @@ use PHP_CodeSniffer\Util\Tokens; class ValidGlobalSniff implements Sniff { - public $coreGlobals = array( - '$argc', - '$argv', - '$base_insecure_url', - '$base_path', - '$base_root', - '$base_secure_url', - '$base_theme_info', - '$base_url', - '$channel', - '$conf', - '$config', - '$config_directories', - '$cookie_domain', - '$databases', - '$db_prefix', - '$db_type', - '$db_url', - '$drupal_hash_salt', - '$drupal_test_info', - '$element', - '$forum_topic_list_header', - '$image', - '$install_state', - '$installed_profile', - '$is_https', - '$is_https_mock', - '$item', - '$items', - '$language', - '$language_content', - '$language_url', - '$locks', - '$menu_admin', - '$multibyte', - '$pager_limits', - '$pager_page_array', - '$pager_total', - '$pager_total_items', - '$tag', - '$theme', - '$theme_engine', - '$theme_info', - '$theme_key', - '$theme_path', - '$timers', - '$update_free_access', - '$update_rewrite_settings', - '$user', - ); + /** + * List of allowed Drupal core global variable names. + * + * @var array + */ + public $coreGlobals = [ + '$argc', + '$argv', + '$base_insecure_url', + '$base_path', + '$base_root', + '$base_secure_url', + '$base_theme_info', + '$base_url', + '$channel', + '$conf', + '$config', + '$config_directories', + '$cookie_domain', + '$databases', + '$db_prefix', + '$db_type', + '$db_url', + '$drupal_hash_salt', + '$drupal_test_info', + '$element', + '$forum_topic_list_header', + '$image', + '$install_state', + '$installed_profile', + '$is_https', + '$is_https_mock', + '$item', + '$items', + '$language', + '$language_content', + '$language_url', + '$locks', + '$menu_admin', + '$multibyte', + '$pager_limits', + '$pager_page_array', + '$pager_total', + '$pager_total_items', + '$tag', + '$theme', + '$theme_engine', + '$theme_info', + '$theme_key', + '$theme_path', + '$timers', + '$update_free_access', + '$update_rewrite_settings', + '$user', + ]; /** @@ -82,7 +87,7 @@ class ValidGlobalSniff implements Sniff */ public function register() { - return array(T_GLOBAL); + return [T_GLOBAL]; }//end register() diff --git a/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidVariableNameSniff.php b/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidVariableNameSniff.php index d5eb9a972f78fbdb5682ea121c059f570fbdf282..e4b0e829e835f22f7d64124326447f690fdbad4a 100644 --- a/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidVariableNameSniff.php +++ b/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidVariableNameSniff.php @@ -71,8 +71,8 @@ class ValidVariableNameSniff extends AbstractVariableSniff if ($extendsName !== false && in_array( $extendsName, [ - 'Plugin', - 'ViewsPluginAnnotationBase', + 'Plugin', + 'ViewsPluginAnnotationBase', ] ) !== false ) { @@ -86,7 +86,7 @@ class ValidVariableNameSniff extends AbstractVariableSniff }//end if $error = 'Class property %s should use lowerCamel naming without underscores'; - $data = array($tokens[$stackPtr]['content']); + $data = [$tokens[$stackPtr]['content']]; $phpcsFile->addError($error, $stackPtr, 'LowerCamelName', $data); }//end processMemberVar() @@ -106,17 +106,17 @@ class ValidVariableNameSniff extends AbstractVariableSniff $varName = ltrim($tokens[$stackPtr]['content'], '$'); - $phpReservedVars = array( - '_SERVER', - '_GET', - '_POST', - '_REQUEST', - '_SESSION', - '_ENV', - '_COOKIE', - '_FILES', - 'GLOBALS', - ); + $phpReservedVars = [ + '_SERVER', + '_GET', + '_POST', + '_REQUEST', + '_SESSION', + '_ENV', + '_COOKIE', + '_FILES', + 'GLOBALS', + ]; // If it's a php reserved var, then its ok. if (in_array($varName, $phpReservedVars) === true) { diff --git a/coder_sniffer/Drupal/Sniffs/Scope/MethodScopeSniff.php b/coder_sniffer/Drupal/Sniffs/Scope/MethodScopeSniff.php index bd8532e812a09910c9a73f15745a1d7a98a2e5c5..b23f97aa671c65966344fb8c30689be7c139dc00 100644 --- a/coder_sniffer/Drupal/Sniffs/Scope/MethodScopeSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Scope/MethodScopeSniff.php @@ -34,7 +34,7 @@ class MethodScopeSniff extends AbstractScopeSniff */ public function __construct() { - parent::__construct(array(T_CLASS, T_INTERFACE, T_TRAIT), array(T_FUNCTION)); + parent::__construct([T_CLASS, T_INTERFACE, T_TRAIT], [T_FUNCTION]); }//end __construct() @@ -75,7 +75,7 @@ class MethodScopeSniff extends AbstractScopeSniff if ($modifier === null) { $error = 'Visibility must be declared on method "%s"'; - $data = array($methodName); + $data = [$methodName]; $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Missing', $data); if ($fix === true) { diff --git a/coder_sniffer/Drupal/Sniffs/Semantics/ConstantNameSniff.php b/coder_sniffer/Drupal/Sniffs/Semantics/ConstantNameSniff.php index 9fb999d01267ea2e52aaef371107d23ed62912bc..83aa3988f436a19d99a3eb60e267097fc1198324 100644 --- a/coder_sniffer/Drupal/Sniffs/Semantics/ConstantNameSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Semantics/ConstantNameSniff.php @@ -31,7 +31,7 @@ class ConstantNameSniff extends FunctionCall */ public function registerFunctionNames() { - return array('define'); + return ['define']; }//end registerFunctionNames() @@ -75,10 +75,10 @@ class ConstantNameSniff extends FunctionCall $constant = substr($tokens[$argument['start']]['content'], 1, -1); if (strpos($constant, $expectedStart) !== 0) { $warning = 'All constants defined by a module must be prefixed with the module\'s name, expected "%s" but found "%s"'; - $data = array( - $expectedStart."_$constant", - $constant, - ); + $data = [ + $expectedStart."_$constant", + $constant, + ]; $phpcsFile->addWarning($warning, $stackPtr, 'ConstantStart', $data); } diff --git a/coder_sniffer/Drupal/Sniffs/Semantics/FunctionAliasSniff.php b/coder_sniffer/Drupal/Sniffs/Semantics/FunctionAliasSniff.php index ee7e12af38ad04ff43731dcaca608d68b1694047..ccb920c668e9582b4df50325b7059373c80e54d9 100644 --- a/coder_sniffer/Drupal/Sniffs/Semantics/FunctionAliasSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Semantics/FunctionAliasSniff.php @@ -28,157 +28,157 @@ class FunctionAliasSniff extends FunctionCall * * @var array */ - protected $aliases = array( - '_' => 'gettext', - 'chop' => 'rtrim', - 'close' => 'closedir', - 'com_get' => 'com_propget', - 'com_propset' => 'com_propput', - 'com_set' => 'com_propput', - 'die' => 'exit', - 'diskfreespace' => 'disk_free_space', - 'doubleval' => 'floatval', - 'fbsql' => 'fbsql_db_query', - 'fputs' => 'fwrite', - 'gzputs' => 'gzwrite', - 'i18n_convert' => 'mb_convert_encoding', - 'i18n_discover_encoding' => 'mb_detect_encoding', - 'i18n_http_input' => 'mb_http_input', - 'i18n_http_output' => 'mb_http_output', - 'i18n_internal_encoding' => 'mb_internal_encoding', - 'i18n_ja_jp_hantozen' => 'mb_convert_kana', - 'i18n_mime_header_decode' => 'mb_decode_mimeheader', - 'i18n_mime_header_encode' => 'mb_encode_mimeheader', - 'imap_create' => 'imap_createmailbox', - 'imap_fetchtext' => 'imap_body', - 'imap_getmailboxes' => 'imap_list_full', - 'imap_getsubscribed' => 'imap_lsub_full', - 'imap_header' => 'imap_headerinfo', - 'imap_listmailbox' => 'imap_list', - 'imap_listsubscribed' => 'imap_lsub', - 'imap_rename' => 'imap_renamemailbox', - 'imap_scan' => 'imap_listscan', - 'imap_scanmailbox' => 'imap_listscan', - 'ini_alter' => 'ini_set', - 'is_double' => 'is_float', - 'is_integer' => 'is_int', - 'is_long' => 'is_int', - 'is_real' => 'is_float', - 'is_writeable' => 'is_writable', - 'join' => 'implode', - 'key_exists' => 'array_key_exists', - 'ldap_close' => 'ldap_unbind', - 'magic_quotes_runtime' => 'set_magic_quotes_runtime', - 'mbstrcut' => 'mb_strcut', - 'mbstrlen' => 'mb_strlen', - 'mbstrpos' => 'mb_strpos', - 'mbstrrpos' => 'mb_strrpos', - 'mbsubstr' => 'mb_substr', - 'ming_setcubicthreshold' => 'ming_setCubicThreshold', - 'ming_setscale' => 'ming_setScale', - 'msql' => 'msql_db_query', - 'msql_createdb' => 'msql_create_db', - 'msql_dbname' => 'msql_result', - 'msql_dropdb' => 'msql_drop_db', - 'msql_fieldflags' => 'msql_field_flags', - 'msql_fieldlen' => 'msql_field_len', - 'msql_fieldname' => 'msql_field_name', - 'msql_fieldtable' => 'msql_field_table', - 'msql_fieldtype' => 'msql_field_type', - 'msql_freeresult' => 'msql_free_result', - 'msql_listdbs' => 'msql_list_dbs', - 'msql_listfields' => 'msql_list_fields', - 'msql_listtables' => 'msql_list_tables', - 'msql_numfields' => 'msql_num_fields', - 'msql_numrows' => 'msql_num_rows', - 'msql_regcase' => 'sql_regcase', - 'msql_selectdb' => 'msql_select_db', - 'msql_tablename' => 'msql_result', - 'mssql_affected_rows' => 'sybase_affected_rows', - 'mssql_affected_rows' => 'sybase_affected_rows', - 'mssql_close' => 'sybase_close', - 'mssql_close' => 'sybase_close', - 'mssql_connect' => 'sybase_connect', - 'mssql_connect' => 'sybase_connect', - 'mssql_data_seek' => 'sybase_data_seek', - 'mssql_data_seek' => 'sybase_data_seek', - 'mssql_fetch_array' => 'sybase_fetch_array', - 'mssql_fetch_array' => 'sybase_fetch_array', - 'mssql_fetch_field' => 'sybase_fetch_field', - 'mssql_fetch_field' => 'sybase_fetch_field', - 'mssql_fetch_object' => 'sybase_fetch_object', - 'mssql_fetch_object' => 'sybase_fetch_object', - 'mssql_fetch_row' => 'sybase_fetch_row', - 'mssql_fetch_row' => 'sybase_fetch_row', - 'mssql_field_seek' => 'sybase_field_seek', - 'mssql_field_seek' => 'sybase_field_seek', - 'mssql_free_result' => 'sybase_free_result', - 'mssql_free_result' => 'sybase_free_result', - 'mssql_get_last_message' => 'sybase_get_last_message', - 'mssql_get_last_message' => 'sybase_get_last_message', - 'mssql_min_client_severity' => 'sybase_min_client_severity', - 'mssql_min_error_severity' => 'sybase_min_error_severity', - 'mssql_min_message_severity' => 'sybase_min_message_severity', - 'mssql_min_server_severity' => 'sybase_min_server_severity', - 'mssql_num_fields' => 'sybase_num_fields', - 'mssql_num_fields' => 'sybase_num_fields', - 'mssql_num_rows' => 'sybase_num_rows', - 'mssql_num_rows' => 'sybase_num_rows', - 'mssql_pconnect' => 'sybase_pconnect', - 'mssql_pconnect' => 'sybase_pconnect', - 'mssql_query' => 'sybase_query', - 'mssql_query' => 'sybase_query', - 'mssql_result' => 'sybase_result', - 'mssql_result' => 'sybase_result', - 'mssql_select_db' => 'sybase_select_db', - 'mssql_select_db' => 'sybase_select_db', - 'mysql' => 'mysql_db_query', - 'mysql_createdb' => 'mysql_create_db', - 'mysql_db_name' => 'mysql_result', - 'mysql_dbname' => 'mysql_result', - 'mysql_dropdb' => 'mysql_drop_db', - 'mysql_fieldflags' => 'mysql_field_flags', - 'mysql_fieldlen' => 'mysql_field_len', - 'mysql_fieldname' => 'mysql_field_name', - 'mysql_fieldtable' => 'mysql_field_table', - 'mysql_fieldtype' => 'mysql_field_type', - 'mysql_freeresult' => 'mysql_free_result', - 'mysql_listdbs' => 'mysql_list_dbs', - 'mysql_listfields' => 'mysql_list_fields', - 'mysql_listtables' => 'mysql_list_tables', - 'mysql_numfields' => 'mysql_num_fields', - 'mysql_numrows' => 'mysql_num_rows', - 'mysql_selectdb' => 'mysql_select_db', - 'mysql_tablename' => 'mysql_result', - 'oci8append' => 'ocicollappend', - 'oci8assign' => 'ocicollassign', - 'oci8assignelem' => 'ocicollassignelem', - 'oci8close' => 'ocicloselob', - 'oci8free' => 'ocifreecoll', - 'oci8free' => 'ocifreedesc', - 'oci8getelem' => 'ocicollgetelem', - 'oci8load' => 'ociloadlob', - 'oci8max' => 'ocicollmax', - 'oci8ocifreecursor' => 'ocifreestatement', - 'oci8save' => 'ocisavelob', - 'oci8savefile' => 'ocisavelobfile', - 'oci8size' => 'ocicollsize', - 'oci8trim' => 'ocicolltrim', - 'oci8writetemporary' => 'ociwritetemporarylob', - 'oci8writetofile' => 'ociwritelobtofile', - 'odbc_do' => 'odbc_exec', - 'odbc_field_precision' => 'odbc_field_len', - 'pdf_add_outline' => 'pdf_add_bookmark', - 'pg_clientencoding' => 'pg_client_encoding', - 'pg_setclientencoding' => 'pg_set_client_encoding', - 'pos' => 'current', - 'recode' => 'recode_string', - 'show_source' => 'highlight_file', - 'sizeof' => 'count', - 'snmpwalkoid' => 'snmprealwalk', - 'strchr' => 'strstr', - 'xptr_new_context' => 'xpath_new_context', - ); + protected $aliases = [ + '_' => 'gettext', + 'chop' => 'rtrim', + 'close' => 'closedir', + 'com_get' => 'com_propget', + 'com_propset' => 'com_propput', + 'com_set' => 'com_propput', + 'die' => 'exit', + 'diskfreespace' => 'disk_free_space', + 'doubleval' => 'floatval', + 'fbsql' => 'fbsql_db_query', + 'fputs' => 'fwrite', + 'gzputs' => 'gzwrite', + 'i18n_convert' => 'mb_convert_encoding', + 'i18n_discover_encoding' => 'mb_detect_encoding', + 'i18n_http_input' => 'mb_http_input', + 'i18n_http_output' => 'mb_http_output', + 'i18n_internal_encoding' => 'mb_internal_encoding', + 'i18n_ja_jp_hantozen' => 'mb_convert_kana', + 'i18n_mime_header_decode' => 'mb_decode_mimeheader', + 'i18n_mime_header_encode' => 'mb_encode_mimeheader', + 'imap_create' => 'imap_createmailbox', + 'imap_fetchtext' => 'imap_body', + 'imap_getmailboxes' => 'imap_list_full', + 'imap_getsubscribed' => 'imap_lsub_full', + 'imap_header' => 'imap_headerinfo', + 'imap_listmailbox' => 'imap_list', + 'imap_listsubscribed' => 'imap_lsub', + 'imap_rename' => 'imap_renamemailbox', + 'imap_scan' => 'imap_listscan', + 'imap_scanmailbox' => 'imap_listscan', + 'ini_alter' => 'ini_set', + 'is_double' => 'is_float', + 'is_integer' => 'is_int', + 'is_long' => 'is_int', + 'is_real' => 'is_float', + 'is_writeable' => 'is_writable', + 'join' => 'implode', + 'key_exists' => 'array_key_exists', + 'ldap_close' => 'ldap_unbind', + 'magic_quotes_runtime' => 'set_magic_quotes_runtime', + 'mbstrcut' => 'mb_strcut', + 'mbstrlen' => 'mb_strlen', + 'mbstrpos' => 'mb_strpos', + 'mbstrrpos' => 'mb_strrpos', + 'mbsubstr' => 'mb_substr', + 'ming_setcubicthreshold' => 'ming_setCubicThreshold', + 'ming_setscale' => 'ming_setScale', + 'msql' => 'msql_db_query', + 'msql_createdb' => 'msql_create_db', + 'msql_dbname' => 'msql_result', + 'msql_dropdb' => 'msql_drop_db', + 'msql_fieldflags' => 'msql_field_flags', + 'msql_fieldlen' => 'msql_field_len', + 'msql_fieldname' => 'msql_field_name', + 'msql_fieldtable' => 'msql_field_table', + 'msql_fieldtype' => 'msql_field_type', + 'msql_freeresult' => 'msql_free_result', + 'msql_listdbs' => 'msql_list_dbs', + 'msql_listfields' => 'msql_list_fields', + 'msql_listtables' => 'msql_list_tables', + 'msql_numfields' => 'msql_num_fields', + 'msql_numrows' => 'msql_num_rows', + 'msql_regcase' => 'sql_regcase', + 'msql_selectdb' => 'msql_select_db', + 'msql_tablename' => 'msql_result', + 'mssql_affected_rows' => 'sybase_affected_rows', + 'mssql_affected_rows' => 'sybase_affected_rows', + 'mssql_close' => 'sybase_close', + 'mssql_close' => 'sybase_close', + 'mssql_connect' => 'sybase_connect', + 'mssql_connect' => 'sybase_connect', + 'mssql_data_seek' => 'sybase_data_seek', + 'mssql_data_seek' => 'sybase_data_seek', + 'mssql_fetch_array' => 'sybase_fetch_array', + 'mssql_fetch_array' => 'sybase_fetch_array', + 'mssql_fetch_field' => 'sybase_fetch_field', + 'mssql_fetch_field' => 'sybase_fetch_field', + 'mssql_fetch_object' => 'sybase_fetch_object', + 'mssql_fetch_object' => 'sybase_fetch_object', + 'mssql_fetch_row' => 'sybase_fetch_row', + 'mssql_fetch_row' => 'sybase_fetch_row', + 'mssql_field_seek' => 'sybase_field_seek', + 'mssql_field_seek' => 'sybase_field_seek', + 'mssql_free_result' => 'sybase_free_result', + 'mssql_free_result' => 'sybase_free_result', + 'mssql_get_last_message' => 'sybase_get_last_message', + 'mssql_get_last_message' => 'sybase_get_last_message', + 'mssql_min_client_severity' => 'sybase_min_client_severity', + 'mssql_min_error_severity' => 'sybase_min_error_severity', + 'mssql_min_message_severity' => 'sybase_min_message_severity', + 'mssql_min_server_severity' => 'sybase_min_server_severity', + 'mssql_num_fields' => 'sybase_num_fields', + 'mssql_num_fields' => 'sybase_num_fields', + 'mssql_num_rows' => 'sybase_num_rows', + 'mssql_num_rows' => 'sybase_num_rows', + 'mssql_pconnect' => 'sybase_pconnect', + 'mssql_pconnect' => 'sybase_pconnect', + 'mssql_query' => 'sybase_query', + 'mssql_query' => 'sybase_query', + 'mssql_result' => 'sybase_result', + 'mssql_result' => 'sybase_result', + 'mssql_select_db' => 'sybase_select_db', + 'mssql_select_db' => 'sybase_select_db', + 'mysql' => 'mysql_db_query', + 'mysql_createdb' => 'mysql_create_db', + 'mysql_db_name' => 'mysql_result', + 'mysql_dbname' => 'mysql_result', + 'mysql_dropdb' => 'mysql_drop_db', + 'mysql_fieldflags' => 'mysql_field_flags', + 'mysql_fieldlen' => 'mysql_field_len', + 'mysql_fieldname' => 'mysql_field_name', + 'mysql_fieldtable' => 'mysql_field_table', + 'mysql_fieldtype' => 'mysql_field_type', + 'mysql_freeresult' => 'mysql_free_result', + 'mysql_listdbs' => 'mysql_list_dbs', + 'mysql_listfields' => 'mysql_list_fields', + 'mysql_listtables' => 'mysql_list_tables', + 'mysql_numfields' => 'mysql_num_fields', + 'mysql_numrows' => 'mysql_num_rows', + 'mysql_selectdb' => 'mysql_select_db', + 'mysql_tablename' => 'mysql_result', + 'oci8append' => 'ocicollappend', + 'oci8assign' => 'ocicollassign', + 'oci8assignelem' => 'ocicollassignelem', + 'oci8close' => 'ocicloselob', + 'oci8free' => 'ocifreecoll', + 'oci8free' => 'ocifreedesc', + 'oci8getelem' => 'ocicollgetelem', + 'oci8load' => 'ociloadlob', + 'oci8max' => 'ocicollmax', + 'oci8ocifreecursor' => 'ocifreestatement', + 'oci8save' => 'ocisavelob', + 'oci8savefile' => 'ocisavelobfile', + 'oci8size' => 'ocicollsize', + 'oci8trim' => 'ocicolltrim', + 'oci8writetemporary' => 'ociwritetemporarylob', + 'oci8writetofile' => 'ociwritelobtofile', + 'odbc_do' => 'odbc_exec', + 'odbc_field_precision' => 'odbc_field_len', + 'pdf_add_outline' => 'pdf_add_bookmark', + 'pg_clientencoding' => 'pg_client_encoding', + 'pg_setclientencoding' => 'pg_set_client_encoding', + 'pos' => 'current', + 'recode' => 'recode_string', + 'show_source' => 'highlight_file', + 'sizeof' => 'count', + 'snmpwalkoid' => 'snmprealwalk', + 'strchr' => 'strstr', + 'xptr_new_context' => 'xpath_new_context', + ]; /** @@ -215,10 +215,10 @@ class FunctionAliasSniff extends FunctionCall $tokens = $phpcsFile->getTokens(); $error = '%s() is a function name alias, use %s() instead'; $name = $tokens[$stackPtr]['content']; - $data = array( - $name, - $this->aliases[$name], - ); + $data = [ + $name, + $this->aliases[$name], + ]; $phpcsFile->addError($error, $stackPtr, 'FunctionAlias', $data); }//end processFunctionCall() diff --git a/coder_sniffer/Drupal/Sniffs/Semantics/FunctionCall.php b/coder_sniffer/Drupal/Sniffs/Semantics/FunctionCall.php index daa4f234bfdc901c2a09f0cf419fa373ea72e778..8d3b6442975892068b990578545da693aa406dce 100644 --- a/coder_sniffer/Drupal/Sniffs/Semantics/FunctionCall.php +++ b/coder_sniffer/Drupal/Sniffs/Semantics/FunctionCall.php @@ -33,21 +33,21 @@ abstract class FunctionCall implements Sniff /** * The token position of the function call. * - * @var int + * @var integer */ protected $functionCall; /** * The token position of the opening bracket of the function call. * - * @var int + * @var integer */ protected $openBracket; /** * The token position of the closing bracket of the function call. * - * @var int + * @var integer */ protected $closeBracket; @@ -62,7 +62,7 @@ abstract class FunctionCall implements Sniff * Whether method invocations with the same function name should be processed, * too. * - * @var bool + * @var boolean */ protected $includeMethodCalls = false; @@ -74,7 +74,7 @@ abstract class FunctionCall implements Sniff */ public function register() { - return array(T_STRING); + return [T_STRING]; }//end register() @@ -108,7 +108,7 @@ abstract class FunctionCall implements Sniff $this->functionCall = $stackPtr; $this->openBracket = $openBracket; $this->closeBracket = $tokens[$openBracket]['parenthesis_closer']; - $this->arguments = array(); + $this->arguments = []; $this->processFunctionCall($phpcsFile, $stackPtr, $openBracket, $this->closeBracket); @@ -204,10 +204,10 @@ abstract class FunctionCall implements Sniff // Update the end token of the current argument. $end = $this->phpcsFile->findPrevious(Tokens::$emptyTokens, ($nextSeperator - 1), null, true); // Save the calculated findings for the current argument. - $this->arguments[$counter] = array( - 'start' => $start, - 'end' => $end, - ); + $this->arguments[$counter] = [ + 'start' => $start, + 'end' => $end, + ]; if ($counter === $number) { break; } @@ -222,10 +222,10 @@ abstract class FunctionCall implements Sniff return false; } - $this->arguments[$counter] = array( - 'start' => $start, - 'end' => $end, - ); + $this->arguments[$counter] = [ + 'start' => $start, + 'end' => $end, + ]; return $this->arguments[$counter]; }//end getArgument() diff --git a/coder_sniffer/Drupal/Sniffs/Semantics/FunctionDefinition.php b/coder_sniffer/Drupal/Sniffs/Semantics/FunctionDefinition.php index 7d047acd49666866e5a6de56f94a3737440a6bfd..b285083d6a067c65a104ef0e366a84b8218aecee 100644 --- a/coder_sniffer/Drupal/Sniffs/Semantics/FunctionDefinition.php +++ b/coder_sniffer/Drupal/Sniffs/Semantics/FunctionDefinition.php @@ -31,7 +31,7 @@ abstract class FunctionDefinition implements Sniff */ public function register() { - return array(T_STRING); + return [T_STRING]; }//end register() @@ -73,7 +73,7 @@ abstract class FunctionDefinition implements Sniff * * @return void */ - public abstract function processFunction(File $phpcsFile, $stackPtr, $functionPtr); + abstract public function processFunction(File $phpcsFile, $stackPtr, $functionPtr); }//end class diff --git a/coder_sniffer/Drupal/Sniffs/Semantics/FunctionTSniff.php b/coder_sniffer/Drupal/Sniffs/Semantics/FunctionTSniff.php index c1f10aa97f39417ac5e1682b79b0465e2dbacd9e..5e6c3b72c8ccfcab3bb423a6d03c5155acd19911 100644 --- a/coder_sniffer/Drupal/Sniffs/Semantics/FunctionTSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Semantics/FunctionTSniff.php @@ -26,7 +26,7 @@ class FunctionTSniff extends FunctionCall /** * We also want to catch $this->t() calls in Drupal 8. * - * @var bool + * @var boolean */ protected $includeMethodCalls = true; @@ -38,11 +38,11 @@ class FunctionTSniff extends FunctionCall */ public function registerFunctionNames() { - return array( - 't', - 'TranslatableMarkup', - 'TranslationWrapper', - ); + return [ + 't', + 'TranslatableMarkup', + 'TranslationWrapper', + ]; }//end registerFunctionNames() @@ -155,19 +155,19 @@ class FunctionTSniff extends FunctionCall return true; } - $allowed_items = array( - '(', - ')', - '[', - ']', - '-', - '<', - '>', - '«', - '»', - '\n', - ); - foreach ($allowed_items as $item) { + $allowedItems = [ + '(', + ')', + '[', + ']', + '-', + '<', + '>', + '«', + '»', + '\n', + ]; + foreach ($allowedItems as $item) { if ($item === $string) { return true; } diff --git a/coder_sniffer/Drupal/Sniffs/Semantics/FunctionTriggerErrorSniff.php b/coder_sniffer/Drupal/Sniffs/Semantics/FunctionTriggerErrorSniff.php index 4f418c381eec84ca26f885cb593b85edc61598de..4b40fd6bcf07c6f2da12d53c8c758de84203e48e 100644 --- a/coder_sniffer/Drupal/Sniffs/Semantics/FunctionTriggerErrorSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Semantics/FunctionTriggerErrorSniff.php @@ -29,7 +29,7 @@ class FunctionTriggerErrorSniff extends FunctionCall */ public function registerFunctionNames() { - return array('trigger_error'); + return ['trigger_error']; }//end registerFunctionNames() @@ -74,10 +74,10 @@ class FunctionTriggerErrorSniff extends FunctionCall if ($tokens[$argument['start']]['code'] === T_STRING && strcasecmp($tokens[$argument['start']]['content'], 'sprintf') === 0 ) { - $message_position = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, $argument['start']); + $messagePosition = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, $argument['start']); // Remove the quotes using substr, because trim would take multiple // quotes away and possibly not report a faulty message. - $message_text = substr($tokens[$message_position]['content'], 1, ($tokens[$message_position]['length'] - 2)); + $messageText = substr($tokens[$messagePosition]['content'], 1, ($tokens[$messagePosition]['length'] - 2)); } else { // If not sprintf() then extract and store all the items except // whitespace, concatenation operators and comma. This will give all @@ -86,14 +86,14 @@ class FunctionTriggerErrorSniff extends FunctionCall if (in_array($tokens[$i]['code'], [T_WHITESPACE, T_STRING_CONCAT, T_COMMA]) === false) { // For strings, remove the quotes using substr not trim. if ($tokens[$i]['code'] === T_CONSTANT_ENCAPSED_STRING) { - $message_parts[] = substr($tokens[$i]['content'], 1, ($tokens[$i]['length'] - 2)); + $messageParts[] = substr($tokens[$i]['content'], 1, ($tokens[$i]['length'] - 2)); } else { - $message_parts[] = $tokens[$i]['content']; + $messageParts[] = $tokens[$i]['content']; } } } - $message_text = implode(' ', $message_parts); + $messageText = implode(' ', $messageParts); }//end if // The standard format for @trigger_error() is: @@ -101,39 +101,39 @@ class FunctionTriggerErrorSniff extends FunctionCall // Use (?U) 'ungreedy' before the version so that only the text up to // the first '. ' is matched, as there may be more than one sentence in // the extra-info part. - $matches = array(); - preg_match('/(.+) is deprecated in (?U)(.+)\. (.+)\. See (.+)$/', $message_text, $matches); + $matches = []; + preg_match('/(.+) is deprecated in (?U)(.+)\. (.+)\. See (.+)$/', $messageText, $matches); // There should be 5 items in $matches: 0 is full text, 1 = thing, // 2 = in-version, 3 = extra-info, 4 = cr-link. if (count($matches) !== 5) { $error = "The deprecation message '%s' does not match the standard format: %%thing%% is deprecated in %%in-version%%. %%extra-info%%. See %%cr-link%%"; - $phpcsFile->addError($error, $argument['start'], 'TriggerErrorTextLayout', array($message_text)); + $phpcsFile->addError($error, $argument['start'], 'TriggerErrorTextLayout', [$messageText]); } else { // The text follows the basic layout. Now check that the version // matches drupal:n.n.n or project:n.x-n.n. The text must be all // lower case and numbers can be one or two digits. - $in_version = $matches[2]; - if (preg_match('/^drupal:\d{1,2}\.\d{1,2}\.\d{1,2}$/', $in_version) === 0 - && preg_match('/^[a-z\d_]+:\d{1,2}\.x\-\d{1,2}\.\d{1,2}$/', $in_version) === 0 + $inVersion = $matches[2]; + if (preg_match('/^drupal:\d{1,2}\.\d{1,2}\.\d{1,2}$/', $inVersion) === 0 + && preg_match('/^[a-z\d_]+:\d{1,2}\.x\-\d{1,2}\.\d{1,2}$/', $inVersion) === 0 ) { $error = "The deprecation version '%s' does not match the standard: drupal:n.n.n or project:n.x-n.n"; - $phpcsFile->addWarning($error, $argument['start'], 'TriggerErrorVersion', array($in_version)); + $phpcsFile->addWarning($error, $argument['start'], 'TriggerErrorVersion', [$inVersion]); } // Check the 'See' link. - $cr_link = $matches[4]; + $crLink = $matches[4]; // Allow for the alternative 'node' or 'project/aaa/issues' format. - preg_match('[^http(s*)://www.drupal.org/(node|project/\w+/issues)/(\d+)(\.*)$]', $cr_link, $matches); + preg_match('[^http(s*)://www.drupal.org/(node|project/\w+/issues)/(\d+)(\.*)$]', $crLink, $matches); // If matches[4] is not blank it means that the url is correct but it // ends with a period. As this can be a common mistake give a specific // message to assist in fixing. if (isset($matches[4]) === true && empty($matches[4]) === false) { $error = "The 'See' url '%s' should not end with a period."; - $phpcsFile->addWarning($error, $argument['start'], 'TriggerErrorPeriodAfterSeeUrl', array($cr_link)); + $phpcsFile->addWarning($error, $argument['start'], 'TriggerErrorPeriodAfterSeeUrl', [$crLink]); } else if (empty($matches) === true) { $error = "The 'See' url '%s' does not match the standard: http(s)://www.drupal.org/node/n or http(s)://www.drupal.org/project/aaa/issues/n"; - $phpcsFile->addWarning($error, $argument['start'], 'TriggerErrorSeeUrlFormat', array($cr_link)); + $phpcsFile->addWarning($error, $argument['start'], 'TriggerErrorSeeUrlFormat', [$crLink]); } }//end if diff --git a/coder_sniffer/Drupal/Sniffs/Semantics/FunctionWatchdogSniff.php b/coder_sniffer/Drupal/Sniffs/Semantics/FunctionWatchdogSniff.php index 05b952c07f36b7b25903459842f4d476316a2cb3..d00bf14ddd7b8369a99fa01eda9c22eafad7ad7a 100644 --- a/coder_sniffer/Drupal/Sniffs/Semantics/FunctionWatchdogSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Semantics/FunctionWatchdogSniff.php @@ -30,7 +30,7 @@ class FunctionWatchdogSniff extends FunctionCall */ public function registerFunctionNames() { - return array('watchdog'); + return ['watchdog']; }//end registerFunctionNames() diff --git a/coder_sniffer/Drupal/Sniffs/Semantics/InstallHooksSniff.php b/coder_sniffer/Drupal/Sniffs/Semantics/InstallHooksSniff.php index 41aaf3e828262d008ad8794d2329b189351660d1..c991f0322022d0daac3c81de882c3e232e3da1f8 100644 --- a/coder_sniffer/Drupal/Sniffs/Semantics/InstallHooksSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Semantics/InstallHooksSniff.php @@ -54,7 +54,7 @@ class InstallHooksSniff extends FunctionDefinition || $tokens[$stackPtr]['content'] === ($fileName.'_disable') ) { $error = '%s() is an installation hook and must be declared in an install file'; - $data = array($tokens[$stackPtr]['content']); + $data = [$tokens[$stackPtr]['content']]; $phpcsFile->addError($error, $stackPtr, 'InstallHook', $data); } diff --git a/coder_sniffer/Drupal/Sniffs/Semantics/LStringTranslatableSniff.php b/coder_sniffer/Drupal/Sniffs/Semantics/LStringTranslatableSniff.php index a8edcef9d323425746ea366d8d2268c6442e5c24..0523a009e95bfa1cc2b8ec983c507ca25ae953f5 100644 --- a/coder_sniffer/Drupal/Sniffs/Semantics/LStringTranslatableSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Semantics/LStringTranslatableSniff.php @@ -30,7 +30,7 @@ class LStringTranslatableSniff extends FunctionCall */ public function registerFunctionNames() { - return array('l'); + return ['l']; }//end registerFunctionNames() diff --git a/coder_sniffer/Drupal/Sniffs/Semantics/PregSecuritySniff.php b/coder_sniffer/Drupal/Sniffs/Semantics/PregSecuritySniff.php index 67ba73c5e67de40f37555141a0c3e7ac997a960d..99943c13829d1500c5aeb78924bf2b2558173c0f 100644 --- a/coder_sniffer/Drupal/Sniffs/Semantics/PregSecuritySniff.php +++ b/coder_sniffer/Drupal/Sniffs/Semantics/PregSecuritySniff.php @@ -31,15 +31,15 @@ class PregSecuritySniff extends FunctionCall */ public function registerFunctionNames() { - return array( - 'preg_filter', - 'preg_grep', - 'preg_match', - 'preg_match_all', - 'preg_replace', - 'preg_replace_callback', - 'preg_split', - ); + return [ + 'preg_filter', + 'preg_grep', + 'preg_match', + 'preg_match_all', + 'preg_replace', + 'preg_replace_callback', + 'preg_split', + ]; }//end registerFunctionNames() @@ -89,7 +89,7 @@ class PregSecuritySniff extends FunctionCall $warn, $argument['start'], 'PregEFlag', - array($tokens[$stackPtr]['content']) + [$tokens[$stackPtr]['content']] ); return; } diff --git a/coder_sniffer/Drupal/Sniffs/Semantics/RemoteAddressSniff.php b/coder_sniffer/Drupal/Sniffs/Semantics/RemoteAddressSniff.php index 53dc4cdf83210d10ff66512089694cfb88452cf2..346a46426ee936273999753eadc4844dbae087fb 100644 --- a/coder_sniffer/Drupal/Sniffs/Semantics/RemoteAddressSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Semantics/RemoteAddressSniff.php @@ -31,7 +31,7 @@ class RemoteAddressSniff implements Sniff */ public function register() { - return array(T_VARIABLE); + return [T_VARIABLE]; }//end register() diff --git a/coder_sniffer/Drupal/Sniffs/WhiteSpace/CloseBracketSpacingSniff.php b/coder_sniffer/Drupal/Sniffs/WhiteSpace/CloseBracketSpacingSniff.php index 720ba3c6f5aeaf7ef1ad7fbf3271979fabe2b171..5ba50d78be867493435168249d79d989c3112e60 100644 --- a/coder_sniffer/Drupal/Sniffs/WhiteSpace/CloseBracketSpacingSniff.php +++ b/coder_sniffer/Drupal/Sniffs/WhiteSpace/CloseBracketSpacingSniff.php @@ -30,10 +30,10 @@ class CloseBracketSpacingSniff implements Sniff * * @var array */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); + public $supportedTokenizers = [ + 'PHP', + 'JS', + ]; /** @@ -43,11 +43,11 @@ class CloseBracketSpacingSniff implements Sniff */ public function register() { - return array( - T_CLOSE_CURLY_BRACKET, - T_CLOSE_PARENTHESIS, - T_CLOSE_SHORT_ARRAY, - ); + return [ + T_CLOSE_CURLY_BRACKET, + T_CLOSE_PARENTHESIS, + T_CLOSE_SHORT_ARRAY, + ]; }//end register() @@ -82,7 +82,7 @@ class CloseBracketSpacingSniff implements Sniff $error, ($stackPtr - 1), 'ClosingWhitespace', - array($tokens[$stackPtr]['content']) + [$tokens[$stackPtr]['content']] ); if ($fix === true) { $phpcsFile->fixer->replaceToken(($stackPtr - 1), ''); diff --git a/coder_sniffer/Drupal/Sniffs/WhiteSpace/CommaSniff.php b/coder_sniffer/Drupal/Sniffs/WhiteSpace/CommaSniff.php index 69f1fba72dea46a1767ff4babef203c4d02786bf..65b63f9ea8062398c2573a681fc06f00a9634e0e 100644 --- a/coder_sniffer/Drupal/Sniffs/WhiteSpace/CommaSniff.php +++ b/coder_sniffer/Drupal/Sniffs/WhiteSpace/CommaSniff.php @@ -32,7 +32,7 @@ class CommaSniff implements Sniff */ public function register() { - return array(T_COMMA); + return [T_COMMA]; }//end register() @@ -73,7 +73,7 @@ class CommaSniff implements Sniff && $tokens[($stackPtr + 1)]['content'] !== ' ' ) { $error = 'Expected one space after the comma, %s found'; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'TooManySpaces', array(strlen($tokens[($stackPtr + 1)]['content']))); + $fix = $phpcsFile->addFixableError($error, $stackPtr, 'TooManySpaces', [strlen($tokens[($stackPtr + 1)]['content'])]); if ($fix === true) { $phpcsFile->fixer->replaceToken(($stackPtr + 1), ' '); } diff --git a/coder_sniffer/Drupal/Sniffs/WhiteSpace/EmptyLinesSniff.php b/coder_sniffer/Drupal/Sniffs/WhiteSpace/EmptyLinesSniff.php index 0d09618d98624dc378be22e148d92fdbdb202d67..7be7f8c3a42b0ae506bc749484e87edfdc264586 100644 --- a/coder_sniffer/Drupal/Sniffs/WhiteSpace/EmptyLinesSniff.php +++ b/coder_sniffer/Drupal/Sniffs/WhiteSpace/EmptyLinesSniff.php @@ -29,11 +29,11 @@ class EmptyLinesSniff implements Sniff * * @var array */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - 'CSS', - ); + public $supportedTokenizers = [ + 'PHP', + 'JS', + 'CSS', + ]; /** @@ -43,7 +43,7 @@ class EmptyLinesSniff implements Sniff */ public function register() { - return array(T_WHITESPACE); + return [T_WHITESPACE]; }//end register() diff --git a/coder_sniffer/Drupal/Sniffs/WhiteSpace/NamespaceSniff.php b/coder_sniffer/Drupal/Sniffs/WhiteSpace/NamespaceSniff.php index ddee5245051e8ea183c3f2db1a6af273e44f3f53..b85b94c1bb1ce4f8b97fe2014fb3539ba028d71f 100644 --- a/coder_sniffer/Drupal/Sniffs/WhiteSpace/NamespaceSniff.php +++ b/coder_sniffer/Drupal/Sniffs/WhiteSpace/NamespaceSniff.php @@ -30,7 +30,7 @@ class NamespaceSniff implements Sniff */ public function register() { - return array(T_NAMESPACE); + return [T_NAMESPACE]; }//end register() diff --git a/coder_sniffer/Drupal/Sniffs/WhiteSpace/ObjectOperatorIndentSniff.php b/coder_sniffer/Drupal/Sniffs/WhiteSpace/ObjectOperatorIndentSniff.php index ab72a1c098626355cc219d07d18022c163afc267..5360884bf6c5492de8c47c4737be7c9e414c9f93 100644 --- a/coder_sniffer/Drupal/Sniffs/WhiteSpace/ObjectOperatorIndentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/WhiteSpace/ObjectOperatorIndentSniff.php @@ -41,7 +41,7 @@ class ObjectOperatorIndentSniff implements Sniff */ public function register() { - return array(T_OBJECT_OPERATOR); + return [T_OBJECT_OPERATOR]; }//end register() @@ -72,16 +72,16 @@ class ObjectOperatorIndentSniff implements Sniff } // Check if the line before is in the same scope and go back if necessary. - $scopeDiff = array($previousLine => $previousLine); + $scopeDiff = [$previousLine => $previousLine]; while (empty($scopeDiff) === false) { // Find the first non whitespace character on the previous line. $startOfLine = $this->findStartOfline($phpcsFile, $previousLine); - $startParenthesis = array(); + $startParenthesis = []; if (isset($tokens[$startOfLine]['nested_parenthesis']) === true) { $startParenthesis = $tokens[$startOfLine]['nested_parenthesis']; } - $operatorParenthesis = array(); + $operatorParenthesis = []; if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) { $operatorParenthesis = $tokens[$stackPtr]['nested_parenthesis']; } @@ -116,10 +116,10 @@ class ObjectOperatorIndentSniff implements Sniff if ($tokens[$stackPtr]['column'] !== ($tokens[$startOfLine]['column'] + $additionalIndent)) { $error = 'Object operator not indented correctly; expected %s spaces but found %s'; $expectedIndent = ($tokens[$startOfLine]['column'] + $additionalIndent - 1); - $data = array( - $expectedIndent, - $tokens[$stackPtr]['column'] - 1, - ); + $data = [ + $expectedIndent, + ($tokens[$stackPtr]['column'] - 1), + ]; $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Indent', $data); if ($fix === true) { diff --git a/coder_sniffer/Drupal/Sniffs/WhiteSpace/ObjectOperatorSpacingSniff.php b/coder_sniffer/Drupal/Sniffs/WhiteSpace/ObjectOperatorSpacingSniff.php index ba787fd8910a0ce184e1262280aed32abc84b7a3..bd34f3f509105cd99024cf8e791f1d2558824485 100644 --- a/coder_sniffer/Drupal/Sniffs/WhiteSpace/ObjectOperatorSpacingSniff.php +++ b/coder_sniffer/Drupal/Sniffs/WhiteSpace/ObjectOperatorSpacingSniff.php @@ -35,7 +35,7 @@ class ObjectOperatorSpacingSniff implements Sniff */ public function register() { - return array(T_OBJECT_OPERATOR); + return [T_OBJECT_OPERATOR]; }//end register() diff --git a/coder_sniffer/Drupal/Sniffs/WhiteSpace/OpenBracketSpacingSniff.php b/coder_sniffer/Drupal/Sniffs/WhiteSpace/OpenBracketSpacingSniff.php index 6c35ecf73ce42997e419574ecf16f9544a96168a..0bb9c254b40ec3c8bdaf2ab84acdd8660f1e09d6 100644 --- a/coder_sniffer/Drupal/Sniffs/WhiteSpace/OpenBracketSpacingSniff.php +++ b/coder_sniffer/Drupal/Sniffs/WhiteSpace/OpenBracketSpacingSniff.php @@ -29,10 +29,10 @@ class OpenBracketSpacingSniff implements Sniff * * @var array */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); + public $supportedTokenizers = [ + 'PHP', + 'JS', + ]; /** @@ -42,11 +42,11 @@ class OpenBracketSpacingSniff implements Sniff */ public function register() { - return array( - T_OPEN_CURLY_BRACKET, - T_OPEN_PARENTHESIS, - T_OPEN_SHORT_ARRAY, - ); + return [ + T_OPEN_CURLY_BRACKET, + T_OPEN_PARENTHESIS, + T_OPEN_SHORT_ARRAY, + ]; }//end register() @@ -83,7 +83,7 @@ class OpenBracketSpacingSniff implements Sniff $error, ($stackPtr + 1), 'OpeningWhitespace', - array($tokens[$stackPtr]['content']) + [$tokens[$stackPtr]['content']] ); if ($fix === true) { $phpcsFile->fixer->replaceToken(($stackPtr + 1), ''); diff --git a/coder_sniffer/Drupal/Sniffs/WhiteSpace/OpenTagNewlineSniff.php b/coder_sniffer/Drupal/Sniffs/WhiteSpace/OpenTagNewlineSniff.php index c4f4e7c5e3bb9beb3f07d8104595a897428ecd24..c5a8339ba908bd157147f393bf7fa39de07bc131 100644 --- a/coder_sniffer/Drupal/Sniffs/WhiteSpace/OpenTagNewlineSniff.php +++ b/coder_sniffer/Drupal/Sniffs/WhiteSpace/OpenTagNewlineSniff.php @@ -30,7 +30,7 @@ class OpenTagNewlineSniff implements Sniff */ public function register() { - return array(T_OPEN_TAG); + return [T_OPEN_TAG]; }//end register() diff --git a/coder_sniffer/Drupal/Sniffs/WhiteSpace/OperatorSpacingSniff.php b/coder_sniffer/Drupal/Sniffs/WhiteSpace/OperatorSpacingSniff.php index 92b851817a2532f6fed34d9cc5b6784f446c0467..56bee50e1736447a01433b9a60e43cd102d9eb42 100644 --- a/coder_sniffer/Drupal/Sniffs/WhiteSpace/OperatorSpacingSniff.php +++ b/coder_sniffer/Drupal/Sniffs/WhiteSpace/OperatorSpacingSniff.php @@ -29,10 +29,10 @@ class OperatorSpacingSniff implements Sniff * * @var array */ - public $supportedTokenizers = array( - 'PHP', - 'JS', - ); + public $supportedTokenizers = [ + 'PHP', + 'JS', + ]; /** * Allow newlines instead of spaces. @@ -52,10 +52,10 @@ class OperatorSpacingSniff implements Sniff $comparison = Tokens::$comparisonTokens; $operators = Tokens::$operators; $assignment = Tokens::$assignmentTokens; - $inlineIf = array( - T_INLINE_THEN, - T_INLINE_ELSE, - ); + $inlineIf = [ + T_INLINE_THEN, + T_INLINE_ELSE, + ]; return array_unique( array_merge($comparison, $operators, $assignment, $inlineIf) @@ -141,7 +141,7 @@ class OperatorSpacingSniff implements Sniff && ($found !== 'newline' || $this->ignoreNewlines === false) ) { $error = 'Expected 1 space before "&" operator; %s found'; - $data = array($found); + $data = [$found]; $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingBeforeAmp', $data); if ($fix === true) { $phpcsFile->fixer->replaceToken(($stackPtr - 1), ' '); @@ -170,7 +170,7 @@ class OperatorSpacingSniff implements Sniff && ($found !== 'newline' || $this->ignoreNewlines === false) ) { $error = 'Expected 1 space after "&" operator; %s found'; - $data = array($found); + $data = [$found]; $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingAfterAmp', $data); if ($fix === true) { $phpcsFile->fixer->replaceToken(($stackPtr + 1), ' '); @@ -212,17 +212,17 @@ class OperatorSpacingSniff implements Sniff // A list of tokens that indicate that the token is not // part of an arithmetic operation. - $invalidTokens = array( - T_COMMA => true, - T_OPEN_PARENTHESIS => true, - T_OPEN_SQUARE_BRACKET => true, - T_OPEN_SHORT_ARRAY => true, - T_DOUBLE_ARROW => true, - T_COLON => true, - T_INLINE_THEN => true, - T_INLINE_ELSE => true, - T_CASE => true, - ); + $invalidTokens = [ + T_COMMA => true, + T_OPEN_PARENTHESIS => true, + T_OPEN_SQUARE_BRACKET => true, + T_OPEN_SHORT_ARRAY => true, + T_DOUBLE_ARROW => true, + T_COLON => true, + T_INLINE_THEN => true, + T_INLINE_ELSE => true, + T_CASE => true, + ]; if (isset($invalidTokens[$tokens[$prev]['code']]) === true) { // Just trying to use a negative value; eg. myFunction($var, -2). @@ -254,10 +254,10 @@ class OperatorSpacingSniff implements Sniff && ($found !== 'newline' || $this->ignoreNewlines === false) ) { $error = 'Expected 1 space before "%s"; %s found'; - $data = array( - $operator, - $found, - ); + $data = [ + $operator, + $found, + ]; $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingBefore', $data); if ($fix === true) { $phpcsFile->fixer->beginChangeset(); @@ -301,10 +301,10 @@ class OperatorSpacingSniff implements Sniff && ($found !== 'newline' || $this->ignoreNewlines === false) ) { $error = 'Expected 1 space after "%s"; %s found'; - $data = array( - $operator, - $found, - ); + $data = [ + $operator, + $found, + ]; $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingAfter', $data); if ($fix === true) { $phpcsFile->fixer->replaceToken(($stackPtr + 1), ' '); diff --git a/coder_sniffer/Drupal/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php b/coder_sniffer/Drupal/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php index a06da0e8a170374c1a417bd2dcfa94ff81d41d56..b58c2ae570da2f02300f31265800e4d04f037dd2 100644 --- a/coder_sniffer/Drupal/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php +++ b/coder_sniffer/Drupal/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php @@ -29,7 +29,7 @@ class ScopeClosingBraceSniff implements Sniff /** * The number of spaces code should be indented. * - * @var int + * @var integer */ public $indent = 2; @@ -104,11 +104,11 @@ class ScopeClosingBraceSniff implements Sniff // Check that the closing brace is on it's own line. $lastContent = $phpcsFile->findPrevious( - array( - T_WHITESPACE, - T_INLINE_HTML, - T_OPEN_TAG, - ), + [ + T_WHITESPACE, + T_INLINE_HTML, + T_OPEN_TAG, + ], ($scopeEnd - 1), $scopeStart, true @@ -163,20 +163,20 @@ class ScopeClosingBraceSniff implements Sniff $expectedIndent = ($startColumn + $this->indent - 1); if ($braceIndent !== $expectedIndent) { $error = 'Case breaking statement indented incorrectly; expected %s spaces, found %s'; - $data = array( - $expectedIndent, - $braceIndent, - ); + $data = [ + $expectedIndent, + $braceIndent, + ]; $fix = $phpcsFile->addFixableError($error, $scopeEnd, 'BreakIndent', $data); } } else { $expectedIndent = ($startColumn - 1); if ($braceIndent !== $expectedIndent) { $error = 'Closing brace indented incorrectly; expected %s spaces, found %s'; - $data = array( - $expectedIndent, - $braceIndent, - ); + $data = [ + $expectedIndent, + $braceIndent, + ]; $fix = $phpcsFile->addFixableError($error, $scopeEnd, 'Indent', $data); } }//end if diff --git a/coder_sniffer/Drupal/Sniffs/WhiteSpace/ScopeIndentSniff.php b/coder_sniffer/Drupal/Sniffs/WhiteSpace/ScopeIndentSniff.php index 7c414eb9868a402726e471485ced4b35cea3885a..97a04547d3517fc41c25450df8c00dda1f3a76ae 100644 --- a/coder_sniffer/Drupal/Sniffs/WhiteSpace/ScopeIndentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/WhiteSpace/ScopeIndentSniff.php @@ -36,12 +36,12 @@ class ScopeIndentSniff implements Sniff * * @var array */ - public $supportedTokenizers = array('PHP'); + public $supportedTokenizers = ['PHP']; /** * The number of spaces code should be indented. * - * @var int + * @var integer */ public $indent = 2; @@ -51,7 +51,7 @@ class ScopeIndentSniff implements Sniff * If TRUE, indent needs to be exactly $indent spaces. If FALSE, * indent needs to be at least $indent spaces (but can be more). * - * @var bool + * @var boolean */ public $exact = true; @@ -62,16 +62,16 @@ class ScopeIndentSniff implements Sniff * The size of each tab is important, so it should be specified * using the --tab-width CLI argument. * - * @var bool + * @var boolean */ public $tabIndent = false; /** * The --tab-width CLI value that is being used. * - * @var int + * @var integer */ - private $_tabWidth = null; + private $tabWidth = null; /** * List of tokens not needing to be checked for indentation. @@ -83,7 +83,7 @@ class ScopeIndentSniff implements Sniff * * @var int[] */ - public $ignoreIndentationTokens = array(); + public $ignoreIndentationTokens = []; /** * List of tokens not needing to be checked for indentation. @@ -93,21 +93,21 @@ class ScopeIndentSniff implements Sniff * * @var int[] */ - private $_ignoreIndentationTokens = array(); + private $_ignoreIndentationTokens = []; /** * Any scope openers that should not cause an indent. * * @var int[] */ - protected $nonIndentingScopes = array(); + protected $nonIndentingScopes = []; /** * Show debug output for this sniff. * - * @var bool + * @var boolean */ - private $_debug = false; + private $debug = false; /** @@ -118,10 +118,10 @@ class ScopeIndentSniff implements Sniff public function register() { if (defined('PHP_CODESNIFFER_IN_TESTS') === true) { - $this->_debug = false; + $this->debug = false; } - return array(T_OPEN_TAG); + return [T_OPEN_TAG]; }//end register() @@ -139,27 +139,27 @@ class ScopeIndentSniff implements Sniff { $debug = Config::getConfigData('scope_indent_debug'); if ($debug !== null) { - $this->_debug = (bool) $debug; + $this->debug = (bool) $debug; } - if ($this->_tabWidth === null) { + if ($this->tabWidth === null) { $config = $phpcsFile->config; if (isset($config->tabWidth) === false || $config->tabWidth === 0) { // We have no idea how wide tabs are, so assume 4 spaces for fixing. // It shouldn't really matter because indent checks elsewhere in the // standard should fix things up. - $this->_tabWidth = 4; + $this->tabWidth = 4; } else { - $this->_tabWidth = $config->tabWidth; + $this->tabWidth = $config->tabWidth; } } $currentIndent = 0; $lastOpenTag = $stackPtr; $lastCloseTag = null; - $openScopes = array(); - $adjustments = array(); - $setIndents = array(); + $openScopes = []; + $adjustments = []; + $setIndents = []; $tokens = $phpcsFile->getTokens(); $first = $phpcsFile->findFirstOnLine(T_INLINE_HTML, $stackPtr); @@ -170,13 +170,13 @@ class ScopeIndentSniff implements Sniff $currentIndent = (strlen($tokens[$first]['content']) - strlen($trimmed)); } - if ($this->_debug === true) { + if ($this->debug === true) { $line = $tokens[$stackPtr]['line']; echo "Start with token $stackPtr on line $line with indent $currentIndent".PHP_EOL; } if (empty($this->_ignoreIndentationTokens) === true) { - $this->_ignoreIndentationTokens = array(T_INLINE_HTML => true); + $this->_ignoreIndentationTokens = [T_INLINE_HTML => true]; foreach ($this->ignoreIndentationTokens as $token) { if (is_int($token) === false) { if (defined($token) === false) { @@ -240,7 +240,7 @@ class ScopeIndentSniff implements Sniff $parenCloser = $i; } - if ($this->_debug === true) { + if ($this->debug === true) { $line = $tokens[$i]['line']; echo "Closing parenthesis found on line $line".PHP_EOL; } @@ -253,7 +253,7 @@ class ScopeIndentSniff implements Sniff ) { end($tokens[$parenCloser]['nested_parenthesis']); $parens = key($tokens[$parenCloser]['nested_parenthesis']); - if ($this->_debug === true) { + if ($this->debug === true) { $line = $tokens[$parens]['line']; echo "\t* token has nested parenthesis $parens on line $line *".PHP_EOL; } @@ -265,7 +265,7 @@ class ScopeIndentSniff implements Sniff ) { end($tokens[$parenCloser]['conditions']); $condition = key($tokens[$parenCloser]['conditions']); - if ($this->_debug === true) { + if ($this->debug === true) { $line = $tokens[$condition]['line']; $type = $tokens[$condition]['type']; echo "\t* token is inside condition $condition ($type) on line $line *".PHP_EOL; @@ -273,14 +273,14 @@ class ScopeIndentSniff implements Sniff } if ($parens > $condition) { - if ($this->_debug === true) { + if ($this->debug === true) { echo "\t* using parenthesis *".PHP_EOL; } $parenOpener = $parens; $condition = 0; } else if ($condition > 0) { - if ($this->_debug === true) { + if ($this->debug === true) { echo "\t* using condition *".PHP_EOL; } @@ -294,7 +294,7 @@ class ScopeIndentSniff implements Sniff $lastOpenTagCondition = array_pop($lastOpenTagConditions); if ($condition > 0 && $lastOpenTagCondition === $condition) { - if ($this->_debug === true) { + if ($this->debug === true) { echo "\t* open tag is inside condition; using open tag *".PHP_EOL; } @@ -305,7 +305,7 @@ class ScopeIndentSniff implements Sniff $currentIndent = $checkIndent; - if ($this->_debug === true) { + if ($this->debug === true) { $type = $tokens[$lastOpenTag]['type']; echo "\t=> checking indent of $checkIndent; main indent set to $currentIndent by token $lastOpenTag ($type)".PHP_EOL; } @@ -320,7 +320,7 @@ class ScopeIndentSniff implements Sniff $currentIndent = $checkIndent; - if ($this->_debug === true) { + if ($this->debug === true) { $type = $tokens[$condition]['type']; echo "\t=> checking indent of $checkIndent; main indent set to $currentIndent by token $condition ($type)".PHP_EOL; } @@ -332,7 +332,7 @@ class ScopeIndentSniff implements Sniff $checkIndent += $adjustments[$first]; } - if ($this->_debug === true) { + if ($this->debug === true) { $line = $tokens[$first]['line']; $type = $tokens[$first]['type']; echo "\t* first token on line $line is $first ($type) *".PHP_EOL; @@ -347,7 +347,7 @@ class ScopeIndentSniff implements Sniff $prev = $phpcsFile->findStartOfStatement($first, T_COMMA); if ($prev !== $first) { // This is not the start of the statement. - if ($this->_debug === true) { + if ($this->debug === true) { $line = $tokens[$prev]['line']; $type = $tokens[$prev]['type']; echo "\t* previous is $type on line $line *".PHP_EOL; @@ -356,7 +356,7 @@ class ScopeIndentSniff implements Sniff $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $prev, true); $prev = $phpcsFile->findStartOfStatement($first, T_COMMA); $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $prev, true); - if ($this->_debug === true) { + if ($this->debug === true) { $line = $tokens[$first]['line']; $type = $tokens[$first]['type']; echo "\t* amended first token is $first ($type) on line $line *".PHP_EOL; @@ -366,7 +366,7 @@ class ScopeIndentSniff implements Sniff if (isset($tokens[$first]['scope_closer']) === true && $tokens[$first]['scope_closer'] === $first ) { - if ($this->_debug === true) { + if ($this->debug === true) { echo "\t* first token is a scope closer *".PHP_EOL; } @@ -386,7 +386,7 @@ class ScopeIndentSniff implements Sniff $setIndents[$first] = $currentIndent; - if ($this->_debug === true) { + if ($this->debug === true) { $type = $tokens[$first]['type']; echo "\t=> indent set to $currentIndent by token $first ($type)".PHP_EOL; } @@ -401,13 +401,13 @@ class ScopeIndentSniff implements Sniff $setIndents[$first] = $currentIndent; - if ($this->_debug === true) { + if ($this->debug === true) { $type = $tokens[$first]['type']; echo "\t=> checking indent of $checkIndent; main indent set to $currentIndent by token $first ($type)".PHP_EOL; } }//end if }//end if - } else if ($this->_debug === true) { + } else if ($this->debug === true) { echo "\t * ignoring single-line definition *".PHP_EOL; }//end if }//end if @@ -424,7 +424,7 @@ class ScopeIndentSniff implements Sniff $arrayCloser = $i; } - if ($this->_debug === true) { + if ($this->debug === true) { $line = $tokens[$arrayCloser]['line']; echo "Closing short array bracket found on line $line".PHP_EOL; } @@ -439,7 +439,7 @@ class ScopeIndentSniff implements Sniff $exact = false; - if ($this->_debug === true) { + if ($this->debug === true) { $line = $tokens[$first]['line']; $type = $tokens[$first]['type']; echo "\t* first token on line $line is $first ($type) *".PHP_EOL; @@ -454,7 +454,7 @@ class ScopeIndentSniff implements Sniff $prev = $phpcsFile->findStartOfStatement($first, T_COMMA); if ($prev !== $first) { // This is not the start of the statement. - if ($this->_debug === true) { + if ($this->debug === true) { $line = $tokens[$prev]['line']; $type = $tokens[$prev]['type']; echo "\t* previous is $type on line $line *".PHP_EOL; @@ -463,7 +463,7 @@ class ScopeIndentSniff implements Sniff $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $prev, true); $prev = $phpcsFile->findStartOfStatement($first, T_COMMA); $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $prev, true); - if ($this->_debug === true) { + if ($this->debug === true) { $line = $tokens[$first]['line']; $type = $tokens[$first]['type']; echo "\t* amended first token is $first ($type) on line $line *".PHP_EOL; @@ -476,13 +476,13 @@ class ScopeIndentSniff implements Sniff // The first token is a scope closer and would have already // been processed and set the indent level correctly, so // don't adjust it again. - if ($this->_debug === true) { + if ($this->debug === true) { echo "\t* first token is a scope closer; ignoring closing short array bracket *".PHP_EOL; } if (isset($setIndents[$first]) === true) { $currentIndent = $setIndents[$first]; - if ($this->_debug === true) { + if ($this->debug === true) { echo "\t=> indent reset to $currentIndent".PHP_EOL; } } @@ -496,12 +496,12 @@ class ScopeIndentSniff implements Sniff $setIndents[$first] = $currentIndent; - if ($this->_debug === true) { + if ($this->debug === true) { $type = $tokens[$first]['type']; echo "\t=> checking indent of $checkIndent; main indent set to $currentIndent by token $first ($type)".PHP_EOL; } }//end if - } else if ($this->_debug === true) { + } else if ($this->debug === true) { echo "\t * ignoring single-line definition *".PHP_EOL; }//end if }//end if @@ -529,8 +529,8 @@ class ScopeIndentSniff implements Sniff $padding = ($tokenIndent + $adjustments[$first]); if ($padding > 0) { if ($this->tabIndent === true) { - $numTabs = floor($padding / $this->_tabWidth); - $numSpaces = ($padding - ($numTabs * $this->_tabWidth)); + $numTabs = floor($padding / $this->tabWidth); + $numSpaces = ($padding - ($numTabs * $this->tabWidth)); $padding = str_repeat("\t", $numTabs).str_repeat(' ', $numSpaces); } else { $padding = str_repeat(' ', $padding); @@ -546,7 +546,7 @@ class ScopeIndentSniff implements Sniff $phpcsFile->fixer->replaceToken(($checkToken - 1), $padding); } - if ($this->_debug === true) { + if ($this->debug === true) { $length = strlen($padding); $line = $tokens[$checkToken]['line']; $type = $tokens[$checkToken]['type']; @@ -555,7 +555,7 @@ class ScopeIndentSniff implements Sniff $adjustments[$checkToken] = $adjustments[$first]; - if ($this->_debug === true) { + if ($this->debug === true) { $line = $tokens[$checkToken]['line']; $type = $tokens[$checkToken]['type']; echo "\t=> Add adjustment of ".$adjustments[$checkToken]." for token $checkToken ($type) on line $line".PHP_EOL; @@ -577,7 +577,7 @@ class ScopeIndentSniff implements Sniff && $tokens[$i]['scope_closer'] === $i && $tokens[$i]['line'] !== $tokens[$tokens[$i]['scope_opener']]['line'])) ) { - if ($this->_debug === true) { + if ($this->debug === true) { if ($checkToken === null) { $type = $tokens[$tokens[$i]['scope_condition']]['type']; $line = $tokens[$i]['line']; @@ -611,7 +611,7 @@ class ScopeIndentSniff implements Sniff $setIndents[$scopeCloser] = $currentIndent; - if ($this->_debug === true) { + if ($this->debug === true) { $type = $tokens[$scopeCloser]['type']; echo "\t=> indent set to $currentIndent by token $scopeCloser ($type)".PHP_EOL; } @@ -635,7 +635,7 @@ class ScopeIndentSniff implements Sniff && $tokens[$i]['code'] === T_CLOSE_OBJECT && $tokens[$i]['line'] !== $tokens[$tokens[$i]['bracket_opener']]['line'])) ) { - if ($this->_debug === true) { + if ($this->debug === true) { $line = $tokens[$i]['line']; echo "Close JS object on line $line".PHP_EOL; } @@ -653,7 +653,7 @@ class ScopeIndentSniff implements Sniff ) { end($tokens[$scopeCloser]['nested_parenthesis']); $parens = key($tokens[$scopeCloser]['nested_parenthesis']); - if ($this->_debug === true) { + if ($this->debug === true) { $line = $tokens[$parens]['line']; echo "\t* token has nested parenthesis $parens on line $line *".PHP_EOL; } @@ -665,7 +665,7 @@ class ScopeIndentSniff implements Sniff ) { end($tokens[$scopeCloser]['conditions']); $condition = key($tokens[$scopeCloser]['conditions']); - if ($this->_debug === true) { + if ($this->debug === true) { $line = $tokens[$condition]['line']; $type = $tokens[$condition]['type']; echo "\t* token is inside condition $condition ($type) on line $line *".PHP_EOL; @@ -673,21 +673,21 @@ class ScopeIndentSniff implements Sniff } if ($parens > $condition) { - if ($this->_debug === true) { + if ($this->debug === true) { echo "\t* using parenthesis *".PHP_EOL; } $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $parens, true); $condition = 0; } else if ($condition > 0) { - if ($this->_debug === true) { + if ($this->debug === true) { echo "\t* using condition *".PHP_EOL; } $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $condition, true); $parens = 0; } else { - if ($this->_debug === true) { + if ($this->debug === true) { $line = $tokens[$tokens[$scopeCloser]['bracket_opener']]['line']; echo "\t* token is not in parenthesis or condition; using opener on line $line *".PHP_EOL; } @@ -720,7 +720,7 @@ class ScopeIndentSniff implements Sniff $checkIndent = (int) (ceil($checkIndent / $this->indent) * $this->indent); $setIndents[$first] = $currentIndent; - if ($this->_debug === true) { + if ($this->debug === true) { $type = $tokens[$first]['type']; echo "\t=> checking indent of $checkIndent; main indent set to $currentIndent by token $first ($type)".PHP_EOL; } @@ -750,7 +750,7 @@ class ScopeIndentSniff implements Sniff ) { $currentIndent -= $this->indent; $setIndents[$lastOpener] = $currentIndent; - if ($this->_debug === true) { + if ($this->debug === true) { $line = $tokens[$i]['line']; $type = $tokens[$lastOpener]['type']; echo "Shared closer found on line $line".PHP_EOL; @@ -766,7 +766,7 @@ class ScopeIndentSniff implements Sniff $checkIndent = (int) (ceil($tokenIndent / $this->indent) * $this->indent); $exact = false; - if ($this->_debug === true) { + if ($this->debug === true) { $line = $tokens[$i]['line']; echo "Closure found on line $line".PHP_EOL; echo "\t=> checking indent of $checkIndent; main indent remains at $currentIndent".PHP_EOL; @@ -832,12 +832,12 @@ class ScopeIndentSniff implements Sniff $before = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($checkToken - 1), null, true); if ($before !== false && in_array( $tokens[$before]['code'], - array( - T_SEMICOLON, - T_CLOSE_CURLY_BRACKET, - T_OPEN_CURLY_BRACKET, - T_COLON, - ) + [ + T_SEMICOLON, + T_CLOSE_CURLY_BRACKET, + T_OPEN_CURLY_BRACKET, + T_COLON, + ] ) === false ) { continue; @@ -863,31 +863,31 @@ class ScopeIndentSniff implements Sniff if ($this->tabIndent === true) { $error .= '%s tabs, found %s'; - $data = array( - floor($checkIndent / $this->_tabWidth), - floor($tokenIndent / $this->_tabWidth), - ); + $data = [ + floor($checkIndent / $this->tabWidth), + floor($tokenIndent / $this->tabWidth), + ]; } else { $error .= '%s spaces, found %s'; - $data = array( - $checkIndent, - $tokenIndent, - ); + $data = [ + $checkIndent, + $tokenIndent, + ]; } - if ($this->_debug === true) { + if ($this->debug === true) { $line = $tokens[$checkToken]['line']; $message = vsprintf($error, $data); echo "[Line $line] $message".PHP_EOL; } $fix = $phpcsFile->addFixableError($error, $checkToken, $type, $data); - if ($fix === true || $this->_debug === true) { + if ($fix === true || $this->debug === true) { $padding = ''; if ($this->tabIndent === true) { - $numTabs = floor($checkIndent / $this->_tabWidth); + $numTabs = floor($checkIndent / $this->tabWidth); if ($numTabs > 0) { - $numSpaces = ($checkIndent - ($numTabs * $this->_tabWidth)); + $numSpaces = ($checkIndent - ($numTabs * $this->tabWidth)); $padding = str_repeat("\t", $numTabs).str_repeat(' ', $numSpaces); } } else if ($checkIndent > 0) { @@ -903,7 +903,7 @@ class ScopeIndentSniff implements Sniff if ($accepted === true) { $adjustments[$checkToken] = ($checkIndent - $tokenIndent); - if ($this->_debug === true) { + if ($this->debug === true) { $line = $tokens[$checkToken]['line']; $type = $tokens[$checkToken]['type']; echo "\t=> Add adjustment of ".$adjustments[$checkToken]." for token $checkToken ($type) on line $line".PHP_EOL; @@ -926,7 +926,7 @@ class ScopeIndentSniff implements Sniff if ($tokens[$i]['code'] === T_START_HEREDOC || $tokens[$i]['code'] === T_START_NOWDOC ) { - $i = $phpcsFile->findNext(array(T_END_HEREDOC, T_END_NOWDOC), ($i + 1)); + $i = $phpcsFile->findNext([T_END_HEREDOC, T_END_NOWDOC], ($i + 1)); continue; } @@ -951,7 +951,7 @@ class ScopeIndentSniff implements Sniff if ($tokens[$i]['code'] === T_OPEN_TAG || $tokens[$i]['code'] === T_OPEN_TAG_WITH_ECHO ) { - if ($this->_debug === true) { + if ($this->debug === true) { $line = $tokens[$i]['line']; echo "Open PHP tag found on line $line".PHP_EOL; } @@ -973,7 +973,7 @@ class ScopeIndentSniff implements Sniff $currentIndent = (int) (ceil($currentIndent / $this->indent) * $this->indent); $setIndents[$i] = $currentIndent; - if ($this->_debug === true) { + if ($this->debug === true) { $type = $tokens[$i]['type']; echo "\t=> indent set to $currentIndent by token $i ($type)".PHP_EOL; } @@ -984,7 +984,7 @@ class ScopeIndentSniff implements Sniff // Close tags reset the indent level, unless they are closing a tag // opened on the same line. if ($tokens[$i]['code'] === T_CLOSE_TAG) { - if ($this->_debug === true) { + if ($this->debug === true) { $line = $tokens[$i]['line']; echo "Close PHP tag found on line $line".PHP_EOL; } @@ -1008,7 +1008,7 @@ class ScopeIndentSniff implements Sniff $currentIndent = (int) (ceil($currentIndent / $this->indent) * $this->indent); $setIndents[$i] = $currentIndent; - if ($this->_debug === true) { + if ($this->debug === true) { $type = $tokens[$i]['type']; echo "\t=> indent set to $currentIndent by token $i ($type)".PHP_EOL; } @@ -1020,7 +1020,7 @@ class ScopeIndentSniff implements Sniff if ($tokens[$i]['code'] === T_CLOSURE || $tokens[$i]['code'] === T_ANON_CLASS) { $closer = $tokens[$i]['scope_closer']; if ($tokens[$i]['line'] === $tokens[$closer]['line']) { - if ($this->_debug === true) { + if ($this->debug === true) { $type = str_replace('_', ' ', strtolower(substr($tokens[$i]['type'], 2))); $line = $tokens[$i]['line']; echo "* ignoring single-line $type on line $line".PHP_EOL; @@ -1030,7 +1030,7 @@ class ScopeIndentSniff implements Sniff continue; } - if ($this->_debug === true) { + if ($this->debug === true) { $type = str_replace('_', ' ', strtolower(substr($tokens[$i]['type'], 2))); $line = $tokens[$i]['line']; echo "Open $type on line $line".PHP_EOL; @@ -1048,7 +1048,7 @@ class ScopeIndentSniff implements Sniff $i = $tokens[$i]['scope_opener']; $setIndents[$i] = $currentIndent; - if ($this->_debug === true) { + if ($this->debug === true) { $type = $tokens[$i]['type']; echo "\t=> indent set to $currentIndent by token $i ($type)".PHP_EOL; } @@ -1063,7 +1063,7 @@ class ScopeIndentSniff implements Sniff ) { $closer = $tokens[$i]['scope_closer']; if ($tokens[$i]['line'] === $tokens[$closer]['line']) { - if ($this->_debug === true) { + if ($this->debug === true) { $line = $tokens[$i]['line']; $type = $tokens[$i]['type']; echo "* ignoring single-line $type on line $line".PHP_EOL; @@ -1077,7 +1077,7 @@ class ScopeIndentSniff implements Sniff if (isset(Tokens::$scopeOpeners[$condition]) === true && in_array($condition, $this->nonIndentingScopes) === false ) { - if ($this->_debug === true) { + if ($this->debug === true) { $line = $tokens[$i]['line']; $type = $tokens[$tokens[$i]['scope_condition']]['type']; echo "Open scope ($type) on line $line".PHP_EOL; @@ -1087,7 +1087,7 @@ class ScopeIndentSniff implements Sniff $setIndents[$i] = $currentIndent; $openScopes[$tokens[$i]['scope_closer']] = $tokens[$i]['scope_condition']; - if ($this->_debug === true) { + if ($this->debug === true) { $type = $tokens[$i]['type']; echo "\t=> indent set to $currentIndent by token $i ($type)".PHP_EOL; } @@ -1102,7 +1102,7 @@ class ScopeIndentSniff implements Sniff ) { $closer = $tokens[$i]['bracket_closer']; if ($tokens[$i]['line'] === $tokens[$closer]['line']) { - if ($this->_debug === true) { + if ($this->debug === true) { $line = $tokens[$i]['line']; echo "* ignoring single-line JS object on line $line".PHP_EOL; } @@ -1111,7 +1111,7 @@ class ScopeIndentSniff implements Sniff continue; } - if ($this->_debug === true) { + if ($this->debug === true) { $line = $tokens[$i]['line']; echo "Open JS object on line $line".PHP_EOL; } @@ -1126,7 +1126,7 @@ class ScopeIndentSniff implements Sniff $currentIndent = (int) (ceil($currentIndent / $this->indent) * $this->indent); $setIndents[$first] = $currentIndent; - if ($this->_debug === true) { + if ($this->debug === true) { $type = $tokens[$first]['type']; echo "\t=> indent set to $currentIndent by token $first ($type)".PHP_EOL; } @@ -1140,7 +1140,7 @@ class ScopeIndentSniff implements Sniff && ($tokens[$tokens[$i]['scope_condition']]['code'] === T_CLOSURE || $tokens[$tokens[$i]['scope_condition']]['code'] === T_ANON_CLASS) ) { - if ($this->_debug === true) { + if ($this->debug === true) { $type = str_replace('_', ' ', strtolower(substr($tokens[$tokens[$i]['scope_condition']]['type'], 2))); $line = $tokens[$i]['line']; echo "Close $type on line $line".PHP_EOL; @@ -1159,7 +1159,7 @@ class ScopeIndentSniff implements Sniff } } - if ($this->_debug === true && $object !== 0) { + if ($this->debug === true && $object !== 0) { $line = $tokens[$object]['line']; echo "\t* token is inside JS object $object on line $line *".PHP_EOL; } @@ -1171,7 +1171,7 @@ class ScopeIndentSniff implements Sniff ) { end($tokens[$i]['nested_parenthesis']); $parens = key($tokens[$i]['nested_parenthesis']); - if ($this->_debug === true) { + if ($this->debug === true) { $line = $tokens[$parens]['line']; echo "\t* token has nested parenthesis $parens on line $line *".PHP_EOL; } @@ -1183,7 +1183,7 @@ class ScopeIndentSniff implements Sniff ) { end($tokens[$i]['conditions']); $condition = key($tokens[$i]['conditions']); - if ($this->_debug === true) { + if ($this->debug === true) { $line = $tokens[$condition]['line']; $type = $tokens[$condition]['type']; echo "\t* token is inside condition $condition ($type) on line $line *".PHP_EOL; @@ -1191,7 +1191,7 @@ class ScopeIndentSniff implements Sniff } if ($parens > $object && $parens > $condition) { - if ($this->_debug === true) { + if ($this->debug === true) { echo "\t* using parenthesis *".PHP_EOL; } @@ -1199,7 +1199,7 @@ class ScopeIndentSniff implements Sniff $object = 0; $condition = 0; } else if ($object > 0 && $object >= $condition) { - if ($this->_debug === true) { + if ($this->debug === true) { echo "\t* using object *".PHP_EOL; } @@ -1207,7 +1207,7 @@ class ScopeIndentSniff implements Sniff $parens = 0; $condition = 0; } else if ($condition > 0) { - if ($this->_debug === true) { + if ($this->debug === true) { echo "\t* using condition *".PHP_EOL; } @@ -1217,23 +1217,23 @@ class ScopeIndentSniff implements Sniff }//end if if ($prev === false) { - $prev = $phpcsFile->findPrevious(array(T_EQUAL, T_RETURN), ($tokens[$i]['scope_condition'] - 1), null, false, null, true); + $prev = $phpcsFile->findPrevious([T_EQUAL, T_RETURN], ($tokens[$i]['scope_condition'] - 1), null, false, null, true); if ($prev === false) { $prev = $i; - if ($this->_debug === true) { + if ($this->debug === true) { echo "\t* could not find a previous T_EQUAL or T_RETURN token; will use current token *".PHP_EOL; } } } - if ($this->_debug === true) { + if ($this->debug === true) { $line = $tokens[$prev]['line']; $type = $tokens[$prev]['type']; echo "\t* previous token is $type on line $line *".PHP_EOL; } $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $prev, true); - if ($this->_debug === true) { + if ($this->debug === true) { $line = $tokens[$first]['line']; $type = $tokens[$first]['type']; echo "\t* first token on line $line is $first ($type) *".PHP_EOL; @@ -1242,14 +1242,14 @@ class ScopeIndentSniff implements Sniff $prev = $phpcsFile->findStartOfStatement($first); if ($prev !== $first) { // This is not the start of the statement. - if ($this->_debug === true) { + if ($this->debug === true) { $line = $tokens[$prev]['line']; $type = $tokens[$prev]['type']; echo "\t* amended previous is $type on line $line *".PHP_EOL; } $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $prev, true); - if ($this->_debug === true) { + if ($this->debug === true) { $line = $tokens[$first]['line']; $type = $tokens[$first]['type']; echo "\t* amended first token is $first ($type) on line $line *".PHP_EOL; @@ -1264,13 +1264,13 @@ class ScopeIndentSniff implements Sniff if (isset($tokens[$first]['scope_closer']) === true && $tokens[$first]['scope_closer'] === $first ) { - if ($this->_debug === true) { + if ($this->debug === true) { echo "\t* first token is a scope closer *".PHP_EOL; } if ($condition === 0 || $tokens[$condition]['scope_opener'] < $first) { $currentIndent = $setIndents[$first]; - } else if ($this->_debug === true) { + } else if ($this->debug === true) { echo "\t* ignoring scope closer *".PHP_EOL; } } @@ -1279,7 +1279,7 @@ class ScopeIndentSniff implements Sniff $currentIndent = (int) (ceil($currentIndent / $this->indent) * $this->indent); $setIndents[$first] = $currentIndent; - if ($this->_debug === true) { + if ($this->debug === true) { $type = $tokens[$first]['type']; echo "\t=> indent set to $currentIndent by token $first ($type)".PHP_EOL; } diff --git a/coder_sniffer/DrupalPractice/Project.php b/coder_sniffer/DrupalPractice/Project.php index 45923bcee150c914d2011363d948b0a26e8d8476..8b775bf8e6d4730618e8d9f0b94b78e362733d75 100644 --- a/coder_sniffer/DrupalPractice/Project.php +++ b/coder_sniffer/DrupalPractice/Project.php @@ -99,7 +99,7 @@ class Project } // Sort the info file names and take the shortest info file. - usort($infoFiles, array(__NAMESPACE__.'\Project', 'compareLength')); + usort($infoFiles, [__NAMESPACE__.'\Project', 'compareLength']); $infoFile = $infoFiles[0]; $cache[$phpcsFile->getFilename()] = $infoFile; return $infoFile; @@ -142,7 +142,7 @@ class Project } // Sort the YML file names and take the shortest info file. - usort($ymlFiles, array(__NAMESPACE__.'\Project', 'compareLength')); + usort($ymlFiles, [__NAMESPACE__.'\Project', 'compareLength']); $ymlFile = $ymlFiles[0]; $cache[$phpcsFile->getFilename()] = $ymlFile; return $ymlFile; @@ -189,9 +189,9 @@ class Project $nsEnd = $phpcsFile->findNext( [ - T_NS_SEPARATOR, - T_STRING, - T_WHITESPACE, + T_NS_SEPARATOR, + T_STRING, + T_WHITESPACE, ], ($namespacePtr + 1), null, @@ -248,9 +248,9 @@ class Project // Drupal 6 and 7 use the .info file extension. if ($pathParts['extension'] === 'info') { - $info_settings = ClassFilesSniff::drupalParseInfoFormat(file_get_contents($infoFile)); - if (isset($info_settings['core']) === true) { - return $info_settings['core']; + $infoSettings = ClassFilesSniff::drupalParseInfoFormat(file_get_contents($infoFile)); + if (isset($infoSettings['core']) === true) { + return $infoSettings['core']; } } else { // Drupal 8 uses the .yml file extension. diff --git a/coder_sniffer/DrupalPractice/Sniffs/CodeAnalysis/VariableAnalysisSniff.php b/coder_sniffer/DrupalPractice/Sniffs/CodeAnalysis/VariableAnalysisSniff.php index 6155951cb1a4931cde14f4d76beed036e3aabf74..3118e081f60e7187e2e7981dfd32a33f9788048d 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/CodeAnalysis/VariableAnalysisSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/CodeAnalysis/VariableAnalysisSniff.php @@ -29,7 +29,7 @@ class ScopeInfo public $owner; public $opener; public $closer; - public $variables = array(); + public $variables = []; /** @@ -37,7 +37,7 @@ class ScopeInfo * * @param int $currScope */ - function __construct($currScope) + public function __construct($currScope) { // TODO: extract opener/closer. $this->owner = $currScope; @@ -62,6 +62,8 @@ class VariableInfo public $name; /** * What scope the variable has: local, param, static, global, bound + * + * @var string */ public $scopeType; public $typeHint; @@ -72,13 +74,13 @@ class VariableInfo public $ignoreUnused = false; public $lastAssignment; - static $scopeTypeDescriptions = array( - 'local' => 'variable', - 'param' => 'function parameter', - 'static' => 'static variable', - 'global' => 'global variable', - 'bound' => 'bound variable', - ); + public static $scopeTypeDescriptions = [ + 'local' => 'variable', + 'param' => 'function parameter', + 'static' => 'static variable', + 'global' => 'global variable', + 'bound' => 'bound variable', + ]; /** @@ -86,7 +88,7 @@ class VariableInfo * * @param string $varName */ - function __construct($varName) + public function __construct($varName) { $this->name = $varName; @@ -113,469 +115,483 @@ class VariableAnalysisSniff implements Sniff /** * The current phpcsFile being checked. * - * @var phpcsFile + * @var File */ protected $currentFile = null; /** * A list of scopes encountered so far and the variables within them. + * + * @var array */ - private $_scopes = array(); + private $scopes = []; /** * A regexp for matching variable names in double-quoted strings. + * + * @var string */ - private $_double_quoted_variable_regexp = '|(?<!\\\\)(?:\\\\{2})*\${?([a-zA-Z0-9_]+)}?|'; + private $doubleQuotedVariableRegexp = '|(?<!\\\\)(?:\\\\{2})*\${?([a-zA-Z0-9_]+)}?|'; /** * Array of known pass-by-reference functions and the argument(s) which are passed * by reference, the arguments are numbered starting from 1 and an elipsis '...' * means all argument numbers after the previous should be considered pass-by-reference. + * + * @var array */ - private $_passByRefFunctions = array( - '__soapCall' => array(5), - 'addFunction' => array(3), - 'addTask' => array(3), - 'addTaskBackground' => array(3), - 'addTaskHigh' => array(3), - 'addTaskHighBackground' => array(3), - 'addTaskLow' => array(3), - 'addTaskLowBackground' => array(3), - 'addTaskStatus' => array(2), - 'apc_dec' => array(3), - 'apc_fetch' => array(2), - 'apc_inc' => array(3), - 'areConfusable' => array(3), - 'array_multisort' => array(1), - 'array_pop' => array(1), - 'array_push' => array(1), - 'array_replace' => array(1), - 'array_replace_recursive' => array( - 1, - 2, - 3, - '...', - ), - 'array_shift' => array(1), - 'array_splice' => array(1), - 'array_unshift' => array(1), - 'array_walk' => array(1), - 'array_walk_recursive' => array(1), - 'arsort' => array(1), - 'asort' => array(1), - 'asort' => array(1), - 'bindColumn' => array(2), - 'bindParam' => array(2), - 'bind_param' => array( - 2, - 3, - '...', - ), - 'bind_result' => array( - 1, - 2, - '...', - ), - 'call_user_method' => array(2), - 'call_user_method_array' => array(2), - 'curl_multi_exec' => array(2), - 'curl_multi_info_read' => array(2), - 'current' => array(1), - 'dbplus_curr' => array(2), - 'dbplus_first' => array(2), - 'dbplus_info' => array(3), - 'dbplus_last' => array(2), - 'dbplus_next' => array(2), - 'dbplus_prev' => array(2), - 'dbplus_tremove' => array(3), - 'dns_get_record' => array( - 3, - 4, - ), - 'domxml_open_file' => array(3), - 'domxml_open_mem' => array(3), - 'each' => array(1), - 'enchant_dict_quick_check' => array(3), - 'end' => array(1), - 'ereg' => array(3), - 'eregi' => array(3), - 'exec' => array( - 2, - 3, - ), - 'exif_thumbnail' => array( - 1, - 2, - 3, - ), - 'expect_expectl' => array(3), - 'extract' => array(1), - 'filter' => array(3), - 'flock' => array( - 2, - 3, - ), - 'fscanf' => array( - 2, - 3, - '...', - ), - 'fsockopen' => array( - 3, - 4, - ), - 'ftp_alloc' => array(3), - 'get' => array( - 2, - 3, - ), - 'getByKey' => array(4), - 'getMulti' => array(2), - 'getMultiByKey' => array(3), - 'getimagesize' => array(2), - 'getmxrr' => array( - 2, - 3, - ), - 'gnupg_decryptverify' => array(3), - 'gnupg_verify' => array(4), - 'grapheme_extract' => array(5), - 'headers_sent' => array( - 1, - 2, - ), - 'http_build_url' => array(4), - 'http_get' => array(3), - 'http_head' => array(3), - 'http_negotiate_charset' => array(2), - 'http_negotiate_content_type' => array(2), - 'http_negotiate_language' => array(2), - 'http_post_data' => array(4), - 'http_post_fields' => array(5), - 'http_put_data' => array(4), - 'http_put_file' => array(4), - 'http_put_stream' => array(4), - 'http_request' => array(5), - 'isSuspicious' => array(2), - 'is_callable' => array(3), - 'key' => array(1), - 'krsort' => array(1), - 'ksort' => array(1), - 'ldap_get_option' => array(3), - 'ldap_parse_reference' => array(3), - 'ldap_parse_result' => array( - 3, - 4, - 5, - 6, - ), - 'localtime' => array(2), - 'm_completeauthorizations' => array(2), - 'maxdb_stmt_bind_param' => array( - 3, - 4, - '...', - ), - 'maxdb_stmt_bind_result' => array( - 2, - 3, - '...', - ), - 'mb_convert_variables' => array( - 3, - 4, - '...', - ), - 'mb_parse_str' => array(2), - 'mqseries_back' => array( - 2, - 3, - ), - 'mqseries_begin' => array( - 3, - 4, - ), - 'mqseries_close' => array( - 4, - 5, - ), - 'mqseries_cmit' => array( - 2, - 3, - ), - 'mqseries_conn' => array( - 2, - 3, - 4, - ), - 'mqseries_connx' => array( - 2, - 3, - 4, - 5, - ), - 'mqseries_disc' => array( - 2, - 3, - ), - 'mqseries_get' => array( - 3, - 4, - 5, - 6, - 7, - 8, - 9, - ), - 'mqseries_inq' => array( - 6, - 8, - 9, - 10, - ), - 'mqseries_open' => array( - 2, - 4, - 5, - 6, - ), - 'mqseries_put' => array( - 3, - 4, - 6, - 7, - ), - 'mqseries_put1' => array( - 2, - 3, - 4, - 6, - 7, - ), - 'mqseries_set' => array( - 9, - 10, - ), - 'msg_receive' => array( - 3, - 5, - 8, - ), - 'msg_send' => array(6), - 'mssql_bind' => array(3), - 'natcasesort' => array(1), - 'natsort' => array(1), - 'ncurses_color_content' => array( - 2, - 3, - 4, - ), - 'ncurses_getmaxyx' => array( - 2, - 3, - ), - 'ncurses_getmouse' => array(1), - 'ncurses_getyx' => array( - 2, - 3, - ), - 'ncurses_instr' => array(1), - 'ncurses_mouse_trafo' => array( - 1, - 2, - ), - 'ncurses_mousemask' => array(2), - 'ncurses_pair_content' => array( - 2, - 3, - ), - 'ncurses_wmouse_trafo' => array( - 2, - 3, - ), - 'newt_button_bar' => array(1), - 'newt_form_run' => array(2), - 'newt_get_screen_size' => array( - 1, - 2, - ), - 'newt_grid_get_size' => array( - 2, - 3, - ), - 'newt_reflow_text' => array( - 5, - 6, - ), - 'newt_win_entries' => array(7), - 'newt_win_menu' => array(8), - 'next' => array(1), - 'oci_bind_array_by_name' => array(3), - 'oci_bind_by_name' => array(3), - 'oci_define_by_name' => array(3), - 'oci_fetch_all' => array(2), - 'ocifetchinto' => array(2), - 'odbc_fetch_into' => array(2), - 'openssl_csr_export' => array(2), - 'openssl_csr_new' => array(2), - 'openssl_open' => array(2), - 'openssl_pkcs12_export' => array(2), - 'openssl_pkcs12_read' => array(2), - 'openssl_pkey_export' => array(2), - 'openssl_private_decrypt' => array(2), - 'openssl_private_encrypt' => array(2), - 'openssl_public_decrypt' => array(2), - 'openssl_public_encrypt' => array(2), - 'openssl_random_pseudo_bytes' => array(2), - 'openssl_seal' => array( - 2, - 3, - ), - 'openssl_sign' => array(2), - 'openssl_x509_export' => array(2), - 'ovrimos_fetch_into' => array(2), - 'parse' => array( - 2, - 3, - ), - 'parseCurrency' => array( - 2, - 3, - ), - 'parse_str' => array(2), - 'parsekit_compile_file' => array(2), - 'parsekit_compile_string' => array(2), - 'passthru' => array(2), - 'pcntl_sigprocmask' => array(3), - 'pcntl_sigtimedwait' => array(2), - 'pcntl_sigwaitinfo' => array(2), - 'pcntl_wait' => array(1), - 'pcntl_waitpid' => array(2), - 'pfsockopen' => array( - 3, - 4, - ), - 'php_check_syntax' => array(2), - 'poll' => array( - 1, - 2, - 3, - ), - 'preg_filter' => array(5), - 'preg_match' => array(3), - 'preg_match_all' => array(3), - 'preg_replace' => array(5), - 'preg_replace_callback' => array(5), - 'prev' => array(1), - 'proc_open' => array(3), - 'query' => array(3), - 'queryExec' => array(2), - 'reset' => array(1), - 'rsort' => array(1), - 'settype' => array(1), - 'shuffle' => array(1), - 'similar_text' => array(3), - 'socket_create_pair' => array(4), - 'socket_getpeername' => array( - 2, - 3, - ), - 'socket_getsockname' => array( - 2, - 3, - ), - 'socket_recv' => array(2), - 'socket_recvfrom' => array( - 2, - 5, - 6, - ), - 'socket_select' => array( - 1, - 2, - 3, - ), - 'sort' => array(1), - 'sortWithSortKeys' => array(1), - 'sqlite_exec' => array(3), - 'sqlite_factory' => array(3), - 'sqlite_open' => array(3), - 'sqlite_popen' => array(3), - 'sqlite_query' => array(4), - 'sqlite_query' => array(4), - 'sqlite_unbuffered_query' => array(4), - 'sscanf' => array( - 3, - '...', - ), - 'str_ireplace' => array(4), - 'str_replace' => array(4), - 'stream_open' => array(4), - 'stream_select' => array( - 1, - 2, - 3, - ), - 'stream_socket_accept' => array(3), - 'stream_socket_client' => array( - 2, - 3, - ), - 'stream_socket_recvfrom' => array(4), - 'stream_socket_server' => array( - 2, - 3, - ), - 'system' => array(2), - 'uasort' => array(1), - 'uksort' => array(1), - 'unbufferedQuery' => array(3), - 'usort' => array(1), - 'wincache_ucache_dec' => array(3), - 'wincache_ucache_get' => array(2), - 'wincache_ucache_inc' => array(3), - 'xdiff_string_merge3' => array(4), - 'xdiff_string_patch' => array(4), - 'xml_parse_into_struct' => array( - 3, - 4, - ), - 'xml_set_object' => array(2), - 'xmlrpc_decode_request' => array(2), - 'xmlrpc_set_type' => array(1), - 'xslt_set_object' => array(2), - 'yaml_parse' => array(3), - 'yaml_parse_file' => array(3), - 'yaml_parse_url' => array(3), - 'yaz_ccl_parse' => array(3), - 'yaz_hits' => array(2), - 'yaz_scan_result' => array(2), - 'yaz_wait' => array(1), - ); + private $passByRefFunctions = [ + '__soapCall' => [5], + 'addFunction' => [3], + 'addTask' => [3], + 'addTaskBackground' => [3], + 'addTaskHigh' => [3], + 'addTaskHighBackground' => [3], + 'addTaskLow' => [3], + 'addTaskLowBackground' => [3], + 'addTaskStatus' => [2], + 'apc_dec' => [3], + 'apc_fetch' => [2], + 'apc_inc' => [3], + 'areConfusable' => [3], + 'array_multisort' => [1], + 'array_pop' => [1], + 'array_push' => [1], + 'array_replace' => [1], + 'array_replace_recursive' => [ + 1, + 2, + 3, + '...', + ], + 'array_shift' => [1], + 'array_splice' => [1], + 'array_unshift' => [1], + 'array_walk' => [1], + 'array_walk_recursive' => [1], + 'arsort' => [1], + 'asort' => [1], + 'asort' => [1], + 'bindColumn' => [2], + 'bindParam' => [2], + 'bind_param' => [ + 2, + 3, + '...', + ], + 'bind_result' => [ + 1, + 2, + '...', + ], + 'call_user_method' => [2], + 'call_user_method_array' => [2], + 'curl_multi_exec' => [2], + 'curl_multi_info_read' => [2], + 'current' => [1], + 'dbplus_curr' => [2], + 'dbplus_first' => [2], + 'dbplus_info' => [3], + 'dbplus_last' => [2], + 'dbplus_next' => [2], + 'dbplus_prev' => [2], + 'dbplus_tremove' => [3], + 'dns_get_record' => [ + 3, + 4, + ], + 'domxml_open_file' => [3], + 'domxml_open_mem' => [3], + 'each' => [1], + 'enchant_dict_quick_check' => [3], + 'end' => [1], + 'ereg' => [3], + 'eregi' => [3], + 'exec' => [ + 2, + 3, + ], + 'exif_thumbnail' => [ + 1, + 2, + 3, + ], + 'expect_expectl' => [3], + 'extract' => [1], + 'filter' => [3], + 'flock' => [ + 2, + 3, + ], + 'fscanf' => [ + 2, + 3, + '...', + ], + 'fsockopen' => [ + 3, + 4, + ], + 'ftp_alloc' => [3], + 'get' => [ + 2, + 3, + ], + 'getByKey' => [4], + 'getMulti' => [2], + 'getMultiByKey' => [3], + 'getimagesize' => [2], + 'getmxrr' => [ + 2, + 3, + ], + 'gnupg_decryptverify' => [3], + 'gnupg_verify' => [4], + 'grapheme_extract' => [5], + 'headers_sent' => [ + 1, + 2, + ], + 'http_build_url' => [4], + 'http_get' => [3], + 'http_head' => [3], + 'http_negotiate_charset' => [2], + 'http_negotiate_content_type' => [2], + 'http_negotiate_language' => [2], + 'http_post_data' => [4], + 'http_post_fields' => [5], + 'http_put_data' => [4], + 'http_put_file' => [4], + 'http_put_stream' => [4], + 'http_request' => [5], + 'isSuspicious' => [2], + 'is_callable' => [3], + 'key' => [1], + 'krsort' => [1], + 'ksort' => [1], + 'ldap_get_option' => [3], + 'ldap_parse_reference' => [3], + 'ldap_parse_result' => [ + 3, + 4, + 5, + 6, + ], + 'localtime' => [2], + 'm_completeauthorizations' => [2], + 'maxdb_stmt_bind_param' => [ + 3, + 4, + '...', + ], + 'maxdb_stmt_bind_result' => [ + 2, + 3, + '...', + ], + 'mb_convert_variables' => [ + 3, + 4, + '...', + ], + 'mb_parse_str' => [2], + 'mqseries_back' => [ + 2, + 3, + ], + 'mqseries_begin' => [ + 3, + 4, + ], + 'mqseries_close' => [ + 4, + 5, + ], + 'mqseries_cmit' => [ + 2, + 3, + ], + 'mqseries_conn' => [ + 2, + 3, + 4, + ], + 'mqseries_connx' => [ + 2, + 3, + 4, + 5, + ], + 'mqseries_disc' => [ + 2, + 3, + ], + 'mqseries_get' => [ + 3, + 4, + 5, + 6, + 7, + 8, + 9, + ], + 'mqseries_inq' => [ + 6, + 8, + 9, + 10, + ], + 'mqseries_open' => [ + 2, + 4, + 5, + 6, + ], + 'mqseries_put' => [ + 3, + 4, + 6, + 7, + ], + 'mqseries_put1' => [ + 2, + 3, + 4, + 6, + 7, + ], + 'mqseries_set' => [ + 9, + 10, + ], + 'msg_receive' => [ + 3, + 5, + 8, + ], + 'msg_send' => [6], + 'mssql_bind' => [3], + 'natcasesort' => [1], + 'natsort' => [1], + 'ncurses_color_content' => [ + 2, + 3, + 4, + ], + 'ncurses_getmaxyx' => [ + 2, + 3, + ], + 'ncurses_getmouse' => [1], + 'ncurses_getyx' => [ + 2, + 3, + ], + 'ncurses_instr' => [1], + 'ncurses_mouse_trafo' => [ + 1, + 2, + ], + 'ncurses_mousemask' => [2], + 'ncurses_pair_content' => [ + 2, + 3, + ], + 'ncurses_wmouse_trafo' => [ + 2, + 3, + ], + 'newt_button_bar' => [1], + 'newt_form_run' => [2], + 'newt_get_screen_size' => [ + 1, + 2, + ], + 'newt_grid_get_size' => [ + 2, + 3, + ], + 'newt_reflow_text' => [ + 5, + 6, + ], + 'newt_win_entries' => [7], + 'newt_win_menu' => [8], + 'next' => [1], + 'oci_bind_array_by_name' => [3], + 'oci_bind_by_name' => [3], + 'oci_define_by_name' => [3], + 'oci_fetch_all' => [2], + 'ocifetchinto' => [2], + 'odbc_fetch_into' => [2], + 'openssl_csr_export' => [2], + 'openssl_csr_new' => [2], + 'openssl_open' => [2], + 'openssl_pkcs12_export' => [2], + 'openssl_pkcs12_read' => [2], + 'openssl_pkey_export' => [2], + 'openssl_private_decrypt' => [2], + 'openssl_private_encrypt' => [2], + 'openssl_public_decrypt' => [2], + 'openssl_public_encrypt' => [2], + 'openssl_random_pseudo_bytes' => [2], + 'openssl_seal' => [ + 2, + 3, + ], + 'openssl_sign' => [2], + 'openssl_x509_export' => [2], + 'ovrimos_fetch_into' => [2], + 'parse' => [ + 2, + 3, + ], + 'parseCurrency' => [ + 2, + 3, + ], + 'parse_str' => [2], + 'parsekit_compile_file' => [2], + 'parsekit_compile_string' => [2], + 'passthru' => [2], + 'pcntl_sigprocmask' => [3], + 'pcntl_sigtimedwait' => [2], + 'pcntl_sigwaitinfo' => [2], + 'pcntl_wait' => [1], + 'pcntl_waitpid' => [2], + 'pfsockopen' => [ + 3, + 4, + ], + 'php_check_syntax' => [2], + 'poll' => [ + 1, + 2, + 3, + ], + 'preg_filter' => [5], + 'preg_match' => [3], + 'preg_match_all' => [3], + 'preg_replace' => [5], + 'preg_replace_callback' => [5], + 'prev' => [1], + 'proc_open' => [3], + 'query' => [3], + 'queryExec' => [2], + 'reset' => [1], + 'rsort' => [1], + 'settype' => [1], + 'shuffle' => [1], + 'similar_text' => [3], + 'socket_create_pair' => [4], + 'socket_getpeername' => [ + 2, + 3, + ], + 'socket_getsockname' => [ + 2, + 3, + ], + 'socket_recv' => [2], + 'socket_recvfrom' => [ + 2, + 5, + 6, + ], + 'socket_select' => [ + 1, + 2, + 3, + ], + 'sort' => [1], + 'sortWithSortKeys' => [1], + 'sqlite_exec' => [3], + 'sqlite_factory' => [3], + 'sqlite_open' => [3], + 'sqlite_popen' => [3], + 'sqlite_query' => [4], + 'sqlite_query' => [4], + 'sqlite_unbuffered_query' => [4], + 'sscanf' => [ + 3, + '...', + ], + 'str_ireplace' => [4], + 'str_replace' => [4], + 'stream_open' => [4], + 'stream_select' => [ + 1, + 2, + 3, + ], + 'stream_socket_accept' => [3], + 'stream_socket_client' => [ + 2, + 3, + ], + 'stream_socket_recvfrom' => [4], + 'stream_socket_server' => [ + 2, + 3, + ], + 'system' => [2], + 'uasort' => [1], + 'uksort' => [1], + 'unbufferedQuery' => [3], + 'usort' => [1], + 'wincache_ucache_dec' => [3], + 'wincache_ucache_get' => [2], + 'wincache_ucache_inc' => [3], + 'xdiff_string_merge3' => [4], + 'xdiff_string_patch' => [4], + 'xml_parse_into_struct' => [ + 3, + 4, + ], + 'xml_set_object' => [2], + 'xmlrpc_decode_request' => [2], + 'xmlrpc_set_type' => [1], + 'xslt_set_object' => [2], + 'yaml_parse' => [3], + 'yaml_parse_file' => [3], + 'yaml_parse_url' => [3], + 'yaz_ccl_parse' => [3], + 'yaz_hits' => [2], + 'yaz_scan_result' => [2], + 'yaz_wait' => [1], + ]; /** * Allows an install to extend the list of known pass-by-reference functions * by defining generic.codeanalysis.variableanalysis.sitePassByRefFunctions. + * + * @var string */ - public $sitePassByRefFunctions = null; + public $sitePassByRefFunctions = ''; /** * Allows exceptions in a catch block to be unused without provoking unused-var warning. * Set generic.codeanalysis.variableanalysis.allowUnusedCaughtExceptions to a true value. + * + * @var boolean */ public $allowUnusedCaughtExceptions = true; /** * Allow function parameters to be unused without provoking unused-var warning. * Set generic.codeanalysis.variableanalysis.allowUnusedFunctionParameters to a true value. + * + * @var boolean */ public $allowUnusedFunctionParameters = true; /** * A list of names of placeholder variables that you want to ignore from * unused variable warnings, ie things like $junk. + * + * @var string */ - public $validUnusedVariableNames = null; + public $validUnusedVariableNames = ''; /** @@ -585,11 +601,11 @@ class VariableAnalysisSniff implements Sniff */ public function register() { - // Magic to modfy $_passByRefFunctions with any site-specific settings. + // Magic to modfy $passByRefFunctions with any site-specific settings. if (empty($this->sitePassByRefFunctions) === false) { foreach (preg_split('/\s+/', trim($this->sitePassByRefFunctions)) as $line) { list ($function, $args) = explode(':', $line); - $this->_passByRefFunctions[$function] = explode(',', $args); + $this->passByRefFunctions[$function] = explode(',', $args); } } @@ -597,13 +613,13 @@ class VariableAnalysisSniff implements Sniff $this->validUnusedVariableNames = preg_split('/\s+/', trim($this->validUnusedVariableNames)); } - return array( - T_VARIABLE, - T_DOUBLE_QUOTED_STRING, - T_HEREDOC, - T_CLOSE_CURLY_BRACKET, - T_STRING, - ); + return [ + T_VARIABLE, + T_DOUBLE_QUOTED_STRING, + T_HEREDOC, + T_CLOSE_CURLY_BRACKET, + T_STRING, + ]; }//end register() @@ -661,7 +677,7 @@ class VariableAnalysisSniff implements Sniff * * @return string */ - function normalizeVarName($varName) + public function normalizeVarName($varName) { $varName = preg_replace('/[{}$]/', '', $varName); return $varName; @@ -676,7 +692,7 @@ class VariableAnalysisSniff implements Sniff * * @return string */ - function scopeKey($currScope) + public function scopeKey($currScope) { if ($currScope === false) { $currScope = 'file'; @@ -699,18 +715,18 @@ class VariableAnalysisSniff implements Sniff * * @return ScopeInfo */ - function getScopeInfo($currScope, $autoCreate = true) + public function getScopeInfo($currScope, $autoCreate=true) { $scopeKey = $this->scopeKey($currScope); - if (isset($this->_scopes[$scopeKey]) === false) { + if (isset($this->scopes[$scopeKey]) === false) { if ($autoCreate === false) { return null; } - $this->_scopes[$scopeKey] = new ScopeInfo($currScope); + $this->scopes[$scopeKey] = new ScopeInfo($currScope); } - return $this->_scopes[$scopeKey]; + return $this->scopes[$scopeKey]; }//end getScopeInfo() @@ -728,7 +744,7 @@ class VariableAnalysisSniff implements Sniff * @return VariableInfo|null * Information about the variable. */ - function getVariableInfo($varName, $currScope, $autoCreate = true) + public function getVariableInfo($varName, $currScope, $autoCreate=true) { $scopeInfo = $this->getScopeInfo($currScope, $autoCreate); if (isset($scopeInfo->variables[$varName]) === false) { @@ -758,7 +774,7 @@ class VariableAnalysisSniff implements Sniff * * @return void */ - function markVariableAssignment($varName, $stackPtr, $currScope) + public function markVariableAssignment($varName, $stackPtr, $currScope) { $varInfo = $this->getVariableInfo($varName, $currScope); if (isset($varInfo->scopeType) === false) { @@ -787,7 +803,7 @@ class VariableAnalysisSniff implements Sniff * * @return void */ - function markVariableDeclaration($varName, $scopeType, $typeHint, $stackPtr, $currScope, $permitMatchingRedeclaration = false) + public function markVariableDeclaration($varName, $scopeType, $typeHint, $stackPtr, $currScope, $permitMatchingRedeclaration=false) { $varInfo = $this->getVariableInfo($varName, $currScope); if (isset($varInfo->scopeType) === true) { @@ -802,11 +818,11 @@ class VariableAnalysisSniff implements Sniff "Redeclaration of %s %s as %s.", $stackPtr, 'VariableRedeclaration', - array( - VariableInfo::$scopeTypeDescriptions[$varInfo->scopeType], - "\${$varName}", - VariableInfo::$scopeTypeDescriptions[$scopeType], - ) + [ + VariableInfo::$scopeTypeDescriptions[$varInfo->scopeType], + "\${$varName}", + VariableInfo::$scopeTypeDescriptions[$scopeType], + ] ); } } @@ -840,7 +856,7 @@ class VariableAnalysisSniff implements Sniff * * @return void */ - function markVariableRead($varName, $stackPtr, $currScope) + public function markVariableRead($varName, $stackPtr, $currScope) { $varInfo = $this->getVariableInfo($varName, $currScope); if (isset($varInfo->firstRead) === true && ($varInfo->firstRead <= $stackPtr)) { @@ -861,7 +877,7 @@ class VariableAnalysisSniff implements Sniff * * @return bool */ - function isVariableInitialized($varName, $stackPtr, $currScope) + public function isVariableInitialized($varName, $stackPtr, $currScope) { $varInfo = $this->getVariableInfo($varName, $currScope); if (isset($varInfo->firstInitialized) === true && $varInfo->firstInitialized <= $stackPtr) { @@ -882,7 +898,7 @@ class VariableAnalysisSniff implements Sniff * * @return bool */ - function isVariableUndefined($varName, $stackPtr, $currScope) + public function isVariableUndefined($varName, $stackPtr, $currScope) { $varInfo = $this->getVariableInfo($varName, $currScope, false); if (isset($varInfo->firstDeclared) === true && $varInfo->firstDeclared <= $stackPtr) { @@ -909,7 +925,7 @@ class VariableAnalysisSniff implements Sniff * * @return bool */ - function markVariableReadAndWarnIfUndefined(File $phpcsFile, $varName, $stackPtr, $currScope) + public function markVariableReadAndWarnIfUndefined(File $phpcsFile, $varName, $stackPtr, $currScope) { $this->markVariableRead($varName, $stackPtr, $currScope); @@ -919,7 +935,7 @@ class VariableAnalysisSniff implements Sniff "Variable %s is undefined.", $stackPtr, 'UndefinedVariable', - array("\${$varName}") + ["\${$varName}"] ); } @@ -936,7 +952,7 @@ class VariableAnalysisSniff implements Sniff * * @return int|false */ - function findFunctionPrototype(File $phpcsFile, $stackPtr) + public function findFunctionPrototype(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -949,11 +965,11 @@ class VariableAnalysisSniff implements Sniff // isn't a function name, reference sigil or whitespace and check if // it's a function keyword. $functionPtr = $phpcsFile->findPrevious( - array( - T_STRING, - T_WHITESPACE, - T_BITWISE_AND, - ), + [ + T_STRING, + T_WHITESPACE, + T_BITWISE_AND, + ], ($openPtr - 1), null, true, @@ -979,7 +995,7 @@ class VariableAnalysisSniff implements Sniff * * @return int|false */ - function findVariableScope(File $phpcsFile, $stackPtr) + public function findVariableScope(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $token = $tokens[$stackPtr]; @@ -1020,7 +1036,7 @@ class VariableAnalysisSniff implements Sniff * * @return bool */ - function isNextThingAnAssign(File $phpcsFile, $stackPtr) + public function isNextThingAnAssign(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -1051,7 +1067,7 @@ class VariableAnalysisSniff implements Sniff * * @return int */ - function findWhereAssignExecuted(File $phpcsFile, $stackPtr) + public function findWhereAssignExecuted(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -1095,7 +1111,7 @@ class VariableAnalysisSniff implements Sniff * * @return int|false */ - function findContainingBrackets(File $phpcsFile, $stackPtr) + public function findContainingBrackets(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -1117,7 +1133,7 @@ class VariableAnalysisSniff implements Sniff * * @return int|false */ - function findFunctionCall(File $phpcsFile, $stackPtr) + public function findFunctionCall(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -1149,7 +1165,7 @@ class VariableAnalysisSniff implements Sniff * * @return array|false */ - function findFunctionCallArguments(File $phpcsFile, $stackPtr) + public function findFunctionCallArguments(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -1181,7 +1197,7 @@ class VariableAnalysisSniff implements Sniff $closePtr = $tokens[$openPtr]['parenthesis_closer']; - $argPtrs = array(); + $argPtrs = []; $lastPtr = $openPtr; $lastArgComma = $openPtr; while (($nextPtr = $phpcsFile->findNext(T_COMMA, ($lastPtr + 1), $closePtr)) !== false) { @@ -1232,11 +1248,11 @@ class VariableAnalysisSniff implements Sniff // isn't a function name, reference sigil or whitespace and check if // it's a function keyword. $functionPtr = $phpcsFile->findPrevious( - array( - T_STRING, - T_WHITESPACE, - T_BITWISE_AND, - ), + [ + T_STRING, + T_WHITESPACE, + T_BITWISE_AND, + ], ($openPtr - 1), null, true, @@ -1280,7 +1296,7 @@ class VariableAnalysisSniff implements Sniff "Variable %s is undefined.", $stackPtr, 'UndefinedVariable', - array("\${$varName}") + ["\${$varName}"] ); return true; } @@ -1434,19 +1450,19 @@ class VariableAnalysisSniff implements Sniff // Are we a superglobal variable? if (in_array( $varName, - array( - 'GLOBALS', - '_SERVER', - '_GET', - '_POST', - '_FILES', - '_COOKIE', - '_SESSION', - '_REQUEST', - '_ENV', - 'argv', - 'argc', - ) + [ + 'GLOBALS', + '_SERVER', + '_GET', + '_POST', + '_FILES', + '_COOKIE', + '_SESSION', + '_REQUEST', + '_ENV', + 'argv', + 'argc', + ] ) === true ) { return true; @@ -1496,11 +1512,11 @@ class VariableAnalysisSniff implements Sniff || ($tokens[$classNamePtr]['code'] === T_STATIC) ) { if ($tokens[$classNamePtr]['code'] === T_SELF) { - $err_class = 'SelfOutsideClass'; - $err_desc = 'self::'; + $errClass = 'SelfOutsideClass'; + $errDesc = 'self::'; } else { - $err_class = 'StaticOutsideClass'; - $err_desc = 'static::'; + $errClass = 'StaticOutsideClass'; + $errDesc = 'static::'; } if (empty($token['conditions']) === false) { @@ -1509,10 +1525,10 @@ class VariableAnalysisSniff implements Sniff // Note: have to fetch code from $tokens, T_CLOSURE isn't set for conditions codes. if ($tokens[$scopePtr]['code'] === T_CLOSURE) { $phpcsFile->addError( - "Use of {$err_desc}%s inside closure.", + "Use of {$errDesc}%s inside closure.", $stackPtr, - $err_class, - array("\${$varName}") + $errClass, + ["\${$varName}"] ); return true; } @@ -1524,10 +1540,10 @@ class VariableAnalysisSniff implements Sniff } $phpcsFile->addError( - "Use of {$err_desc}%s outside class definition.", + "Use of {$errDesc}%s outside class definition.", $stackPtr, - $err_class, - array("\${$varName}") + $errClass, + ["\${$varName}"] ); return true; }//end if @@ -1643,11 +1659,11 @@ class VariableAnalysisSniff implements Sniff // Are we a global declaration? // Search backwards for first token that isn't whitespace, comma or variable. $globalPtr = $phpcsFile->findPrevious( - array( - T_WHITESPACE, - T_VARIABLE, - T_COMMA, - ), + [ + T_WHITESPACE, + T_VARIABLE, + T_COMMA, + ], ($stackPtr - 1), null, true, @@ -1707,24 +1723,24 @@ class VariableAnalysisSniff implements Sniff // Search backwards for first token that isn't whitespace, comma, variable, // equals, or on the list of assignable constant values above. $staticPtr = $phpcsFile->findPrevious( - array( - T_WHITESPACE, - T_VARIABLE, - T_COMMA, - T_EQUAL, - T_MINUS, - T_LNUMBER, - T_DNUMBER, - T_CONSTANT_ENCAPSED_STRING, - T_STRING, - T_DOUBLE_COLON, - T_START_HEREDOC, - T_HEREDOC, - T_END_HEREDOC, - T_START_NOWDOC, - T_NOWDOC, - T_END_NOWDOC, - ), + [ + T_WHITESPACE, + T_VARIABLE, + T_COMMA, + T_EQUAL, + T_MINUS, + T_LNUMBER, + T_DNUMBER, + T_CONSTANT_ENCAPSED_STRING, + T_STRING, + T_DOUBLE_COLON, + T_START_HEREDOC, + T_HEREDOC, + T_END_HEREDOC, + T_START_NOWDOC, + T_NOWDOC, + T_END_NOWDOC, + ], ($stackPtr - 1), null, true, @@ -1839,11 +1855,11 @@ class VariableAnalysisSniff implements Sniff // Is our function a known pass-by-reference function? $functionName = $tokens[$functionPtr]['content']; - if (isset($this->_passByRefFunctions[$functionName]) === false) { + if (isset($this->passByRefFunctions[$functionName]) === false) { return false; } - $refArgs = $this->_passByRefFunctions[$functionName]; + $refArgs = $this->passByRefFunctions[$functionName]; if (($argPtrs = $this->findFunctionCallArguments($phpcsFile, $stackPtr)) === false) { return false; @@ -2079,15 +2095,12 @@ class VariableAnalysisSniff implements Sniff * * @return void */ - protected function processVariableInString( - File - $phpcsFile, - $stackPtr - ) { + protected function processVariableInString(File $phpcsFile, $stackPtr) + { $tokens = $phpcsFile->getTokens(); $token = $tokens[$stackPtr]; - $runMatch = preg_match_all($this->_double_quoted_variable_regexp, $token['content'], $matches); + $runMatch = preg_match_all($this->doubleQuotedVariableRegexp, $token['content'], $matches); if ($runMatch === 0 || $runMatch === false) { return; } @@ -2120,13 +2133,8 @@ class VariableAnalysisSniff implements Sniff * * @return void */ - protected function processCompactArguments( - File - $phpcsFile, - $stackPtr, - $arguments, - $currScope - ) { + protected function processCompactArguments(File $phpcsFile, $stackPtr, $arguments, $currScope) + { $tokens = $phpcsFile->getTokens(); foreach ($arguments as $argumentPtrs) { @@ -2171,7 +2179,7 @@ class VariableAnalysisSniff implements Sniff if ($argument_first_token['code'] === T_DOUBLE_QUOTED_STRING) { // Double-quoted string literal. - if (preg_match($this->_double_quoted_variable_regexp, $argument_first_token['content']) === 1) { + if (preg_match($this->doubleQuotedVariableRegexp, $argument_first_token['content']) === 1) { // Bail if the string needs variable expansion, that's runtime stuff. continue; } @@ -2196,11 +2204,8 @@ class VariableAnalysisSniff implements Sniff * * @return void */ - protected function processCompact( - File - $phpcsFile, - $stackPtr - ) { + protected function processCompact(File $phpcsFile, $stackPtr) + { $tokens = $phpcsFile->getTokens(); $token = $tokens[$stackPtr]; @@ -2225,13 +2230,10 @@ class VariableAnalysisSniff implements Sniff * * @return void */ - protected function processScopeClose( - File - $phpcsFile, - $stackPtr - ) { + protected function processScopeClose(File $phpcsFile, $stackPtr) + { $scopeInfo = $this->getScopeInfo($stackPtr, false); - if (is_null($scopeInfo) === true) { + if ($scopeInfo === null) { return; } @@ -2257,20 +2259,20 @@ class VariableAnalysisSniff implements Sniff "Unused %s %s.", $varInfo->firstDeclared, 'UnusedVariable', - array( - VariableInfo::$scopeTypeDescriptions[$varInfo->scopeType], - "\${$varInfo->name}", - ) + [ + VariableInfo::$scopeTypeDescriptions[$varInfo->scopeType], + "\${$varInfo->name}", + ] ); } else if (isset($varInfo->firstInitialized) === true) { $phpcsFile->addWarning( "Unused %s %s.", $varInfo->firstInitialized, 'UnusedVariable', - array( - VariableInfo::$scopeTypeDescriptions[$varInfo->scopeType], - "\${$varInfo->name}", - ) + [ + VariableInfo::$scopeTypeDescriptions[$varInfo->scopeType], + "\${$varInfo->name}", + ] ); }//end if }//end foreach diff --git a/coder_sniffer/DrupalPractice/Sniffs/Commenting/AuthorTagSniff.php b/coder_sniffer/DrupalPractice/Sniffs/Commenting/AuthorTagSniff.php index df78d6df195c76469a2a109bd7d24c60324c6d00..178dd8d88a65834f6b4868bfbd1ecf10fa685372 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/Commenting/AuthorTagSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/Commenting/AuthorTagSniff.php @@ -30,7 +30,7 @@ class AuthorTagSniff implements Sniff */ public function register() { - return array(T_DOC_COMMENT_TAG); + return [T_DOC_COMMENT_TAG]; }//end register() diff --git a/coder_sniffer/DrupalPractice/Sniffs/Commenting/CommentEmptyLineSniff.php b/coder_sniffer/DrupalPractice/Sniffs/Commenting/CommentEmptyLineSniff.php index 0cb4e96e0f3647a86022c551b473ee5b9e96885a..f2c2bf6c9f6671ba8426bc7f8298e9e36bff5caa 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/Commenting/CommentEmptyLineSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/Commenting/CommentEmptyLineSniff.php @@ -31,7 +31,7 @@ class CommentEmptyLineSniff implements Sniff */ public function register() { - return array(T_COMMENT); + return [T_COMMENT]; }//end register() diff --git a/coder_sniffer/DrupalPractice/Sniffs/Commenting/ExpectedExceptionSniff.php b/coder_sniffer/DrupalPractice/Sniffs/Commenting/ExpectedExceptionSniff.php index e1a85e10ffc58a407cbaa8ddbe9fe8000701695a..61a831b2e73ce83cca676d07b53b52832f6e64ac 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/Commenting/ExpectedExceptionSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/Commenting/ExpectedExceptionSniff.php @@ -32,7 +32,7 @@ class ExpectedExceptionSniff implements Sniff */ public function register() { - return array(T_DOC_COMMENT_TAG); + return [T_DOC_COMMENT_TAG]; }//end register() diff --git a/coder_sniffer/DrupalPractice/Sniffs/Constants/GlobalConstantSniff.php b/coder_sniffer/DrupalPractice/Sniffs/Constants/GlobalConstantSniff.php index 9e40e495fed489fec347cc27b3cac541134ff0a8..57bbb773a54f70eed291efc511741ffb95218d1b 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/Constants/GlobalConstantSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/Constants/GlobalConstantSniff.php @@ -31,7 +31,7 @@ class GlobalConstantSniff implements Sniff */ public function register() { - return array(T_CONST); + return [T_CONST]; }//end register() diff --git a/coder_sniffer/DrupalPractice/Sniffs/Constants/GlobalDefineSniff.php b/coder_sniffer/DrupalPractice/Sniffs/Constants/GlobalDefineSniff.php index 20fb979b5877192d7d88d540d60ef27869d6e597..1b07328f49553764e34b2e378383ddc73e63cc73 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/Constants/GlobalDefineSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/Constants/GlobalDefineSniff.php @@ -31,7 +31,7 @@ class GlobalDefineSniff extends FunctionCall */ public function registerFunctionNames() { - return array('define'); + return ['define']; }//end registerFunctionNames() diff --git a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/CheckPlainSniff.php b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/CheckPlainSniff.php index 438a3833f325638c9ab5fafcd742b2bfd4f8bcba..ecc07e720991d776c3b7750949d6b2a90fbf783a 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/CheckPlainSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/CheckPlainSniff.php @@ -30,7 +30,7 @@ class CheckPlainSniff extends FunctionCall */ public function registerFunctionNames() { - return array('check_plain'); + return ['check_plain']; }//end registerFunctionNames() diff --git a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/CurlSslVerifierSniff.php b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/CurlSslVerifierSniff.php index 14bc814f14fe13cd26fd99a1ed4257c36e66f04f..5fa07cfc9b09dcb50f22a4764cffa2b2258da72a 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/CurlSslVerifierSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/CurlSslVerifierSniff.php @@ -31,7 +31,7 @@ class CurlSslVerifierSniff extends FunctionCall */ public function registerFunctionNames() { - return array('curl_setopt'); + return ['curl_setopt']; }//end registerFunctionNames() diff --git a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/DbQuerySniff.php b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/DbQuerySniff.php index e08a5291ee7e7450530d4db7c6091880c90d029d..de75c18561d5d7642bcff4af24c5bf7be2fca915 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/DbQuerySniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/DbQuerySniff.php @@ -31,7 +31,7 @@ class DbQuerySniff extends FunctionCall */ public function registerFunctionNames() { - return array('db_query'); + return ['db_query']; }//end registerFunctionNames() @@ -63,17 +63,17 @@ class DbQuerySniff extends FunctionCall $tokens = $phpcsFile->getTokens(); $argument = $this->getArgument(1); - $query_start = ''; - for ($start = $argument['start']; $tokens[$start]['code'] === T_CONSTANT_ENCAPSED_STRING && empty($query_start) === true; $start++) { + $queryStart = ''; + for ($start = $argument['start']; $tokens[$start]['code'] === T_CONSTANT_ENCAPSED_STRING && empty($queryStart) === true; $start++) { // Remove quote and white space from the beginning. - $query_start = trim(substr($tokens[$start]['content'], 1)); + $queryStart = trim(substr($tokens[$start]['content'], 1)); // Just look at the first word. - $parts = explode(' ', $query_start); - $query_start = $parts[0]; + $parts = explode(' ', $queryStart); + $queryStart = $parts[0]; - if (in_array(strtoupper($query_start), array('INSERT', 'UPDATE', 'DELETE', 'TRUNCATE')) === true) { + if (in_array(strtoupper($queryStart), ['INSERT', 'UPDATE', 'DELETE', 'TRUNCATE']) === true) { $warning = 'Do not use %s queries with db_query(), use %s instead'; - $phpcsFile->addWarning($warning, $start, 'DbQuery', array($query_start, 'db_'.strtolower($query_start).'()')); + $phpcsFile->addWarning($warning, $start, 'DbQuery', [$queryStart, 'db_'.strtolower($queryStart).'()']); } } diff --git a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/DbSelectBracesSniff.php b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/DbSelectBracesSniff.php index fe9704d0e84510088086fbab0b27ba3ecd1975a4..beeee36f3b794125281540448933bbb8e81fadf5 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/DbSelectBracesSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/DbSelectBracesSniff.php @@ -30,7 +30,7 @@ class DbSelectBracesSniff extends FunctionCall */ public function registerFunctionNames() { - return array('db_select'); + return ['db_select']; }//end registerFunctionNames() diff --git a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/DefaultValueSanitizeSniff.php b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/DefaultValueSanitizeSniff.php index 227c1860907cb16f81f7cbf55e80fdbfa1e7947d..f83c55f882a83bceef4871b67f4a1be71b45dcd2 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/DefaultValueSanitizeSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/DefaultValueSanitizeSniff.php @@ -32,13 +32,13 @@ class DefaultValueSanitizeSniff extends FunctionCall */ public function registerFunctionNames() { - return array( - 'check_markup', - 'check_plain', - 'check_url', - 'filter_xss', - 'filter_xss_admin', - ); + return [ + 'check_markup', + 'check_plain', + 'check_url', + 'filter_xss', + 'filter_xss_admin', + ]; }//end registerFunctionNames() @@ -80,7 +80,7 @@ class DefaultValueSanitizeSniff extends FunctionCall } $warning = 'Do not use the %s() sanitization function on Form API #default_value elements, they get escaped automatically'; - $data = array($tokens[$stackPtr]['content']); + $data = [$tokens[$stackPtr]['content']]; $phpcsFile->addWarning($warning, $stackPtr, 'DefaultValue', $data); }//end processFunctionCall() diff --git a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/FormErrorTSniff.php b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/FormErrorTSniff.php index b0bacc3b1e9648d16ac4fd4c509f6b1d1b47e55a..46645429f8d0d4ce2de10c15df488f0acf63a560 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/FormErrorTSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/FormErrorTSniff.php @@ -30,10 +30,10 @@ class FormErrorTSniff extends FunctionCall */ public function registerFunctionNames() { - return array( - 'form_set_error', - 'form_error', - ); + return [ + 'form_set_error', + 'form_error', + ]; }//end registerFunctionNames() diff --git a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/LCheckPlainSniff.php b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/LCheckPlainSniff.php index 815fc436cc6ed095034defae877fc57955ba6011..143968c28ab88468ba2ad186e5c003bc5ed87c99 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/LCheckPlainSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/LCheckPlainSniff.php @@ -30,7 +30,7 @@ class LCheckPlainSniff extends FunctionCall */ public function registerFunctionNames() { - return array('l'); + return ['l']; }//end registerFunctionNames() diff --git a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/MessageTSniff.php b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/MessageTSniff.php index bf4ac9e6b27b9694b12f8768c0f40fdb7d3698a0..429b25dde8fb8d33a496cf175bf964bc4a68011e 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/MessageTSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/MessageTSniff.php @@ -30,7 +30,7 @@ class MessageTSniff extends FunctionCall */ public function registerFunctionNames() { - return array('drupal_set_message'); + return ['drupal_set_message']; }//end registerFunctionNames() diff --git a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/TCheckPlainSniff.php b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/TCheckPlainSniff.php index 8e7e37bbf187ad840324e0d7a33262139438a9b1..5e0fed34f5ecc469852f43cec2781f3ece3729e0 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/TCheckPlainSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/TCheckPlainSniff.php @@ -31,10 +31,10 @@ class TCheckPlainSniff extends FunctionCall */ public function registerFunctionNames() { - return array( - 't', - 'watchdog', - ); + return [ + 't', + 'watchdog', + ]; }//end registerFunctionNames() diff --git a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/ThemeSniff.php b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/ThemeSniff.php index 1339c4ab368d3a66ddd45a5f7158df4c8fd6867e..0d46528d47699d678bfc79715257b02f66dad453 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/ThemeSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/ThemeSniff.php @@ -27,14 +27,14 @@ class ThemeSniff extends FunctionCall * * @var array */ - protected $reservedFunctions = array( - 'theme_get_registry', - 'theme_get_setting', - 'theme_render_template', - 'theme_enable', - 'theme_disable', - 'theme_get_suggestions', - ); + protected $reservedFunctions = [ + 'theme_get_registry', + 'theme_get_setting', + 'theme_render_template', + 'theme_enable', + 'theme_disable', + 'theme_get_suggestions', + ]; /** @@ -59,7 +59,7 @@ class ThemeSniff extends FunctionCall $themeName = substr($functionName, 6); $warning = "Do not call theme functions directly, use theme('%s', ...) instead"; - $phpcsFile->addWarning($warning, $stackPtr, 'ThemeFunctionDirect', array($themeName)); + $phpcsFile->addWarning($warning, $stackPtr, 'ThemeFunctionDirect', [$themeName]); }//end process() diff --git a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/VariableSetSanitizeSniff.php b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/VariableSetSanitizeSniff.php index 60937a23e486a2f3982b162c43cba01932d81a62..fd3101be1b8403b9f999ee7f051b0cd31133652f 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/VariableSetSanitizeSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/VariableSetSanitizeSniff.php @@ -31,7 +31,7 @@ class VariableSetSanitizeSniff extends FunctionCall */ public function registerFunctionNames() { - return array('variable_set'); + return ['variable_set']; }//end registerFunctionNames() @@ -60,17 +60,17 @@ class VariableSetSanitizeSniff extends FunctionCall $argument = $this->getArgument(2); if ($argument !== false && in_array( $tokens[$argument['start']]['content'], - array( - 'check_markup', - 'check_plain', - 'check_url', - 'filter_xss', - 'filter_xss_admin', - ) + [ + 'check_markup', + 'check_plain', + 'check_url', + 'filter_xss', + 'filter_xss_admin', + ] ) === true ) { $warning = 'Do not use the %s() sanitization function when writing values to the database, use it on output to HTML instead'; - $data = array($tokens[$argument['start']]['content']); + $data = [$tokens[$argument['start']]['content']]; $phpcsFile->addWarning($warning, $argument['start'], 'VariableSet', $data); } diff --git a/coder_sniffer/DrupalPractice/Sniffs/FunctionDefinitions/AccessHookMenuSniff.php b/coder_sniffer/DrupalPractice/Sniffs/FunctionDefinitions/AccessHookMenuSniff.php index c4cedb29adc1991a501cae1244968dbc1538596d..d226441e6c32cfb96f113a034304c8b4fb9aaf4e 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/FunctionDefinitions/AccessHookMenuSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/FunctionDefinitions/AccessHookMenuSniff.php @@ -57,18 +57,18 @@ class AccessHookMenuSniff extends FunctionDefinition ); while ($string !== false) { if (substr($tokens[$string]['content'], 1, -1) === 'access callback') { - $array_operator = $phpcsFile->findNext( + $arrayOperator = $phpcsFile->findNext( Tokens::$emptyTokens, ($string + 1), null, true ); - if ($array_operator !== false - && $tokens[$array_operator]['code'] === T_DOUBLE_ARROW + if ($arrayOperator !== false + && $tokens[$arrayOperator]['code'] === T_DOUBLE_ARROW ) { $callback = $phpcsFile->findNext( Tokens::$emptyTokens, - ($array_operator + 1), + ($arrayOperator + 1), null, true ); diff --git a/coder_sniffer/DrupalPractice/Sniffs/FunctionDefinitions/FormAlterDocSniff.php b/coder_sniffer/DrupalPractice/Sniffs/FunctionDefinitions/FormAlterDocSniff.php index 746c57d5a77f5f9f5933ee7a83d3450d496c191f..5eb5282dcc130d3feeed4d98421211ed259d70ad 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/FunctionDefinitions/FormAlterDocSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/FunctionDefinitions/FormAlterDocSniff.php @@ -68,10 +68,10 @@ class FormAlterDocSniff extends FunctionDefinition if ($tokens[$stackPtr]['content'] !== $projectName.'_form_alter') { $warning = 'Doc comment indicates hook_form_alter() but function signature is "%s" instead of "%s". Did you mean hook_form_FORM_ID_alter()?'; - $data = array( - $tokens[$stackPtr]['content'], - $projectName.'_form_alter', - ); + $data = [ + $tokens[$stackPtr]['content'], + $projectName.'_form_alter', + ]; $phpcsFile->addWarning($warning, $commentLine, 'Different', $data); } diff --git a/coder_sniffer/DrupalPractice/Sniffs/FunctionDefinitions/HookInitCssSniff.php b/coder_sniffer/DrupalPractice/Sniffs/FunctionDefinitions/HookInitCssSniff.php index 51347fb81c1f10d8120fe4bb52307d0dd9612d5b..7fe3634dea7a03608d5b6bf02f17569564dbae29 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/FunctionDefinitions/HookInitCssSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/FunctionDefinitions/HookInitCssSniff.php @@ -74,10 +74,10 @@ class HookInitCssSniff extends FunctionDefinition ) { if ($tokens[$stackPtr]['content'] === ($fileName.'_init')) { $warning = 'Do not use %s() in hook_init(), use #attached for CSS and JS in your page/form callback or in hook_page_build() instead'; - $phpcsFile->addWarning($warning, $string, 'AddFunctionFound', array($tokens[$string]['content'])); + $phpcsFile->addWarning($warning, $string, 'AddFunctionFound', [$tokens[$string]['content']]); } else { $warning = 'Do not use %s() in hook_page_build(), use #attached for CSS and JS on the $page render array instead'; - $phpcsFile->addWarning($warning, $string, 'AddFunctionFoundPageBuild', array($tokens[$string]['content'])); + $phpcsFile->addWarning($warning, $string, 'AddFunctionFoundPageBuild', [$tokens[$string]['content']]); } } } diff --git a/coder_sniffer/DrupalPractice/Sniffs/General/ClassNameSniff.php b/coder_sniffer/DrupalPractice/Sniffs/General/ClassNameSniff.php index 51b45c80695bda770138b708f8553acdb7c4162a..7949b60e5c496f9a0835c823113330e45d007b56 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/General/ClassNameSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/General/ClassNameSniff.php @@ -32,10 +32,10 @@ class ClassNameSniff implements Sniff */ public function register() { - return array( - T_CLASS, - T_INTERFACE, - ); + return [ + T_CLASS, + T_INTERFACE, + ]; }//end register() @@ -83,10 +83,10 @@ class ClassNameSniff implements Sniff $camelName .= ucfirst($part); } - $errorData = array( - ucfirst($tokens[$stackPtr]['content']), - $camelName, - ); + $errorData = [ + ucfirst($tokens[$stackPtr]['content']), + $camelName, + ]; $phpcsFile->addWarning($warning, $className, 'ClassPrefix', $errorData); } diff --git a/coder_sniffer/DrupalPractice/Sniffs/General/DescriptionTSniff.php b/coder_sniffer/DrupalPractice/Sniffs/General/DescriptionTSniff.php index 3ba9d105675982320a2973c2d4b6ca5693eef276..4a2b4326ad08e2ce5261affc48b6430b548ceed1 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/General/DescriptionTSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/General/DescriptionTSniff.php @@ -30,7 +30,7 @@ class DescriptionTSniff implements Sniff */ public function register() { - return array(T_CONSTANT_ENCAPSED_STRING); + return [T_CONSTANT_ENCAPSED_STRING]; }//end register() diff --git a/coder_sniffer/DrupalPractice/Sniffs/General/FormStateInputSniff.php b/coder_sniffer/DrupalPractice/Sniffs/General/FormStateInputSniff.php index 86fdec86a30ba42061ac2a57ace4b1f0fe2816c6..8400048ee4dbcd24d0920e4890ca97c92268f77b 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/General/FormStateInputSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/General/FormStateInputSniff.php @@ -31,7 +31,7 @@ class FormStateInputSniff implements Sniff */ public function register() { - return array(T_VARIABLE); + return [T_VARIABLE]; }//end register() diff --git a/coder_sniffer/DrupalPractice/Sniffs/General/LanguageNoneSniff.php b/coder_sniffer/DrupalPractice/Sniffs/General/LanguageNoneSniff.php index 642742a9fefb2411fc4698c97dbf33e4623add40..5f123a47d608352727a89c2909fa763e2e27052b 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/General/LanguageNoneSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/General/LanguageNoneSniff.php @@ -30,10 +30,10 @@ class LanguageNoneSniff implements Sniff */ public function register() { - return array( - T_OPEN_SQUARE_BRACKET, - T_OPEN_SHORT_ARRAY, - ); + return [ + T_OPEN_SQUARE_BRACKET, + T_OPEN_SHORT_ARRAY, + ]; }//end register() diff --git a/coder_sniffer/DrupalPractice/Sniffs/General/OptionsTSniff.php b/coder_sniffer/DrupalPractice/Sniffs/General/OptionsTSniff.php index 74b4d3c8bd6aebabadca80d005f8c7b8a4ff0bac..f3b8cd82f0aab17a36cf2190efb6565320a43240 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/General/OptionsTSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/General/OptionsTSniff.php @@ -30,7 +30,7 @@ class OptionsTSniff implements Sniff */ public function register() { - return array(T_CONSTANT_ENCAPSED_STRING); + return [T_CONSTANT_ENCAPSED_STRING]; }//end register() diff --git a/coder_sniffer/DrupalPractice/Sniffs/General/VariableNameSniff.php b/coder_sniffer/DrupalPractice/Sniffs/General/VariableNameSniff.php index b8b38e36188491488f0821558f185fbd94593500..93eebbff404f05dfcde5f6012049f05563dd9613 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/General/VariableNameSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/General/VariableNameSniff.php @@ -32,7 +32,7 @@ class VariableNameSniff extends FunctionCall */ public function registerFunctionNames() { - return array('variable_get'); + return ['variable_get']; }//end registerFunctionNames() @@ -88,10 +88,10 @@ class VariableNameSniff extends FunctionCall $variableName = substr($tokens[$argument['start']]['content'], 1, -1); if (strpos($variableName, $moduleName) !== 0) { $warning = 'All variables defined by your module must be prefixed with your module\'s name to avoid name collisions with others. Expected start with "%s" but found "%s"'; - $data = array( - $moduleName, - $variableName, - ); + $data = [ + $moduleName, + $variableName, + ]; $phpcsFile->addWarning($warning, $argument['start'], 'VariableName', $data); } diff --git a/coder_sniffer/DrupalPractice/Sniffs/InfoFiles/NamespacedDependencySniff.php b/coder_sniffer/DrupalPractice/Sniffs/InfoFiles/NamespacedDependencySniff.php index d571017bf5e81edafeb02265dd42ace517838bde..3825e16f6efff36282bf1090bbc98bb0924a9cb3 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/InfoFiles/NamespacedDependencySniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/InfoFiles/NamespacedDependencySniff.php @@ -31,7 +31,7 @@ class NamespacedDependencySniff implements Sniff */ public function register() { - return array(T_INLINE_HTML); + return [T_INLINE_HTML]; }//end register() diff --git a/coder_sniffer/DrupalPractice/Sniffs/Objects/GlobalClassSniff.php b/coder_sniffer/DrupalPractice/Sniffs/Objects/GlobalClassSniff.php index e93542a50792f252a00aaacc7ff75aaa53063d92..bc6cc6e21e52c99b3c28491ccf29faff8e54d2d2 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/Objects/GlobalClassSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/Objects/GlobalClassSniff.php @@ -29,14 +29,14 @@ class GlobalClassSniff implements Sniff * * @var string[] */ - protected $classes = array( - 'File', - 'Node', - 'NodeType', - 'Role', - 'Term', - 'User', - ); + protected $classes = [ + 'File', + 'Node', + 'NodeType', + 'Role', + 'Term', + 'User', + ]; /** @@ -46,7 +46,7 @@ class GlobalClassSniff implements Sniff */ public function register() { - return array(T_STRING); + return [T_STRING]; }//end register() @@ -70,7 +70,7 @@ class GlobalClassSniff implements Sniff || $tokens[($stackPtr + 1)]['code'] !== T_DOUBLE_COLON || isset($tokens[($stackPtr + 2)]) === false || $tokens[($stackPtr + 2)]['code'] !== T_STRING - || in_array($tokens[($stackPtr + 2)]['content'], array('load', 'loadMultiple')) === false + || in_array($tokens[($stackPtr + 2)]['content'], ['load', 'loadMultiple']) === false || isset($tokens[($stackPtr + 3)]) === false || $tokens[($stackPtr + 3)]['code'] !== T_OPEN_PARENTHESIS || empty($tokens[$stackPtr]['conditions']) === true @@ -98,10 +98,10 @@ class GlobalClassSniff implements Sniff } $warning = '%s::%s calls should be avoided in classes, use dependency injection instead'; - $data = array( - $tokens[$stackPtr]['content'], - $tokens[($stackPtr + 2)]['content'], - ); + $data = [ + $tokens[$stackPtr]['content'], + $tokens[($stackPtr + 2)]['content'], + ]; $phpcsFile->addWarning($warning, $stackPtr, 'GlobalClass', $data); }//end process() diff --git a/coder_sniffer/DrupalPractice/Sniffs/Objects/GlobalDrupalSniff.php b/coder_sniffer/DrupalPractice/Sniffs/Objects/GlobalDrupalSniff.php index ee2eda4b293092f0f8af57d0092dbccf8bb67f80..473d2e8514558d098155d00e553b5bf986bef575 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/Objects/GlobalDrupalSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/Objects/GlobalDrupalSniff.php @@ -28,20 +28,20 @@ class GlobalDrupalSniff implements Sniff * * @var string[] */ - public static $baseClasses = array( - 'BlockBase', - 'ConfigFormBase', - 'ContentEntityForm', - 'ControllerBase', - 'EntityForm', - 'EntityReferenceFormatterBase', - 'FileFormatterBase', - 'FormatterBase', - 'FormBase', - 'ImageFormatter', - 'ImageFormatterBase', - 'WidgetBase', - ); + public static $baseClasses = [ + 'BlockBase', + 'ConfigFormBase', + 'ContentEntityForm', + 'ControllerBase', + 'EntityForm', + 'EntityReferenceFormatterBase', + 'FileFormatterBase', + 'FormatterBase', + 'FormBase', + 'ImageFormatter', + 'ImageFormatterBase', + 'WidgetBase', + ]; /** @@ -51,7 +51,7 @@ class GlobalDrupalSniff implements Sniff */ public function register() { - return array(T_STRING); + return [T_STRING]; }//end register() diff --git a/coder_sniffer/DrupalPractice/Sniffs/Objects/GlobalFunctionSniff.php b/coder_sniffer/DrupalPractice/Sniffs/Objects/GlobalFunctionSniff.php index 969d1c808ad1dab7af42d99cb4e60340409ce821..8ae275bd4fb32f4fd7229b73a19bd5de3c1ab83a 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/Objects/GlobalFunctionSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/Objects/GlobalFunctionSniff.php @@ -29,21 +29,21 @@ class GlobalFunctionSniff implements Sniff * * @var string[] */ - protected $functions = array( - 'drupal_get_destination' => 'the "redirect.destination" service', - 'drupal_render' => 'the "renderer" service', - 'entity_load' => 'the "entity_type.manager" service', - 'file_load' => 'the "entity_type.manager" service', - 'format_date' => 'the "date.formatter" service', - 'node_load' => 'the "entity_type.manager" service', - 'node_load_multiple' => 'the "entity_type.manager" service', - 'node_type_load' => 'the "entity_type.manager" service', - 't' => '$this->t()', - 'taxonomy_term_load' => 'the "entity_type.manager" service', - 'taxonomy_vocabulary_load' => 'the "entity_type.manager" service', - 'user_load' => 'the "entity_type.manager" service', - 'user_role_load' => 'the "entity_type.manager" service', - ); + protected $functions = [ + 'drupal_get_destination' => 'the "redirect.destination" service', + 'drupal_render' => 'the "renderer" service', + 'entity_load' => 'the "entity_type.manager" service', + 'file_load' => 'the "entity_type.manager" service', + 'format_date' => 'the "date.formatter" service', + 'node_load' => 'the "entity_type.manager" service', + 'node_load_multiple' => 'the "entity_type.manager" service', + 'node_type_load' => 'the "entity_type.manager" service', + 't' => '$this->t()', + 'taxonomy_term_load' => 'the "entity_type.manager" service', + 'taxonomy_vocabulary_load' => 'the "entity_type.manager" service', + 'user_load' => 'the "entity_type.manager" service', + 'user_role_load' => 'the "entity_type.manager" service', + ]; /** @@ -53,7 +53,7 @@ class GlobalFunctionSniff implements Sniff */ public function register() { - return array(T_STRING); + return [T_STRING]; }//end register() @@ -108,10 +108,10 @@ class GlobalFunctionSniff implements Sniff } $warning = '%s() calls should be avoided in classes, use dependency injection and %s instead'; - $data = array( - $tokens[$stackPtr]['content'], - $this->functions[$tokens[$stackPtr]['content']], - ); + $data = [ + $tokens[$stackPtr]['content'], + $this->functions[$tokens[$stackPtr]['content']], + ]; $phpcsFile->addWarning($warning, $stackPtr, 'GlobalFunction', $data); }//end process() diff --git a/coder_sniffer/DrupalPractice/Sniffs/Objects/StrictSchemaDisabledSniff.php b/coder_sniffer/DrupalPractice/Sniffs/Objects/StrictSchemaDisabledSniff.php index e1eb2ca2fb9426b7d7549939add2d2b45a70c5f5..3e9e8d4115b8413db6621eab9cadbc089e89f138 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/Objects/StrictSchemaDisabledSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/Objects/StrictSchemaDisabledSniff.php @@ -42,12 +42,12 @@ class StrictSchemaDisabledSniff extends AbstractVariableSniff $tokens = $phpcsFile->getTokens(); if (($tokens[$stackPtr]['content'] === static::STRICT_CONFIG_SCHEMA_NAME) && ($this->isTestClass($phpcsFile, $stackPtr) === true)) { - $find = array( - T_FALSE, - T_TRUE, - T_NULL, - T_SEMICOLON, - ); + $find = [ + T_FALSE, + T_TRUE, + T_NULL, + T_SEMICOLON, + ]; $next = $phpcsFile->findNext($find, ($stackPtr + 1)); // If this variable is being set, the only allowed value is TRUE. // Otherwise if FALSE or NULL, schema checking is disabled. diff --git a/coder_sniffer/DrupalPractice/Sniffs/Yaml/RoutingAccessSniff.php b/coder_sniffer/DrupalPractice/Sniffs/Yaml/RoutingAccessSniff.php index 7ca3619545ef61d6eacd02d849efc9afe18d0009..e866fa7f8e11c494828ae69f2137f3fab06d3c32 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/Yaml/RoutingAccessSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/Yaml/RoutingAccessSniff.php @@ -33,7 +33,7 @@ class RoutingAccessSniff implements Sniff */ public function register() { - return array(T_INLINE_HTML); + return [T_INLINE_HTML]; }//end register() diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 0e340b15a6aab494447019ffcf89deed6829dd63..264087f9bc46255846456af876605e7fc2987c01 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -1,90 +1,162 @@ <?xml version="1.0"?> <ruleset name="drupal_coder"> - <description>The coding standard for coder_sniffer.</description> - - <file>coder_sniffer</file> - - <exclude-pattern>*/Test/*</exclude-pattern> - - <!-- The following comes from the 2.9 PHPCS ruleset.xml { --> - - <!-- Include the whole PEAR standard --> - <rule ref="PEAR"/> - - <!-- Include some sniffs from other standards that don't conflict with PEAR --> - <rule ref="Squiz.Arrays.ArrayBracketSpacing" /> - <rule ref="Squiz.Arrays.ArrayDeclaration" /> - <rule ref="Squiz.Commenting.ClosingDeclarationComment" /> - <rule ref="Squiz.ControlStructures.ElseIfDeclaration" /> - <rule ref="Squiz.Commenting.BlockComment" /> - <rule ref="Squiz.Commenting.DocCommentAlignment" /> - <rule ref="Squiz.Commenting.EmptyCatchComment" /> - <rule ref="Squiz.Commenting.InlineComment" /> - <rule ref="Squiz.Commenting.LongConditionClosingComment" /> - <rule ref="Squiz.Commenting.PostStatementComment" /> - <rule ref="Squiz.Formatting.OperatorBracket" /> - <rule ref="Squiz.Operators.ComparisonOperatorUsage" /> - <rule ref="Squiz.PHP.DisallowInlineIf" /> - <rule ref="Squiz.Strings.ConcatenationSpacing" /> - <rule ref="Squiz.WhiteSpace.ControlStructureSpacing" /> - <rule ref="Squiz.WhiteSpace.FunctionClosingBraceSpace" /> - <rule ref="Squiz.WhiteSpace.FunctionSpacing" /> - <rule ref="Squiz.WhiteSpace.OperatorSpacing" /> - <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace" /> - <rule ref="Generic.Commenting.Todo"/> - <rule ref="Generic.ControlStructures.InlineControlStructure"/> - <rule ref="Generic.Formatting.DisallowMultipleStatements"/> - <rule ref="Generic.Formatting.SpaceAfterCast"/> - <rule ref="Generic.NamingConventions.ConstructorName"/> - <rule ref="Generic.PHP.DeprecatedFunctions"/> - <rule ref="Generic.PHP.LowerCaseKeyword"/> - <rule ref="Generic.Strings.UnnecessaryStringConcat"/> - <rule ref="PSR2.Files.EndFileNewline"/> - <rule ref="Zend.Files.ClosingTag"/> - - <!-- Only one argument per line in multi-line function calls --> - <rule ref="PEAR.Functions.FunctionCallSignature"> - <properties> - <property name="allowMultipleArguments" value="false"/> - </properties> - </rule> - - <!-- Have 12 chars padding maximum and always show as errors --> - <rule ref="Generic.Formatting.MultipleStatementAlignment"> - <properties> - <property name="maxPadding" value="12"/> - <property name="error" value="true"/> - </properties> - </rule> - - <!-- } End of original PHPCS ruleset.xml --> - - <!-- The following sniffs are disabled because we don't want them --> - <rule ref="PEAR.Commenting.FileComment"> - <exclude name="PEAR.Commenting.FileComment.MissingAuthorTag"/> - <exclude name="PEAR.Commenting.FileComment.MissingLicenseTag"/> - <exclude name="PEAR.Commenting.FileComment.MissingVersion"/> - </rule> - <rule ref="PEAR.Commenting.ClassComment"> - <exclude name="PEAR.Commenting.ClassComment.CategoryTagOrder"/> - <exclude name="PEAR.Commenting.ClassComment.MissingAuthorTag"/> - <exclude name="PEAR.Commenting.ClassComment.MissingLicenseTag"/> - </rule> - <rule ref="PEAR.NamingConventions.ValidFunctionName"> - <exclude name="PEAR.NamingConventions.ValidFunctionName.PrivateNoUnderscore"/> - </rule> - <rule ref="Generic.Files.LineLength"> - <exclude name="Generic.Files.LineLength.TooLong"/> - </rule> - <rule ref="Generic.Commenting.Todo"> - <exclude name="Generic.Commenting.Todo.TaskFound"/> - <exclude name="Generic.Commenting.Todo.CommentFound"/> - </rule> - - <!-- The following sniffs are disabled because Coder is not compliant yet, see - https://www.drupal.org/node/2734539 --> - <rule ref="PEAR.Commenting.FunctionComment.MissingParamComment"> - <exclude-pattern>*/DrupalPractice/Sniffs/CodeAnalysis/VariableAnalysisSniff.php</exclude-pattern> - </rule> + <description>The coding standard for coder_sniffer.</description> + + <file>coder_sniffer</file> + + <exclude-pattern>*/Test/*</exclude-pattern> + + <!-- The following comes from the 3.4.2 PHPCS ruleset.xml { --> + + <!-- Don't hide tokenizer exceptions --> + <rule ref="Internal.Tokenizer.Exception"> + <type>error</type> + </rule> + + <!-- Include the whole PEAR standard --> + <rule ref="PEAR"> + <exclude name="PEAR.NamingConventions.ValidFunctionName"/> + <exclude name="PEAR.NamingConventions.ValidVariableName"/> + <exclude name="PEAR.Commenting.ClassComment"/> + <exclude name="PEAR.Commenting.FileComment.MissingCategoryTag"/> + <exclude name="PEAR.Commenting.FileComment.MissingPackageTag"/> + <exclude name="PEAR.Commenting.FileComment.MissingLinkTag"/> + <exclude name="PEAR.Commenting.FileComment.MissingVersion"/> + <exclude name="PEAR.Commenting.InlineComment"/> + </rule> + + <!-- Include some sniffs from other standards that don't conflict with PEAR --> + <rule ref="Squiz.Arrays.ArrayBracketSpacing"/> + <rule ref="Squiz.Arrays.ArrayDeclaration"/> + <rule ref="Squiz.Commenting.ClosingDeclarationComment"/> + <rule ref="Squiz.ControlStructures.ControlSignature"/> + <rule ref="Squiz.ControlStructures.ElseIfDeclaration"/> + <rule ref="Squiz.Commenting.BlockComment"/> + <rule ref="Squiz.Commenting.DocCommentAlignment"/> + <rule ref="Squiz.Commenting.EmptyCatchComment"/> + <rule ref="Squiz.Commenting.InlineComment"/> + <rule ref="Squiz.Commenting.LongConditionClosingComment"/> + <rule ref="Squiz.Commenting.PostStatementComment"/> + <rule ref="Squiz.Commenting.VariableComment"/> + <rule ref="Squiz.Formatting.OperatorBracket"/> + <rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing"/> + <rule ref="Squiz.Operators.ComparisonOperatorUsage"/> + <rule ref="Squiz.PHP.DisallowInlineIf"/> + <rule ref="Squiz.Scope.MethodScope"/> + <rule ref="Squiz.Strings.ConcatenationSpacing"/> + <rule ref="Squiz.WhiteSpace.ControlStructureSpacing"/> + <rule ref="Squiz.WhiteSpace.FunctionClosingBraceSpace"/> + <rule ref="Squiz.WhiteSpace.FunctionSpacing"/> + <rule ref="Squiz.WhiteSpace.OperatorSpacing"/> + <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace"/> + <rule ref="Generic.Arrays.DisallowLongArraySyntax"/> + <rule ref="Generic.Commenting.Todo"/> + <rule ref="Generic.ControlStructures.InlineControlStructure"/> + <rule ref="Generic.Formatting.DisallowMultipleStatements"/> + <rule ref="Generic.Formatting.SpaceAfterCast"/> + <rule ref="Generic.NamingConventions.ConstructorName"/> + <rule ref="Generic.PHP.DeprecatedFunctions"/> + <rule ref="Generic.PHP.LowerCaseKeyword"/> + <rule ref="Generic.Strings.UnnecessaryStringConcat"/> + <rule ref="Generic.WhiteSpace.IncrementDecrementSpacing"/> + <rule ref="PSR2.Classes.PropertyDeclaration"/> + <rule ref="PSR2.Methods.MethodDeclaration"/> + <rule ref="PSR2.Files.EndFileNewline"/> + <rule ref="Zend.Files.ClosingTag"/> + + <!-- PEAR uses warnings for inline control structures, so switch back to errors --> + <rule ref="Generic.ControlStructures.InlineControlStructure"> + <properties> + <property name="error" value="true"/> + </properties> + </rule> + + <!-- We use custom indent rules for arrays --> + <rule ref="Generic.Arrays.ArrayIndent"/> + <rule ref="Squiz.Arrays.ArrayDeclaration.KeyNotAligned"> + <severity>0</severity> + </rule> + <rule ref="Squiz.Arrays.ArrayDeclaration.ValueNotAligned"> + <severity>0</severity> + </rule> + <rule ref="Squiz.Arrays.ArrayDeclaration.CloseBraceNotAligned"> + <severity>0</severity> + </rule> + <rule ref="Squiz.Arrays.ArrayDeclaration.CloseBraceNewLine"> + <severity>0</severity> + </rule> + + <!-- Check var names, but we don't want leading underscores for private vars --> + <rule ref="Squiz.NamingConventions.ValidVariableName"/> + <rule ref="Squiz.NamingConventions.ValidVariableName.PrivateNoUnderscore"> + <severity>0</severity> + </rule> + + <!-- Only one argument per line in multi-line function calls --> + <rule ref="PEAR.Functions.FunctionCallSignature"> + <properties> + <property name="allowMultipleArguments" value="false"/> + </properties> + </rule> + + <!-- Have 12 chars padding maximum and always show as errors --> + <rule ref="Generic.Formatting.MultipleStatementAlignment"> + <properties> + <property name="maxPadding" value="12"/> + <property name="error" value="true"/> + </properties> + </rule> + + <!-- Ban some functions --> + <rule ref="Generic.PHP.ForbiddenFunctions"> + <properties> + <property name="forbiddenFunctions" type="array"> + <element key="sizeof" value="count"/> + <element key="delete" value="unset"/> + <element key="print" value="echo"/> + <element key="is_null" value="null"/> + <element key="create_function" value="null"/> + </property> + </properties> + </rule> + + <!-- Private methods MUST not be prefixed with an underscore --> + <rule ref="PSR2.Methods.MethodDeclaration.Underscore"> + <type>error</type> + </rule> + + <!-- Private properties MUST not be prefixed with an underscore --> + <rule ref="PSR2.Classes.PropertyDeclaration.Underscore"> + <type>error</type> + </rule> + + <!-- } End of original PHPCS ruleset.xml --> + + <!-- The following sniffs are disabled because we don't want them --> + <rule ref="PEAR.Commenting.FileComment"> + <exclude name="PEAR.Commenting.FileComment.MissingAuthorTag"/> + <exclude name="PEAR.Commenting.FileComment.MissingLicenseTag"/> + </rule> + <rule ref="Generic.Files.LineLength"> + <exclude name="Generic.Files.LineLength.TooLong"/> + </rule> + <rule ref="Generic.Commenting.Todo"> + <exclude name="Generic.Commenting.Todo.TaskFound"/> + <exclude name="Generic.Commenting.Todo.CommentFound"/> + </rule> + + <!-- Not compliant yet, should be fixed in the future. --> + <rule ref="PSR2.Classes.PropertyDeclaration"> + <exclude-pattern>coder_sniffer/Drupal/Sniffs/WhiteSpace/ScopeIndentSniff.php</exclude-pattern> + </rule> + <rule ref="Squiz.NamingConventions.ValidVariableName.NotCamelCaps"> + <exclude-pattern>coder_sniffer/DrupalPractice/Sniffs/CodeAnalysis/VariableAnalysisSniff.php</exclude-pattern> + </rule> + <rule ref="PEAR.Commenting.FunctionComment.MissingParamComment"> + <exclude-pattern>coder_sniffer/DrupalPractice/Sniffs/CodeAnalysis/VariableAnalysisSniff.php</exclude-pattern> + </rule> + <rule ref="Squiz.Commenting.VariableComment.Missing"> + <exclude-pattern>coder_sniffer/DrupalPractice/Sniffs/CodeAnalysis/VariableAnalysisSniff.php</exclude-pattern> + </rule> </ruleset>