From e8f29433ce2aee0af4047461a62bf576e4340e1c Mon Sep 17 00:00:00 2001 From: Michael Welford <michael.welford@adelaide.edu.au> Date: Wed, 11 Apr 2018 15:49:23 +0930 Subject: [PATCH] Initial commit. --- .../Array/DisallowLongArraySyntaxSniff.php | 43 --- .../Sniffs/{Array => Arrays}/ArraySniff.php | 28 +- .../Arrays/DisallowLongArraySyntaxSniff.php | 51 +++ .../CSS/ClassDefinitionNameSpacingSniff.php | 24 +- .../Sniffs/CSS/ColourDefinitionSniff.php | 19 +- .../Classes/ClassCreateInstanceSniff.php | 20 +- .../Sniffs/Classes/ClassDeclarationSniff.php | 26 +- .../Classes/FullyQualifiedNamespaceSniff.php | 21 +- .../Sniffs/Classes/InterfaceNameSniff.php | 17 +- .../Classes/PropertyDeclarationSniff.php | 33 +- .../Classes/UnusedUseStatementSniff.php | 22 +- .../Classes/UseLeadingBackslashSniff.php | 20 +- .../Sniffs/Commenting/ClassCommentSniff.php | 20 +- .../Commenting/DataTypeNamespaceSniff.php | 20 +- .../Commenting/DocCommentAlignmentSniff.php | 25 +- .../Sniffs/Commenting/DocCommentSniff.php | 20 +- .../Sniffs/Commenting/DocCommentStarSniff.php | 17 +- .../Sniffs/Commenting/FileCommentSniff.php | 15 +- .../Commenting/FunctionCommentSniff.php | 79 ++--- .../Sniffs/Commenting/HookCommentSniff.php | 20 +- .../Sniffs/Commenting/InlineCommentSniff.php | 45 +-- .../Commenting/PostStatementCommentSniff.php | 22 +- .../Commenting/VariableCommentSniff.php | 38 ++- .../ControlSignatureSniff.php | 25 +- .../Sniffs/ControlStructures/ElseIfSniff.php | 17 +- .../InlineControlStructureSniff.php | 20 +- .../Sniffs/Files/EndFileNewlineSniff.php | 17 +- .../Drupal/Sniffs/Files/FileEncodingSniff.php | 19 +- .../Drupal/Sniffs/Files/LineLengthSniff.php | 26 +- .../Sniffs/Files/TxtFileLineLengthSniff.php | 27 +- .../Formatting/MultiLineAssignmentSniff.php | 30 +- .../MultipleStatementAlignmentSniff.php | 28 +- .../Sniffs/Formatting/SpaceInlineIfSniff.php | 17 +- .../Formatting/SpaceUnaryOperatorSniff.php | 22 +- .../Functions/DiscouragedFunctionsSniff.php | 8 +- .../Functions/FunctionDeclarationSniff.php | 17 +- .../Sniffs/InfoFiles/AutoAddedKeysSniff.php | 20 +- .../Sniffs/InfoFiles/ClassFilesSniff.php | 25 +- .../Sniffs/InfoFiles/DuplicateEntrySniff.php | 17 +- .../Drupal/Sniffs/InfoFiles/RequiredSniff.php | 22 +- .../Sniffs/Methods/MethodDeclarationSniff.php | 15 +- .../NamingConventions/ValidClassNameSniff.php | 19 +- .../ValidFunctionNameSniff.php | 39 ++- .../NamingConventions/ValidGlobalSniff.php | 20 +- .../ValidVariableNameSniff.php | 33 +- .../Drupal/Sniffs/Scope/MethodScopeSniff.php | 42 ++- .../Sniffs/Semantics/ConstantNameSniff.php | 25 +- .../Sniffs/Semantics/EmptyInstallSniff.php | 24 +- .../Sniffs/Semantics/FunctionAliasSniff.php | 25 +- .../Drupal/Sniffs/Semantics/FunctionCall.php | 42 +-- .../Sniffs/Semantics/FunctionDefinition.php | 32 +- .../Sniffs/Semantics/FunctionTSniff.php | 30 +- .../Semantics/FunctionWatchdogSniff.php | 25 +- .../Sniffs/Semantics/InstallHooksSniff.php | 21 +- .../Semantics/LStringTranslatableSniff.php | 25 +- .../Sniffs/Semantics/PregSecuritySniff.php | 25 +- .../Sniffs/Semantics/RemoteAddressSniff.php | 17 +- .../Sniffs/Semantics/TInHookMenuSniff.php | 24 +- .../Sniffs/Semantics/TInHookSchemaSniff.php | 24 +- .../Strings/UnnecessaryStringConcatSniff.php | 38 +-- .../WhiteSpace/CloseBracketSpacingSniff.php | 23 +- .../Drupal/Sniffs/WhiteSpace/CommaSniff.php | 19 +- .../Sniffs/WhiteSpace/EmptyLinesSniff.php | 19 +- .../Sniffs/WhiteSpace/NamespaceSniff.php | 17 +- .../WhiteSpace/ObjectOperatorIndentSniff.php | 30 +- .../WhiteSpace/ObjectOperatorSpacingSniff.php | 25 +- .../WhiteSpace/OpenBracketSpacingSniff.php | 20 +- .../Sniffs/WhiteSpace/OpenTagNewlineSniff.php | 22 +- .../WhiteSpace/OperatorSpacingSniff.php | 34 +- .../WhiteSpace/ScopeClosingBraceSniff.php | 22 +- .../Sniffs/WhiteSpace/ScopeIndentSniff.php | 43 ++- .../Test/{Array => Arrays}/ArrayUnitTest.inc | 0 .../{Array => Arrays}/ArrayUnitTest.inc.fixed | 0 .../Test/{Array => Arrays}/ArrayUnitTest.php | 10 +- .../DisallowLongArraySyntaxUnitTest.php | 12 +- .../DisallowLongArraySyntaxUnitTest.1.inc | 0 .../disallow_long_array_d7.info | 0 .../DisallowLongArraySyntaxUnitTest.2.inc | 0 ...isallowLongArraySyntaxUnitTest.2.inc.fixed | 0 .../disallow_long_array_d8.info.yml | 0 .../Classes/ClassCreateInstanceUnitTest.php | 10 +- .../Test/Classes/ClassDeclarationUnitTest.php | 10 +- .../FullyQualifiedNamespaceUnitTest.php | 12 +- .../Classes/PropertyDeclarationUnitTest.php | 10 +- .../Classes/UnusedUseStatementUnitTest.php | 10 +- .../Classes/UseLeadingBackslashUnitTest.php | 10 +- .../Drupal/Test/CoderSniffUnitTest.php | 299 +++++++++++------- .../Test/Commenting/ClassCommentUnitTest.php | 10 +- .../Commenting/DataTypeNamespaceUnitTest.php | 10 +- .../DocCommentAlignmentUnitTest.php | 10 +- .../Commenting/DocCommentStarUnitTest.php | 10 +- .../Test/Commenting/DocCommentUnitTest.inc | 7 + .../Commenting/DocCommentUnitTest.inc.fixed | 8 + .../Test/Commenting/DocCommentUnitTest.php | 12 +- .../Commenting/FileCommentUnitTest.10.inc | 11 +- .../FileCommentUnitTest.10.inc.fixed | 10 +- .../Commenting/FileCommentUnitTest.11.inc | 4 +- .../FileCommentUnitTest.11.inc.fixed | 4 +- .../Commenting/FileCommentUnitTest.12.inc | 7 - .../FileCommentUnitTest.12.inc.fixed | 12 - .../Test/Commenting/FileCommentUnitTest.5.inc | 12 +- .../FileCommentUnitTest.5.inc.fixed | 10 +- .../Test/Commenting/FileCommentUnitTest.6.inc | 20 +- .../FileCommentUnitTest.6.inc.fixed | 14 +- .../Test/Commenting/FileCommentUnitTest.7.inc | 6 - .../FileCommentUnitTest.7.inc.fixed | 2 - .../Test/Commenting/FileCommentUnitTest.8.inc | 8 +- .../FileCommentUnitTest.8.inc.fixed | 4 +- .../Test/Commenting/FileCommentUnitTest.9.inc | 2 +- .../FileCommentUnitTest.9.inc.fixed | 2 +- .../Test/Commenting/FileCommentUnitTest.php | 26 +- .../Commenting/FunctionCommentUnitTest.php | 10 +- .../Test/Commenting/InlineCommentUnitTest.php | 10 +- .../PostStatementCommentUnitTest.php | 10 +- .../Commenting/VariableCommentUnitTest.php | 10 +- .../ControlSignatureUnitTest.php | 12 +- .../Test/ControlStructures/ElseIfUnitTest.php | 10 +- .../Test/Files/EndFileNewlineUnitTest.php | 10 +- .../Test/Files/FileEncodingUnitTest.php | 10 +- .../Drupal/Test/Files/LineLengthUnitTest.php | 10 +- .../Test/Files/TxtFileLineLengthUnitTest.php | 10 +- .../MultipleStatementAlignmentUnitTest.php | 10 +- .../Formatting/SpaceUnaryOperatorUnitTest.php | 10 +- .../Test/InfoFiles/AutoAddedKeysUnitTest.php | 14 +- .../Test/InfoFiles/ClassFilesUnitTest.php | 12 +- .../Test/InfoFiles/DuplicateEntryUnitTest.php | 12 +- .../ValidFunctionNameUnitTest.php | 10 +- .../ValidVariableNameUnitTest.php | 10 +- .../Drupal/Test/Scope/MethodScopeUnitTest.php | 10 +- .../Test/Semantics/ConstantNameUnitTest.php | 12 +- .../Test/Semantics/FunctionTUnitTest.php | 10 +- .../Semantics/FunctionWatchdogUnitTest.php | 10 +- .../CloseBracketSpacingUnitTest.php | 10 +- .../Drupal/Test/WhiteSpace/CommaUnitTest.php | 10 +- .../Test/WhiteSpace/NamespaceUnitTest.php | 10 +- .../ObjectOperatorIndentUnitTest.php | 10 +- .../ObjectOperatorSpacingUnitTest.php | 10 +- .../WhiteSpace/OpenBracketSpacingUnitTest.php | 10 +- .../WhiteSpace/OpenTagNewlineUnitTest.php | 10 +- .../Test/WhiteSpace/ScopeIndentUnitTest.php | 10 +- coder_sniffer/Drupal/Test/bad/BadUnitTest.php | 18 +- .../Drupal/Test/good/GoodUnitTest.php | 18 +- .../Drupal/Test/phpunit-bootstrap.php | 1 + coder_sniffer/Drupal/ruleset.xml | 3 + coder_sniffer/DrupalPractice/Project.php | 38 ++- .../CodeAnalysis/VariableAnalysisSniff.php | 241 +++++++------- .../Sniffs/Commenting/AuthorTagSniff.php | 17 +- .../Commenting/CommentEmptyLineSniff.php | 17 +- .../Commenting/ExpectedExceptionSniff.php | 17 +- .../Sniffs/Constants/GlobalConstantSniff.php | 20 +- .../Sniffs/Constants/GlobalDefineSniff.php | 28 +- .../Sniffs/FunctionCalls/CheckPlainSniff.php | 25 +- .../FunctionCalls/CurlSslVerifierSniff.php | 25 +- .../Sniffs/FunctionCalls/DbQuerySniff.php | 28 +- .../FunctionCalls/DbSelectBracesSniff.php | 25 +- .../DefaultValueSanitizeSniff.php | 30 +- .../Sniffs/FunctionCalls/FormErrorTSniff.php | 25 +- .../Sniffs/FunctionCalls/LCheckPlainSniff.php | 25 +- .../Sniffs/FunctionCalls/MessageTSniff.php | 25 +- .../Sniffs/FunctionCalls/TCheckPlainSniff.php | 25 +- .../Sniffs/FunctionCalls/ThemeSniff.php | 19 +- .../VariableSetSanitizeSniff.php | 25 +- .../AccessHookMenuSniff.php | 28 +- .../FunctionDefinitions/FormAlterDocSniff.php | 24 +- .../FunctionDefinitions/HookInitCssSniff.php | 27 +- .../FunctionDefinitions/InstallTSniff.php | 27 +- .../Sniffs/General/AccessAdminPagesSniff.php | 21 +- .../Sniffs/General/ClassNameSniff.php | 20 +- .../Sniffs/General/DescriptionTSniff.php | 19 +- .../Sniffs/General/FormStateInputSniff.php | 17 +- .../Sniffs/General/LanguageNoneSniff.php | 17 +- .../Sniffs/General/OptionsTSniff.php | 17 +- .../Sniffs/General/VariableNameSniff.php | 33 +- .../InfoFiles/NamespacedDependencySniff.php | 17 +- .../Sniffs/Objects/GlobalClassSniff.php | 22 +- .../Sniffs/Objects/GlobalDrupalSniff.php | 20 +- .../Sniffs/Objects/GlobalFunctionSniff.php | 23 +- .../Objects/UnusedPrivateMethodSniff.php | 43 ++- .../Sniffs/Yaml/RoutingAccessSniff.php | 17 +- .../CodeAnalysis/VariableAnalysisUnitTest.php | 10 +- .../Test/Commenting/AuthorTagUnitTest.php | 10 +- .../Commenting/CommentEmptyLineUnitTest.php | 10 +- .../Commenting/ExpectedExceptionUnitTest.php | 10 +- .../Test/Constants/GlobalConstantUnitTest.php | 10 +- .../Test/Constants/GlobalDefineUnitTest.php | 10 +- .../Test/FunctionCalls/CheckPlainUnitTest.php | 10 +- .../FunctionCalls/CurlSslVerifierUnitTest.php | 10 +- .../Test/FunctionCalls/DbQueryUnitTest.php | 10 +- .../FunctionCalls/DbSelectBracesUnitTest.php | 10 +- .../DefaultValueSanitizeUnitTest.php | 10 +- .../FunctionCalls/TCheckPlainUnitTest.php | 10 +- .../VariableSetSanitizeUnitTest.php | 10 +- .../AccessHookMenuUnitTest.php | 12 +- .../FormAlterDocUnitTest.php | 12 +- .../HookInitCssUnitTest.php | 12 +- .../InstallTSniffUnitTest.php | 12 +- .../Test/General/OptionsTUnitTest.php | 10 +- .../Test/General/VariableNameUnitTest.php | 10 +- .../NamespacedDependencyUnitTest.php | 12 +- .../Test/Objects/GlobalClassUnitTest.php | 14 +- .../Test/Objects/GlobalDrupalUnitTest.php | 14 +- .../Test/Objects/GlobalFunctionUnitTest.php | 14 +- .../Objects/UnusedPrivateMethodUnitTest.php | 10 +- .../Test/ProjectDetection/ProjectUnitTest.php | 79 ----- .../modules/drupal6/nested/test.php | 4 - .../modules/drupal6/testmodule.info | 4 - .../modules/drupal7/testmodule.info | 6 - .../modules/drupal8/testmodule.info.yml | 7 - .../Test/Yaml/RoutingAccessUnitTest.php | 12 +- .../DrupalPractice/Test/good/GoodUnitTest.php | 18 +- composer.json | 8 +- phpcs.xml.dist | 53 +++- 212 files changed, 2605 insertions(+), 1662 deletions(-) delete mode 100644 coder_sniffer/Drupal/Sniffs/Array/DisallowLongArraySyntaxSniff.php rename coder_sniffer/Drupal/Sniffs/{Array => Arrays}/ArraySniff.php (92%) create mode 100644 coder_sniffer/Drupal/Sniffs/Arrays/DisallowLongArraySyntaxSniff.php rename coder_sniffer/Drupal/Test/{Array => Arrays}/ArrayUnitTest.inc (100%) rename coder_sniffer/Drupal/Test/{Array => Arrays}/ArrayUnitTest.inc.fixed (100%) rename coder_sniffer/Drupal/Test/{Array => Arrays}/ArrayUnitTest.php (81%) rename coder_sniffer/Drupal/Test/{Array => Arrays}/DisallowLongArraySyntaxUnitTest.php (80%) rename coder_sniffer/Drupal/Test/{Array => Arrays}/disallow_long_array_d7/DisallowLongArraySyntaxUnitTest.1.inc (100%) rename coder_sniffer/Drupal/Test/{Array => Arrays}/disallow_long_array_d7/disallow_long_array_d7.info (100%) rename coder_sniffer/Drupal/Test/{Array => Arrays}/disallow_long_array_d8/DisallowLongArraySyntaxUnitTest.2.inc (100%) rename coder_sniffer/Drupal/Test/{Array => Arrays}/disallow_long_array_d8/DisallowLongArraySyntaxUnitTest.2.inc.fixed (100%) rename coder_sniffer/Drupal/Test/{Array => Arrays}/disallow_long_array_d8/disallow_long_array_d8.info.yml (100%) delete mode 100644 coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.12.inc delete mode 100644 coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.12.inc.fixed delete mode 100644 coder_sniffer/DrupalPractice/Test/ProjectDetection/ProjectUnitTest.php delete mode 100644 coder_sniffer/DrupalPractice/Test/ProjectDetection/modules/drupal6/nested/test.php delete mode 100644 coder_sniffer/DrupalPractice/Test/ProjectDetection/modules/drupal6/testmodule.info delete mode 100644 coder_sniffer/DrupalPractice/Test/ProjectDetection/modules/drupal7/testmodule.info delete mode 100644 coder_sniffer/DrupalPractice/Test/ProjectDetection/modules/drupal8/testmodule.info.yml diff --git a/coder_sniffer/Drupal/Sniffs/Array/DisallowLongArraySyntaxSniff.php b/coder_sniffer/Drupal/Sniffs/Array/DisallowLongArraySyntaxSniff.php deleted file mode 100644 index fe72b444..00000000 --- a/coder_sniffer/Drupal/Sniffs/Array/DisallowLongArraySyntaxSniff.php +++ /dev/null @@ -1,43 +0,0 @@ -<?php -/** - * Drupal_Sniffs_Array_DisallowLongArraySyntaxSniff. - * - * @category PHP - * @package PHP_CodeSniffer - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/** - * Bans the use of the PHP long array syntax in Drupal 8. - * - * @category PHP - * @package PHP_CodeSniffer - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class Drupal_Sniffs_Array_DisallowLongArraySyntaxSniff extends Generic_Sniffs_Arrays_DisallowLongArraySyntaxSniff -{ - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void|int - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $drupalVersion = DrupalPractice_Project::getCoreVersion($phpcsFile); - if ($drupalVersion !== '8.x') { - // No need to check this file again, mark it as done. - return ($phpcsFile->numTokens + 1); - } - - return parent::process($phpcsFile, $stackPtr); - - }//end process() - - -}//end class diff --git a/coder_sniffer/Drupal/Sniffs/Array/ArraySniff.php b/coder_sniffer/Drupal/Sniffs/Arrays/ArraySniff.php similarity index 92% rename from coder_sniffer/Drupal/Sniffs/Array/ArraySniff.php rename to coder_sniffer/Drupal/Sniffs/Arrays/ArraySniff.php index f9fcd43f..e1edb9fb 100644 --- a/coder_sniffer/Drupal/Sniffs/Array/ArraySniff.php +++ b/coder_sniffer/Drupal/Sniffs/Arrays/ArraySniff.php @@ -1,14 +1,20 @@ <?php /** - * Drupal_Sniffs_Array_ArraySniff. + * \Drupal\Sniffs\Arrays\ArraySniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Arrays; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Util\Tokens; + /** - * Drupal_Sniffs_Array_ArraySniff. + * ArraySniff. * * Checks if the array's are styled in the Drupal way. * - Comma after the last array element @@ -18,7 +24,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Array_ArraySniff implements PHP_CodeSniffer_Sniff +class ArraySniff implements Sniff { @@ -40,13 +46,13 @@ class Drupal_Sniffs_Array_ArraySniff implements PHP_CodeSniffer_Sniff /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in + * the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -65,7 +71,7 @@ class Drupal_Sniffs_Array_ArraySniff implements PHP_CodeSniffer_Sniff } $lastItem = $phpcsFile->findPrevious( - PHP_CodeSniffer_Tokens::$emptyTokens, + Tokens::$emptyTokens, ($tokens[$stackPtr][$parenthesis_closer] - 1), $stackPtr, true @@ -83,7 +89,7 @@ class Drupal_Sniffs_Array_ArraySniff implements PHP_CodeSniffer_Sniff if ($tokens[$lastItem]['code'] !== T_COMMA && $isInlineArray === false && $tokens[($lastItem + 1)]['code'] !== T_CLOSE_PARENTHESIS && $tokens[($lastItem + 1)]['code'] !== T_CLOSE_SHORT_ARRAY - && isset(PHP_CodeSniffer_Tokens::$heredocTokens[$tokens[$lastItem]['code']]) === false + && isset(Tokens::$heredocTokens[$tokens[$lastItem]['code']]) === false ) { $data = array($tokens[$lastItem]['content']); $fix = $phpcsFile->addFixableWarning('A comma should follow the last multiline array item. Found: %s', $lastItem, 'CommaLastItem', $data); @@ -146,7 +152,7 @@ class Drupal_Sniffs_Array_ArraySniff implements PHP_CodeSniffer_Sniff $current_line = $tokens[$newLineStart]['line']; while ($current_line >= $tokens[$newLineStart]['line']) { $newLineStart = $phpcsFile->findNext( - PHP_CodeSniffer_Tokens::$emptyTokens, + Tokens::$emptyTokens, ($newLineStart + 1), ($tokens[$stackPtr][$parenthesis_closer] + 1), true @@ -215,7 +221,7 @@ class Drupal_Sniffs_Array_ArraySniff implements PHP_CodeSniffer_Sniff $isMultiLineString = $tokens[($newLineStart - 1)]['code'] === T_CONSTANT_ENCAPSED_STRING && substr($tokens[($newLineStart - 1)]['content'], -1) === $phpcsFile->eolChar; // Skip NOWDOC or HEREDOC lines. - $nowDoc = isset(PHP_CodeSniffer_Tokens::$heredocTokens[$tokens[$newLineStart]['code']]); + $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( diff --git a/coder_sniffer/Drupal/Sniffs/Arrays/DisallowLongArraySyntaxSniff.php b/coder_sniffer/Drupal/Sniffs/Arrays/DisallowLongArraySyntaxSniff.php new file mode 100644 index 00000000..23808033 --- /dev/null +++ b/coder_sniffer/Drupal/Sniffs/Arrays/DisallowLongArraySyntaxSniff.php @@ -0,0 +1,51 @@ +<?php +/** + * \Drupal\Sniffs\Arrays\DisallowLongArraySyntaxSniff. + * + * @category PHP + * @package PHP_CodeSniffer + * @link http://pear.php.net/package/PHP_CodeSniffer + */ + +namespace Drupal\Sniffs\Arrays; + +require_once __DIR__.'/../../../DrupalPractice/Project.php'; + +use PHP_CodeSniffer\Files\File; +use DrupalPractice\Project; +use PHP_CodeSniffer\Standards\Generic\Sniffs\Arrays\DisallowLongArraySyntaxSniff as GenericDisallowLongArraySyntaxSniff; + +/** + * Bans the use of the PHP long array syntax in Drupal 8. + * + * @category PHP + * @package PHP_CodeSniffer + * @link http://pear.php.net/package/PHP_CodeSniffer + */ +class DisallowLongArraySyntaxSniff extends GenericDisallowLongArraySyntaxSniff +{ + + + /** + * Processes this test, when one of its tokens is encountered. + * + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. + * + * @return void|int + */ + public function process(File $phpcsFile, $stackPtr) + { + $drupalVersion = Project::getCoreVersion($phpcsFile); + if ($drupalVersion !== '8.x') { + // No need to check this file again, mark it as done. + return ($phpcsFile->numTokens + 1); + } + + return parent::process($phpcsFile, $stackPtr); + + }//end process() + + +}//end class diff --git a/coder_sniffer/Drupal/Sniffs/CSS/ClassDefinitionNameSpacingSniff.php b/coder_sniffer/Drupal/Sniffs/CSS/ClassDefinitionNameSpacingSniff.php index 4184ac6b..a3780c28 100644 --- a/coder_sniffer/Drupal/Sniffs/CSS/ClassDefinitionNameSpacingSniff.php +++ b/coder_sniffer/Drupal/Sniffs/CSS/ClassDefinitionNameSpacingSniff.php @@ -1,22 +1,28 @@ <?php /** - * Drupal_Sniffs_CSS_ClassDefinitionNameSpacingSniff. + * \Drupal\Sniffs\CSS\ClassDefinitionNameSpacingSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\CSS; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Util\Tokens; + /** * Ensure there are no blank lines between the names of classes/IDs. Copied from - * Squiz_Sniffs_CSS_ClassDefinitionNameSpacingSniff because we also check for comma - * separated selectors on their own line. + * \PHP_CodeSniffer\Standards\Squiz\Sniffs\CSS\ClassDefinitionNameSpacingSniff + * because we also check for comma separated selectors on their own line. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_CSS_ClassDefinitionNameSpacingSniff implements PHP_CodeSniffer_Sniff +class ClassDefinitionNameSpacingSniff implements Sniff { /** @@ -42,13 +48,13 @@ class Drupal_Sniffs_CSS_ClassDefinitionNameSpacingSniff implements PHP_CodeSniff /** * Processes the tokens that this sniff is interested in. * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where the token was found. + * @param int $stackPtr The position in the stack where + * the token was found. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -65,7 +71,7 @@ class Drupal_Sniffs_CSS_ClassDefinitionNameSpacingSniff implements PHP_CodeSniff T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, T_OPEN_TAG => T_OPEN_TAG, ); - $endTokens += PHP_CodeSniffer_Tokens::$commentTokens; + $endTokens += Tokens::$commentTokens; $foundContent = false; $currentLine = $tokens[$stackPtr]['line']; diff --git a/coder_sniffer/Drupal/Sniffs/CSS/ColourDefinitionSniff.php b/coder_sniffer/Drupal/Sniffs/CSS/ColourDefinitionSniff.php index e80021a4..be8f8889 100644 --- a/coder_sniffer/Drupal/Sniffs/CSS/ColourDefinitionSniff.php +++ b/coder_sniffer/Drupal/Sniffs/CSS/ColourDefinitionSniff.php @@ -1,14 +1,19 @@ <?php /** - * Drupal_Sniffs_CSS_ColourDefinitionSniff. + * \Drupal\Sniffs\CSS\ColourDefinitionSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\CSS; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** - * Squiz_Sniffs_CSS_ColourDefinitionSniff. + * \Drupal\Sniffs\CSS\ColourDefinitionSniff. * * Ensure colours are defined in lower-case. * @@ -16,7 +21,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_CSS_ColourDefinitionSniff implements PHP_CodeSniffer_Sniff +class ColourDefinitionSniff implements Sniff { /** @@ -42,13 +47,13 @@ class Drupal_Sniffs_CSS_ColourDefinitionSniff implements PHP_CodeSniffer_Sniff /** * Processes the tokens that this sniff is interested in. * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where the token was found. + * @param int $stackPtr The position in the stack where + * the token was found. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $colour = $tokens[$stackPtr]['content']; diff --git a/coder_sniffer/Drupal/Sniffs/Classes/ClassCreateInstanceSniff.php b/coder_sniffer/Drupal/Sniffs/Classes/ClassCreateInstanceSniff.php index 9476c7d2..bb08722e 100644 --- a/coder_sniffer/Drupal/Sniffs/Classes/ClassCreateInstanceSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Classes/ClassCreateInstanceSniff.php @@ -7,6 +7,12 @@ * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Classes; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Util\Tokens; + /** * Class create instance Test. * @@ -16,7 +22,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Classes_ClassCreateInstanceSniff implements PHP_CodeSniffer_Sniff +class ClassCreateInstanceSniff implements Sniff { @@ -35,13 +41,13 @@ class Drupal_Sniffs_Classes_ClassCreateInstanceSniff implements PHP_CodeSniffer_ /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in the + * stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -56,7 +62,7 @@ class Drupal_Sniffs_Classes_ClassCreateInstanceSniff implements PHP_CodeSniffer_ $nextParenthesis = $phpcsFile->findNext(T_OPEN_PARENTHESIS, ($stackPtr + 1), $commaOrColon); if ($nextParenthesis === false) { $error = 'Calling class constructors must always include parentheses'; - $constructor = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true, null, true); + $constructor = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true, null, true); // We can invoke the fixer if we know this is a static constructor // function call or constructor calls with namespaces, example // "new \DOMDocument;" or constructor with class names in variables @@ -70,7 +76,7 @@ class Drupal_Sniffs_Classes_ClassCreateInstanceSniff implements PHP_CodeSniffer_ $nextConstructorPart = $constructor; while (true) { $nextConstructorPart = $phpcsFile->findNext( - PHP_CodeSniffer_Tokens::$emptyTokens, + Tokens::$emptyTokens, ($nextConstructorPart + 1), null, true, diff --git a/coder_sniffer/Drupal/Sniffs/Classes/ClassDeclarationSniff.php b/coder_sniffer/Drupal/Sniffs/Classes/ClassDeclarationSniff.php index d4c49c25..ea63234b 100644 --- a/coder_sniffer/Drupal/Sniffs/Classes/ClassDeclarationSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Classes/ClassDeclarationSniff.php @@ -7,6 +7,12 @@ * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Classes; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Standards\PSR2\Sniffs\Classes\ClassDeclarationSniff as PSR2ClassDeclarationSniff; +use PHP_CodeSniffer\Util\Tokens; + /** * Class Declaration Test. * @@ -16,7 +22,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Classes_ClassDeclarationSniff extends PSR2_Sniffs_Classes_ClassDeclarationSniff +class ClassDeclarationSniff extends PSR2ClassDeclarationSniff { @@ -39,13 +45,13 @@ class Drupal_Sniffs_Classes_ClassDeclarationSniff extends PSR2_Sniffs_Classes_Cl /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param integer $stackPtr The position of the current token in the - * stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param integer $stackPtr The position of the current token in the + * stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $errorData = array(strtolower($tokens[$stackPtr]['content'])); @@ -122,13 +128,13 @@ class Drupal_Sniffs_Classes_ClassDeclarationSniff extends PSR2_Sniffs_Classes_Cl /** * Processes the closing section of a class declaration. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - public function processClose(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function processClose(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -143,7 +149,7 @@ class Drupal_Sniffs_Classes_ClassDeclarationSniff extends PSR2_Sniffs_Classes_Cl if ($prevContent !== $tokens[$stackPtr]['scope_opener'] && $tokens[$prevContent]['line'] !== ($tokens[$closeBrace]['line'] - 2) // If the class only contains a comment no extra line is needed. - && isset(PHP_CodeSniffer_Tokens::$commentTokens[$tokens[$prevContent]['code']]) === false + && 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']); diff --git a/coder_sniffer/Drupal/Sniffs/Classes/FullyQualifiedNamespaceSniff.php b/coder_sniffer/Drupal/Sniffs/Classes/FullyQualifiedNamespaceSniff.php index ed608851..46f71ab8 100644 --- a/coder_sniffer/Drupal/Sniffs/Classes/FullyQualifiedNamespaceSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Classes/FullyQualifiedNamespaceSniff.php @@ -1,12 +1,17 @@ <?php /** - * Drupal_Sniffs_Classes_FullyQualifiedNamespaceSniff. + * \Drupal\Sniffs\Classes\FullyQualifiedNamespaceSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Classes; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** * Checks that class references do not use FQN but use statements. * @@ -14,7 +19,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Classes_FullyQualifiedNamespaceSniff implements PHP_CodeSniffer_Sniff +class FullyQualifiedNamespaceSniff implements Sniff { @@ -33,18 +38,18 @@ class Drupal_Sniffs_Classes_FullyQualifiedNamespaceSniff implements PHP_CodeSnif /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where the - * token was found. - * @param int $stackPtr The position in the PHP_CodeSniffer - * file's token stack where the token - * was found. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where the + * token was found. + * @param int $stackPtr The position in the PHP_CodeSniffer + * file's token stack where the token + * was found. * * @return void|int Optionally returns a stack pointer. The sniff will not be * called again on the current file until the returned stack * pointer is reached. Return $phpcsFile->numTokens + 1 to skip * the rest of the file. */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); diff --git a/coder_sniffer/Drupal/Sniffs/Classes/InterfaceNameSniff.php b/coder_sniffer/Drupal/Sniffs/Classes/InterfaceNameSniff.php index 2852da2d..156ea060 100644 --- a/coder_sniffer/Drupal/Sniffs/Classes/InterfaceNameSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Classes/InterfaceNameSniff.php @@ -1,12 +1,17 @@ <?php /** - * Drupal_Sniffs_Classes_InterfaceNameSniff. + * \Drupal\Sniffs\Classes\InterfaceNameSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Classes; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** * Checks that interface names end with "Interface". * @@ -14,7 +19,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Classes_InterfaceNameSniff implements PHP_CodeSniffer_Sniff +class InterfaceNameSniff implements Sniff { @@ -33,13 +38,13 @@ class Drupal_Sniffs_Classes_InterfaceNameSniff implements PHP_CodeSniffer_Sniff /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in + * the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $namePtr = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); diff --git a/coder_sniffer/Drupal/Sniffs/Classes/PropertyDeclarationSniff.php b/coder_sniffer/Drupal/Sniffs/Classes/PropertyDeclarationSniff.php index b6723296..ffd231d3 100644 --- a/coder_sniffer/Drupal/Sniffs/Classes/PropertyDeclarationSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Classes/PropertyDeclarationSniff.php @@ -7,27 +7,34 @@ * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Classes; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\AbstractVariableSniff; +use PHP_CodeSniffer\Util\Tokens; + /** - * Laregely copied from PSR2_Sniffs_Classes_PropertyDeclarationSniff to have a fixer + * Laregely copied from + * \PHP_CodeSniffer\Standards\PSR2\Sniffs\Classes\PropertyDeclarationSniff to have a fixer * for the var keyword. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Classes_PropertyDeclarationSniff extends PHP_CodeSniffer_Standards_AbstractVariableSniff +class PropertyDeclarationSniff extends AbstractVariableSniff { /** * Processes the function tokens within the class. * - * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found. - * @param int $stackPtr The position where the token was found. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. + * @param int $stackPtr The position where the token was found. * * @return void */ - protected function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + protected function processMemberVar(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -40,7 +47,7 @@ class Drupal_Sniffs_Classes_PropertyDeclarationSniff extends PHP_CodeSniffer_Sta // Detect multiple properties defined at the same time. Throw an error // for this, but also only process the first property in the list so we don't // repeat errors. - $find = PHP_CodeSniffer_Tokens::$scopeModifiers; + $find = Tokens::$scopeModifiers; $find = array_merge($find, array(T_VARIABLE, T_VAR, T_SEMICOLON)); $prev = $phpcsFile->findPrevious($find, ($stackPtr - 1)); if ($tokens[$prev]['code'] === T_VARIABLE) { @@ -61,7 +68,7 @@ class Drupal_Sniffs_Classes_PropertyDeclarationSniff extends PHP_CodeSniffer_Sta $phpcsFile->addError($error, $stackPtr, 'Multiple'); } - $modifier = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$scopeModifiers, $stackPtr); + $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']); @@ -74,12 +81,12 @@ class Drupal_Sniffs_Classes_PropertyDeclarationSniff extends PHP_CodeSniffer_Sta /** * Processes normal variables. * - * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found. - * @param int $stackPtr The position where the token was found. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. + * @param int $stackPtr The position where the token was found. * * @return void */ - protected function processVariable(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + protected function processVariable(File $phpcsFile, $stackPtr) { /* We don't care about normal variables. @@ -91,12 +98,12 @@ class Drupal_Sniffs_Classes_PropertyDeclarationSniff extends PHP_CodeSniffer_Sta /** * Processes variables in double quoted strings. * - * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found. - * @param int $stackPtr The position where the token was found. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. + * @param int $stackPtr The position where the token was found. * * @return void */ - protected function processVariableInString(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + protected function processVariableInString(File $phpcsFile, $stackPtr) { /* We don't care about normal variables. diff --git a/coder_sniffer/Drupal/Sniffs/Classes/UnusedUseStatementSniff.php b/coder_sniffer/Drupal/Sniffs/Classes/UnusedUseStatementSniff.php index 4825e228..d506a59c 100644 --- a/coder_sniffer/Drupal/Sniffs/Classes/UnusedUseStatementSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Classes/UnusedUseStatementSniff.php @@ -1,12 +1,18 @@ <?php /** - * Drupal_Sniffs_Classes_UnusedUseStatementSniff. + * \Drupal\Sniffs\Classes\UnusedUseStatementSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Classes; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Util\Tokens; + /** * Checks for "use" statements that are not needed in a file. * @@ -14,7 +20,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Classes_UnusedUseStatementSniff implements PHP_CodeSniffer_Sniff +class UnusedUseStatementSniff implements Sniff { @@ -33,13 +39,13 @@ class Drupal_Sniffs_Classes_UnusedUseStatementSniff implements PHP_CodeSniffer_S /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in + * the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -55,7 +61,7 @@ class Drupal_Sniffs_Classes_UnusedUseStatementSniff implements PHP_CodeSniffer_S } $classPtr = $phpcsFile->findPrevious( - PHP_CodeSniffer_Tokens::$emptyTokens, + Tokens::$emptyTokens, ($semiColon - 1), null, true @@ -117,7 +123,7 @@ class Drupal_Sniffs_Classes_UnusedUseStatementSniff implements PHP_CodeSniffer_S } $beforeUsage = $phpcsFile->findPrevious( - PHP_CodeSniffer_Tokens::$emptyTokens, + Tokens::$emptyTokens, ($classUsed - 1), null, true diff --git a/coder_sniffer/Drupal/Sniffs/Classes/UseLeadingBackslashSniff.php b/coder_sniffer/Drupal/Sniffs/Classes/UseLeadingBackslashSniff.php index bad21c08..9bc894a0 100644 --- a/coder_sniffer/Drupal/Sniffs/Classes/UseLeadingBackslashSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Classes/UseLeadingBackslashSniff.php @@ -1,12 +1,18 @@ <?php /** - * Drupal_Sniffs_Classes_UseLeadingBackslashSniff. + * \Drupal\Sniffs\Classes\UseLeadingBackslashSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Classes; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Util\Tokens; + /** * Use statements to import classes must not begin with "\". * @@ -14,7 +20,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Classes_UseLeadingBackslashSniff implements PHP_CodeSniffer_Sniff +class UseLeadingBackslashSniff implements Sniff { @@ -33,13 +39,13 @@ class Drupal_Sniffs_Classes_UseLeadingBackslashSniff implements PHP_CodeSniffer_ /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in + * the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -49,7 +55,7 @@ class Drupal_Sniffs_Classes_UseLeadingBackslashSniff implements PHP_CodeSniffer_ } $startPtr = $phpcsFile->findNext( - PHP_CodeSniffer_Tokens::$emptyTokens, + Tokens::$emptyTokens, ($stackPtr + 1), null, true diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/ClassCommentSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/ClassCommentSniff.php index 6cf50484..68bacb1b 100644 --- a/coder_sniffer/Drupal/Sniffs/Commenting/ClassCommentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Commenting/ClassCommentSniff.php @@ -7,9 +7,15 @@ * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Commenting; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Util\Tokens; + /** * Checks that comment doc blocks exist on classes, interfaces and traits. Largely - * copied from Squiz_Sniffs_Commenting_ClassCommentSniff. + * copied from PHP_CodeSniffer\Standards\Squiz\Sniffs\Commenting\ClassCommentSniff. * * @category PHP * @package PHP_CodeSniffer @@ -19,7 +25,7 @@ * @version Release: @package_version@ * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Commenting_ClassCommentSniff implements PHP_CodeSniffer_Sniff +class ClassCommentSniff implements Sniff { @@ -42,16 +48,16 @@ class Drupal_Sniffs_Commenting_ClassCommentSniff implements PHP_CodeSniffer_Snif /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); - $find = PHP_CodeSniffer_Tokens::$methodPrefixes; + $find = Tokens::$methodPrefixes; $find[] = T_WHITESPACE; $name = $tokens[$stackPtr]['content']; diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/DataTypeNamespaceSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/DataTypeNamespaceSniff.php index 6638a519..6778d5ce 100644 --- a/coder_sniffer/Drupal/Sniffs/Commenting/DataTypeNamespaceSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Commenting/DataTypeNamespaceSniff.php @@ -1,12 +1,18 @@ <?php /** - * Drupal_Sniffs_Commenting_DataTypeNamespaceSniff. + * \Drupal\Sniffs\Commenting\DataTypeNamespaceSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Commenting; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Util\Tokens; + /** * Checks that data types in param, return, var tags are fully namespaced. * @@ -14,7 +20,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Commenting_DataTypeNamespaceSniff implements PHP_CodeSniffer_Sniff +class DataTypeNamespaceSniff implements Sniff { @@ -33,13 +39,13 @@ class Drupal_Sniffs_Commenting_DataTypeNamespaceSniff implements PHP_CodeSniffer /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in + * the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -55,7 +61,7 @@ class Drupal_Sniffs_Commenting_DataTypeNamespaceSniff implements PHP_CodeSniffer } $classPtr = $phpcsFile->findPrevious( - PHP_CodeSniffer_Tokens::$emptyTokens, + Tokens::$emptyTokens, ($semiColon - 1), null, true diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentAlignmentSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentAlignmentSniff.php index 4703dbe3..167b2def 100644 --- a/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentAlignmentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentAlignmentSniff.php @@ -1,14 +1,21 @@ <?php /** - * Drupal_Sniffs_Commenting_EmptyCatchCommentSniff. + * \Drupal\Sniffs\Commenting\DocCommentAlignmentSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Commenting; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Util\Tokens; + /** - * Largely copied from Squiz_Sniffs_Commenting_DocCommentAlignmentSniff to also + * Largely copied from + * \PHP_CodeSniffer\Standards\Squiz\Sniffs\Commenting\DocCommentAlignmentSniff to also * handle the "var" keyword. See * https://github.com/squizlabs/PHP_CodeSniffer/pull/1212 * @@ -16,7 +23,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Commenting_DocCommentAlignmentSniff implements PHP_CodeSniffer_Sniff +class DocCommentAlignmentSniff implements Sniff { @@ -35,18 +42,18 @@ class Drupal_Sniffs_Commenting_DocCommentAlignmentSniff implements PHP_CodeSniff /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); // We are only interested in function/class/interface doc block comments. - $ignore = PHP_CodeSniffer_Tokens::$emptyTokens; + $ignore = Tokens::$emptyTokens; if ($phpcsFile->tokenizerType === 'JS') { $ignore[] = T_EQUAL; $ignore[] = T_STRING; @@ -71,7 +78,7 @@ class Drupal_Sniffs_Commenting_DocCommentAlignmentSniff implements PHP_CodeSniff if (isset($ignore[$tokens[$nextToken]['code']]) === false) { // Could be a file comment. - $prevToken = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true); + $prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); if ($tokens[$prevToken]['code'] !== T_OPEN_TAG) { return; } diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentSniff.php index 10fbe8f2..ecc948a9 100644 --- a/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentSniff.php @@ -7,17 +7,23 @@ * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Commenting; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** * Ensures doc blocks follow basic formatting. * - * Largely copied from Generic_Sniffs_Commenting_DocCommentSniff, but Drupal @file - * comments are different. + * Largely copied from + * \PHP_CodeSniffer\Standards\Generic\Sniffs\Commenting\DocCommentSniff, + * but Drupal @file comments are different. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Commenting_DocCommentSniff implements PHP_CodeSniffer_Sniff +class DocCommentSniff implements Sniff { /** @@ -46,13 +52,13 @@ class Drupal_Sniffs_Commenting_DocCommentSniff implements PHP_CodeSniffer_Sniff /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $commentEnd = $phpcsFile->findNext(T_DOC_COMMENT_CLOSE_TAG, ($stackPtr + 1)); diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentStarSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentStarSniff.php index f4a87ae2..f7910813 100644 --- a/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentStarSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentStarSniff.php @@ -1,12 +1,17 @@ <?php /** - * Drupal_Sniffs_Commenting_DocCommentStarSniff + * \Drupal\Sniffs\Commenting\DocCommentStarSniff * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Commenting; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** * Checks that a doc comment block has a doc comment star on every line. * @@ -14,7 +19,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Commenting_DocCommentStarSniff implements PHP_CodeSniffer_Sniff +class DocCommentStarSniff implements Sniff { @@ -33,13 +38,13 @@ class Drupal_Sniffs_Commenting_DocCommentStarSniff implements PHP_CodeSniffer_Sn /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/FileCommentSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/FileCommentSniff.php index 55746bc3..2fe5e944 100644 --- a/coder_sniffer/Drupal/Sniffs/Commenting/FileCommentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Commenting/FileCommentSniff.php @@ -7,6 +7,11 @@ * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Commenting; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** * Parses and verifies the doc comments for files. * @@ -21,7 +26,7 @@ * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff +class FileCommentSniff implements Sniff { @@ -51,13 +56,13 @@ class Drupal_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return int */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $this->currentFile = $phpcsFile; diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php index ed9e14cd..b6806fb8 100644 --- a/coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php @@ -7,15 +7,21 @@ * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Commenting; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Util\Tokens; + /** * Parses and verifies the doc comments for functions. Largely copied from - * Squiz_Sniffs_Commenting_FunctionCommentSniff. + * PHP_CodeSniffer\Standards\Squiz\Sniffs\Commenting\FunctionCommentSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Commenting_FunctionCommentSniff implements PHP_CodeSniffer_Sniff +class FunctionCommentSniff implements Sniff { /** @@ -72,20 +78,20 @@ class Drupal_Sniffs_Commenting_FunctionCommentSniff implements PHP_CodeSniffer_S /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); - $find = PHP_CodeSniffer_Tokens::$methodPrefixes; + $find = Tokens::$methodPrefixes; $find[] = T_WHITESPACE; $commentEnd = $phpcsFile->findPrevious($find, ($stackPtr - 1), null, true); - $beforeCommentEnd = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($commentEnd - 1), null, true); + $beforeCommentEnd = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($commentEnd - 1), null, true); if (($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG && $tokens[$commentEnd]['code'] !== T_COMMENT) || ($beforeCommentEnd !== false @@ -162,14 +168,14 @@ class Drupal_Sniffs_Commenting_FunctionCommentSniff implements PHP_CodeSniffer_S /** * Process the return comment of this function comment. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * @param int $commentStart The position in the stack where the comment started. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. + * @param int $commentStart The position in the stack where the comment started. * * @return void */ - protected function processReturn(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $commentStart) + protected function processReturn(File $phpcsFile, $stackPtr, $commentStart) { $tokens = $phpcsFile->getTokens(); @@ -365,14 +371,14 @@ class Drupal_Sniffs_Commenting_FunctionCommentSniff implements PHP_CodeSniffer_S /** * Process any throw tags that this function comment has. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * @param int $commentStart The position in the stack where the comment started. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. + * @param int $commentStart The position in the stack where the comment started. * * @return void */ - protected function processThrows(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $commentStart) + protected function processThrows(File $phpcsFile, $stackPtr, $commentStart) { $tokens = $phpcsFile->getTokens(); @@ -445,14 +451,14 @@ class Drupal_Sniffs_Commenting_FunctionCommentSniff implements PHP_CodeSniffer_S /** * Process the function parameter comments. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * @param int $commentStart The position in the stack where the comment started. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. + * @param int $commentStart The position in the stack where the comment started. * * @return void */ - protected function processParams(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $commentStart) + protected function processParams(File $phpcsFile, $stackPtr, $commentStart) { $tokens = $phpcsFile->getTokens(); @@ -568,6 +574,7 @@ class Drupal_Sniffs_Commenting_FunctionCommentSniff implements PHP_CodeSniffer_S $phpcsFile->addError($error, $tag, 'MissingParamComment'); $commentLines[] = array('comment' => ''); }//end if + $variableArguments = false; // Allow the "..." @param doc for a variable number of parameters. // This could happen with type defined as @param array ... or @@ -872,14 +879,14 @@ class Drupal_Sniffs_Commenting_FunctionCommentSniff implements PHP_CodeSniffer_S /** * Process the function "see" comments. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * @param int $commentStart The position in the stack where the comment started. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. + * @param int $commentStart The position in the stack where the comment started. * * @return void */ - protected function processSees(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $commentStart) + protected function processSees(File $phpcsFile, $stackPtr, $commentStart) { $tokens = $phpcsFile->getTokens(); foreach ($tokens[$commentStart]['comment_tags'] as $tag) { @@ -938,14 +945,14 @@ class Drupal_Sniffs_Commenting_FunctionCommentSniff implements PHP_CodeSniffer_S /** * Checks if a used type hint is an alias defined by a "use" statement. * - * @param string $typeHint The type hint used. - * @param string $suggestedTypeHint The fully qualified type to - * check against. - * @param PHP_CodeSniffer_File $phpcsFile The file being checked. + * @param string $typeHint The type hint used. + * @param string $suggestedTypeHint The fully qualified type to + * check against. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being checked. * * @return boolean */ - protected function isAliasedType($typeHint, $suggestedTypeHint, PHP_CodeSniffer_File $phpcsFile) + protected function isAliasedType($typeHint, $suggestedTypeHint, File $phpcsFile) { $tokens = $phpcsFile->getTokens(); @@ -964,7 +971,7 @@ class Drupal_Sniffs_Commenting_FunctionCommentSniff implements PHP_CodeSniffer_S // Now comes the original class name, possibly with namespace // backslashes. - $originalClass = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($usePtr + 1), null, true); + $originalClass = $phpcsFile->findNext(Tokens::$emptyTokens, ($usePtr + 1), null, true); if ($originalClass === false || ($tokens[$originalClass]['code'] !== T_STRING && $tokens[$originalClass]['code'] !== T_NS_SEPARATOR) ) { @@ -982,13 +989,13 @@ class Drupal_Sniffs_Commenting_FunctionCommentSniff implements PHP_CodeSniffer_S } // Now comes the "as" keyword signaling an alias name for the class. - $asPtr = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($originalClass + 1), null, true); + $asPtr = $phpcsFile->findNext(Tokens::$emptyTokens, ($originalClass + 1), null, true); if ($asPtr === false || $tokens[$asPtr]['code'] !== T_AS) { continue; } // Now comes the name the class is aliased to. - $aliasPtr = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($asPtr + 1), null, true); + $aliasPtr = $phpcsFile->findNext(Tokens::$emptyTokens, ($asPtr + 1), null, true); if ($aliasPtr === false || $tokens[$aliasPtr]['code'] !== T_STRING || $tokens[$aliasPtr]['content'] !== $typeHint ) { diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/HookCommentSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/HookCommentSniff.php index f2fa4f01..84f95ff2 100644 --- a/coder_sniffer/Drupal/Sniffs/Commenting/HookCommentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Commenting/HookCommentSniff.php @@ -7,6 +7,12 @@ * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Commenting; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Util\Tokens; + /** * Ensures hook comments on function are correct. * @@ -14,7 +20,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Commenting_HookCommentSniff implements PHP_CodeSniffer_Sniff +class HookCommentSniff implements Sniff { @@ -33,16 +39,16 @@ class Drupal_Sniffs_Commenting_HookCommentSniff implements PHP_CodeSniffer_Sniff /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); - $find = PHP_CodeSniffer_Tokens::$methodPrefixes; + $find = Tokens::$methodPrefixes; $find[] = T_WHITESPACE; $commentEnd = $phpcsFile->findPrevious($find, ($stackPtr - 1), null, true); @@ -89,7 +95,7 @@ class Drupal_Sniffs_Commenting_HookCommentSniff implements PHP_CodeSniffer_Sniff if (strstr($matches[0], 'Implements ') === false || strstr($matches[0], 'Implements of') !== false || preg_match('/ (drush_)?hook_[a-zA-Z0-9_]+\(\)( for .+)?\.$/', $matches[0]) !== 1 ) { - $phpcsFile->addWarning('Format should be "* Implements hook_foo().", "* Implements hook_foo_BAR_ID_bar() for xyz_bar().",, "* Implements hook_foo_BAR_ID_bar() for xyz-bar.html.twig.", "* Implements hook_foo_BAR_ID_bar() for xyz-bar.tpl.php.", or "* Implements hook_foo_BAR_ID_bar() for block templates."', $short); + $phpcsFile->addWarning('Format should be "* Implements hook_foo().", "* Implements hook_foo_BAR_ID_bar() for xyz_bar().",, "* Implements hook_foo_BAR_ID_bar() for xyz-bar.html.twig.", "* Implements hook_foo_BAR_ID_bar() for xyz-bar.tpl.php.", or "* Implements hook_foo_BAR_ID_bar() for block templates."', $short, 'HookCommentFormat'); } else { // Check that a hook implementation does not duplicate @param and // @return documentation. diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/InlineCommentSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/InlineCommentSniff.php index 32da8dd9..cbdfc708 100644 --- a/coder_sniffer/Drupal/Sniffs/Commenting/InlineCommentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Commenting/InlineCommentSniff.php @@ -1,24 +1,31 @@ <?php /** - * PHP_CodeSniffer_Sniffs_Drupal_Commenting_InlineCommentSniff. + * \Drupal\Sniffs\Commenting\InlineCommentSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Commenting; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Util\Tokens; + /** - * PHP_CodeSniffer_Sniffs_Drupal_Commenting_InlineCommentSniff. + * \Drupal\Sniffs\Commenting\InlineCommentSniff. * * Checks that no perl-style comments are used. Checks that inline comments ("//") * have a space after //, start capitalized and end with proper punctuation. - * Largely copied from Squiz_Sniffs_Commenting_InlineCommentSniff. + * Largely copied from + * \PHP_CodeSniffer\Standards\Squiz\Sniffs\Commenting\InlineCommentSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Commenting_InlineCommentSniff implements PHP_CodeSniffer_Sniff +class InlineCommentSniff implements Sniff { /** @@ -50,13 +57,13 @@ class Drupal_Sniffs_Commenting_InlineCommentSniff implements PHP_CodeSniffer_Sni /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in the + * stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -65,7 +72,7 @@ class Drupal_Sniffs_Commenting_InlineCommentSniff implements PHP_CodeSniffer_Sni // not allowed. if ($tokens[$stackPtr]['code'] === T_DOC_COMMENT_OPEN_TAG) { $nextToken = $phpcsFile->findNext( - PHP_CodeSniffer_Tokens::$emptyTokens, + Tokens::$emptyTokens, ($stackPtr + 1), null, true @@ -99,7 +106,7 @@ class Drupal_Sniffs_Commenting_InlineCommentSniff implements PHP_CodeSniffer_Sni if ($phpcsFile->tokenizerType === 'JS') { // We allow block comments if a function or object // is being assigned to a variable. - $ignore = PHP_CodeSniffer_Tokens::$emptyTokens; + $ignore = Tokens::$emptyTokens; $ignore[] = T_EQUAL; $ignore[] = T_STRING; $ignore[] = T_OBJECT_OPERATOR; @@ -114,7 +121,7 @@ class Drupal_Sniffs_Commenting_InlineCommentSniff implements PHP_CodeSniffer_Sni } $prevToken = $phpcsFile->findPrevious( - PHP_CodeSniffer_Tokens::$emptyTokens, + Tokens::$emptyTokens, ($stackPtr - 1), null, true @@ -322,14 +329,14 @@ class Drupal_Sniffs_Commenting_InlineCommentSniff implements PHP_CodeSniffer_Sni /** * Determines if a comment line is part of an @code/@endcode example. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return boolean Returns true if the comment line is within a @code block, * false otherwise. */ - protected function isInCodeExample(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + protected function isInCodeExample(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $prevComment = $stackPtr; @@ -358,13 +365,13 @@ class Drupal_Sniffs_Commenting_InlineCommentSniff implements PHP_CodeSniffer_Sni /** * Checks the indentation level of the comment contents. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - protected function processIndentation(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + protected function processIndentation(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $comment = rtrim($tokens[$stackPtr]['content']); diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/PostStatementCommentSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/PostStatementCommentSniff.php index ae38ded6..57b2091d 100644 --- a/coder_sniffer/Drupal/Sniffs/Commenting/PostStatementCommentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Commenting/PostStatementCommentSniff.php @@ -1,21 +1,27 @@ <?php /** - * Drupal_Sniffs_Commenting_PostStatementCommentSniff. + * \Drupal\Sniffs\Commenting\PostStatementCommentSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Commenting; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** - * Largely copied from Squiz_Sniffs_Commenting_PostStatementCommentSniff but we want - * the fixer to move the comment to the previous line. + * Largely copied from + * \PHP_CodeSniffer\Standards\Squiz\Sniffs\Commenting\PostStatementCommentSniff + * but we want the fixer to move the comment to the previous line. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Commenting_PostStatementCommentSniff implements PHP_CodeSniffer_Sniff +class PostStatementCommentSniff implements Sniff { /** @@ -41,13 +47,13 @@ class Drupal_Sniffs_Commenting_PostStatementCommentSniff implements PHP_CodeSnif /** * Processes this sniff, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in the + * stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/VariableCommentSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/VariableCommentSniff.php index db3feeb6..9649f5b2 100644 --- a/coder_sniffer/Drupal/Sniffs/Commenting/VariableCommentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Commenting/VariableCommentSniff.php @@ -7,29 +7,37 @@ * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Commenting; + +use Drupal\Sniffs\Commenting\FunctionCommentSniff; +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\AbstractVariableSniff; +use PHP_CodeSniffer\Util\Tokens; + /** * Parses and verifies class property doc comments. * - * Laregely copied from Squiz_Sniffs_Commenting_VariableCommentSniff. + * Laregely copied from + * \PHP_CodeSniffer\Standards\Squiz\Sniffs\Commenting\VariableCommentSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Commenting_VariableCommentSniff extends PHP_CodeSniffer_Standards_AbstractVariableSniff +class VariableCommentSniff extends AbstractVariableSniff { /** * Called to process class member vars. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - public function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function processMemberVar(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $commentToken = array( @@ -120,7 +128,7 @@ class Drupal_Sniffs_Commenting_VariableCommentSniff extends PHP_CodeSniffer_Stan // There may be multiple types separated by pipes. $suggestedTypes = array(); foreach (explode('|', $varType) as $type) { - $suggestedTypes[] = Drupal_Sniffs_Commenting_FunctionCommentSniff::suggestType($type); + $suggestedTypes[] = FunctionCommentSniff::suggestType($type); } $suggestedType = implode('|', $suggestedTypes); @@ -157,13 +165,13 @@ class Drupal_Sniffs_Commenting_VariableCommentSniff extends PHP_CodeSniffer_Stan * * Not required for this sniff. * - * @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this token was found. - * @param int $stackPtr The position where the double quoted - * string was found. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where this token was found. + * @param int $stackPtr The position where the double quoted + * string was found. * * @return void */ - protected function processVariable(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + protected function processVariable(File $phpcsFile, $stackPtr) { }//end processVariable() @@ -174,13 +182,13 @@ class Drupal_Sniffs_Commenting_VariableCommentSniff extends PHP_CodeSniffer_Stan * * Not required for this sniff. * - * @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this token was found. - * @param int $stackPtr The position where the double quoted - * string was found. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where this token was found. + * @param int $stackPtr The position where the double quoted + * string was found. * * @return void */ - protected function processVariableInString(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + protected function processVariableInString(File $phpcsFile, $stackPtr) { }//end processVariableInString() diff --git a/coder_sniffer/Drupal/Sniffs/ControlStructures/ControlSignatureSniff.php b/coder_sniffer/Drupal/Sniffs/ControlStructures/ControlSignatureSniff.php index 43f35ebd..ab74cdbe 100644 --- a/coder_sniffer/Drupal/Sniffs/ControlStructures/ControlSignatureSniff.php +++ b/coder_sniffer/Drupal/Sniffs/ControlStructures/ControlSignatureSniff.php @@ -7,17 +7,24 @@ * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\ControlStructures; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Util\Tokens; + /** * Verifies that control statements conform to their coding standards. * - * Largely copied from Squiz_Sniffs_ControlStructures_ControlSignatureSniff and - * adapted for Drupal's else on new lines. + * Largely copied from + * \PHP_CodeSniffer\Standards\Squiz\Sniffs\ControlStructures\ControlSignatureSniff + * and adapted for Drupal's else on new lines. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_ControlStructures_ControlSignatureSniff implements PHP_CodeSniffer_Sniff +class ControlSignatureSniff implements Sniff { /** @@ -57,13 +64,13 @@ class Drupal_Sniffs_ControlStructures_ControlSignatureSniff implements PHP_CodeS /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in the + * stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -155,7 +162,7 @@ class Drupal_Sniffs_ControlStructures_ControlSignatureSniff implements PHP_CodeS // Skip all empty tokens on the same line as the opener. if ($tokens[$next]['line'] === $tokens[$opener]['line'] - && (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$code]) === true + && (isset(Tokens::$emptyTokens[$code]) === true || $code === T_CLOSE_TAG) ) { continue; @@ -248,7 +255,7 @@ class Drupal_Sniffs_ControlStructures_ControlSignatureSniff implements PHP_CodeS || $tokens[$stackPtr]['code'] === T_ELSEIF || $tokens[$stackPtr]['code'] === T_CATCH ) { - $closer = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true); + $closer = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); if ($closer === false || $tokens[$closer]['code'] !== T_CLOSE_CURLY_BRACKET) { return; } diff --git a/coder_sniffer/Drupal/Sniffs/ControlStructures/ElseIfSniff.php b/coder_sniffer/Drupal/Sniffs/ControlStructures/ElseIfSniff.php index 734453d3..aabc0167 100644 --- a/coder_sniffer/Drupal/Sniffs/ControlStructures/ElseIfSniff.php +++ b/coder_sniffer/Drupal/Sniffs/ControlStructures/ElseIfSniff.php @@ -7,6 +7,11 @@ * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\ControlStructures; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** * Checks that "elseif" is used instead of "else if". * @@ -14,7 +19,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_ControlStructures_ElseIfSniff implements PHP_CodeSniffer_Sniff +class ElseIfSniff implements Sniff { @@ -33,13 +38,13 @@ class Drupal_Sniffs_ControlStructures_ElseIfSniff implements PHP_CodeSniffer_Sni /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in the + * stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -54,7 +59,7 @@ class Drupal_Sniffs_ControlStructures_ElseIfSniff implements PHP_CodeSniffer_Sni ); if ($tokens[$nextNonWhiteSpace]['code'] === T_IF) { - $fix = $phpcsFile->addFixableError('Use "elseif" in place of "else if"', $nextNonWhiteSpace); + $fix = $phpcsFile->addFixableError('Use "elseif" in place of "else if"', $nextNonWhiteSpace, 'ElseIfDeclaration'); if ($fix === true) { $phpcsFile->fixer->beginChangeset(); $phpcsFile->fixer->replaceToken($stackPtr, 'elseif'); diff --git a/coder_sniffer/Drupal/Sniffs/ControlStructures/InlineControlStructureSniff.php b/coder_sniffer/Drupal/Sniffs/ControlStructures/InlineControlStructureSniff.php index c2dd39a1..ef1fb70a 100644 --- a/coder_sniffer/Drupal/Sniffs/ControlStructures/InlineControlStructureSniff.php +++ b/coder_sniffer/Drupal/Sniffs/ControlStructures/InlineControlStructureSniff.php @@ -1,14 +1,19 @@ <?php /** - * Drupal_Sniffs_ControlStructures_InlineControlStructureSniff. + * \Drupal\Sniffs\ControlStructures\InlineControlStructureSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\ControlStructures; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Standards\Generic\Sniffs\ControlStructures\InlineControlStructureSniff as GenericInlineControlStructureSniff; + /** - * Drupal_Sniffs_ControlStructures_InlineControlStructureSniff. + * \Drupal\Sniffs\ControlStructures\InlineControlStructureSniff. * * Verifies that inline control statements are not present. This Sniff overides * the generic sniff because Drupal template files may use the alternative @@ -19,21 +24,20 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_ControlStructures_InlineControlStructureSniff -extends Generic_Sniffs_ControlStructures_InlineControlStructureSniff +class InlineControlStructureSniff extends GenericInlineControlStructureSniff { /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in + * the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); diff --git a/coder_sniffer/Drupal/Sniffs/Files/EndFileNewlineSniff.php b/coder_sniffer/Drupal/Sniffs/Files/EndFileNewlineSniff.php index 4f7d7b88..d829cda3 100644 --- a/coder_sniffer/Drupal/Sniffs/Files/EndFileNewlineSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Files/EndFileNewlineSniff.php @@ -1,12 +1,17 @@ <?php /** - * Drupal_Sniffs_Files_EndFileNewlineSniff. + * \Drupal\Sniffs\Files\EndFileNewlineSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Files; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** * Ensures the file ends with a newline character. * @@ -17,7 +22,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Files_EndFileNewlineSniff implements PHP_CodeSniffer_Sniff +class EndFileNewlineSniff implements Sniff { @@ -51,13 +56,13 @@ class Drupal_Sniffs_Files_EndFileNewlineSniff implements PHP_CodeSniffer_Sniff /** * Processes this sniff, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in + * the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { // Skip to the end of the file. $tokens = $phpcsFile->getTokens(); diff --git a/coder_sniffer/Drupal/Sniffs/Files/FileEncodingSniff.php b/coder_sniffer/Drupal/Sniffs/Files/FileEncodingSniff.php index a071f1c6..26a08da1 100644 --- a/coder_sniffer/Drupal/Sniffs/Files/FileEncodingSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Files/FileEncodingSniff.php @@ -1,6 +1,6 @@ <?php /** - * Drupal_Sniffs_Files_FileEncodingSniff. + * \Drupal\Sniffs\Files\FileEncodingSniff. * * @category PHP * @package PHP_CodeSniffer @@ -10,8 +10,13 @@ * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Files; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** - * Drupal_Sniffs_Files_FileEncodingSniff. + * \Drupal\Sniffs\Files\FileEncodingSniff. * * Validates the encoding of a file against a white list of allowed encodings. * @@ -23,7 +28,7 @@ * @version Release: @package_version@ * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Files_FileEncodingSniff implements PHP_CodeSniffer_Sniff +class FileEncodingSniff implements Sniff { /** @@ -54,13 +59,13 @@ class Drupal_Sniffs_Files_FileEncodingSniff implements PHP_CodeSniffer_Sniff /** * Processes this sniff, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in + * the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { // Not all PHP installs have the multi byte extension - nothing we can do. if (function_exists('mb_check_encoding') === false) { diff --git a/coder_sniffer/Drupal/Sniffs/Files/LineLengthSniff.php b/coder_sniffer/Drupal/Sniffs/Files/LineLengthSniff.php index d77987c1..90abba08 100644 --- a/coder_sniffer/Drupal/Sniffs/Files/LineLengthSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Files/LineLengthSniff.php @@ -1,12 +1,18 @@ <?php /** - * Drupal_Sniffs_Files_LineLengthSniff. + * \Drupal\Sniffs\Files\LineLengthSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Files; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineLengthSniff as GenericLineLengthSniff; +use PHP_CodeSniffer\Util\Tokens; + /** * Checks comment lines in the file, and throws warnings if they are over 80 * characters in length. @@ -15,7 +21,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Files_LineLengthSniff extends Generic_Sniffs_Files_LineLengthSniff +class LineLengthSniff extends GenericLineLengthSniff { /** @@ -39,15 +45,15 @@ class Drupal_Sniffs_Files_LineLengthSniff extends Generic_Sniffs_Files_LineLengt /** * Checks if a line is too long. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param array $tokens The token stack. - * @param int $stackPtr The first token on the next line. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param array $tokens The token stack. + * @param int $stackPtr The first token on the next line. * * @return void */ - protected function checkLineLength(PHP_CodeSniffer_File $phpcsFile, $tokens, $stackPtr) + protected function checkLineLength($phpcsFile, $tokens, $stackPtr) { - if (isset(PHP_CodeSniffer_Tokens::$commentTokens[$tokens[($stackPtr - 1)]['code']]) === true) { + 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) { // Allow doc comment tags such as long @param tags to exceed the 80 @@ -105,12 +111,12 @@ class Drupal_Sniffs_Files_LineLengthSniff extends Generic_Sniffs_Files_LineLengt /** * Returns the length of a defined line. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $currentLine The current line. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $currentLine The current line. * * @return int */ - public function getLineLength(PHP_CodeSniffer_File $phpcsFile, $currentLine) + public function getLineLength(File $phpcsFile, $currentLine) { $tokens = $phpcsFile->getTokens(); diff --git a/coder_sniffer/Drupal/Sniffs/Files/TxtFileLineLengthSniff.php b/coder_sniffer/Drupal/Sniffs/Files/TxtFileLineLengthSniff.php index 4ba76dd3..803a9e01 100644 --- a/coder_sniffer/Drupal/Sniffs/Files/TxtFileLineLengthSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Files/TxtFileLineLengthSniff.php @@ -1,14 +1,19 @@ <?php /** - * Drupal_Sniffs_Files_TxtFileLineLengthSniff. + * \Drupal\Sniffs\Files\TxtFileLineLengthSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Files; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** - * Drupal_Sniffs_Files_TxtFileLineLengthSniff. + * \Drupal\Sniffs\Files\TxtFileLineLengthSniff. * * Checks all lines in a *.txt or *.md file and throws warnings if they are over 80 * characters in length. @@ -17,7 +22,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Files_TxtFileLineLengthSniff implements PHP_CodeSniffer_Sniff +class TxtFileLineLengthSniff implements Sniff { @@ -36,13 +41,13 @@ class Drupal_Sniffs_Files_TxtFileLineLengthSniff implements PHP_CodeSniffer_Snif /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in the + * stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $fileExtension = strtolower(substr($phpcsFile->getFilename(), -3)); if ($fileExtension === 'txt' || $fileExtension === '.md') { @@ -51,10 +56,10 @@ class Drupal_Sniffs_Files_TxtFileLineLengthSniff implements PHP_CodeSniffer_Snif $content = rtrim($tokens[$stackPtr]['content']); $lineLength = mb_strlen($content, 'UTF-8'); // Lines without spaces are allowed to be longer (for example long URLs). - // Markdown is allowed to be longer for lines - // - without spaces. - // - starting with #. - // - containing URLs (https://). + // Markdown allowed to be longer for lines + // - without spaces + // - starting with # + // - containing URLs (https://) // - starting with | (tables). if ($lineLength > 80 && preg_match('/^([^ ]+$|#|.*https?:\/\/|\|)/', $content) === 0) { $data = array( diff --git a/coder_sniffer/Drupal/Sniffs/Formatting/MultiLineAssignmentSniff.php b/coder_sniffer/Drupal/Sniffs/Formatting/MultiLineAssignmentSniff.php index c7a52064..4b5c1c91 100644 --- a/coder_sniffer/Drupal/Sniffs/Formatting/MultiLineAssignmentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Formatting/MultiLineAssignmentSniff.php @@ -1,17 +1,19 @@ <?php /** - * PEAR_Sniffs_Functions_FunctionDeclarationSniff. + * \Drupal\Sniffs\Formatting\MultiLineAssignmentSniff. * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood <gsherwood@squiz.net> - * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600) - * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer + * @category PHP + * @package PHP_CodeSniffer + * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Formatting; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** - * Drupal_Sniffs_Formatting_MultiLineAssignmentSniff. + * \Drupal\Sniffs\Formatting\MultiLineAssignmentSniff. * * If an assignment goes over two lines, ensure the equal sign is indented. * @@ -23,7 +25,7 @@ * @version Release: 1.2.0RC3 * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Formatting_MultiLineAssignmentSniff implements PHP_CodeSniffer_Sniff +class MultiLineAssignmentSniff implements Sniff { @@ -42,13 +44,13 @@ class Drupal_Sniffs_Formatting_MultiLineAssignmentSniff implements PHP_CodeSniff /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -91,7 +93,7 @@ class Drupal_Sniffs_Formatting_MultiLineAssignmentSniff implements PHP_CodeSniff $foundIndent = strlen($tokens[$prev]['content']); if ($foundIndent !== $expectedIndent) { $error = "Multi-line assignment not indented correctly; expected $expectedIndent spaces but found $foundIndent"; - $phpcsFile->addError($error, $stackPtr); + $phpcsFile->addError($error, $stackPtr, 'MultiLineAssignmentIndent'); } }//end process() diff --git a/coder_sniffer/Drupal/Sniffs/Formatting/MultipleStatementAlignmentSniff.php b/coder_sniffer/Drupal/Sniffs/Formatting/MultipleStatementAlignmentSniff.php index bc029f27..38071a46 100644 --- a/coder_sniffer/Drupal/Sniffs/Formatting/MultipleStatementAlignmentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Formatting/MultipleStatementAlignmentSniff.php @@ -1,22 +1,28 @@ <?php /** - * Drupal_Sniffs_Formatting_MultipleStatementAlignmentSniff. + * \Drupal\Sniffs\Formatting\MultipleStatementAlignmentSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Formatting; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Standards\Generic\Sniffs\Formatting\MultipleStatementAlignmentSniff as GenericMultipleStatementAlignmentSniff; +use PHP_CodeSniffer\Util\Tokens; + /** * Checks alignment of multiple assignments.Largely copied from - * Generic_Sniffs_Formatting_MultipleStatementAlignmentSniff but also allows multiple - * single space assignments. + * \PHP_CodeSniffer\Standards\Generic\Sniffs\Formatting\MultipleStatementAlignmentSniff + * but also allows multiple single space assignments. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Formatting_MultipleStatementAlignmentSniff extends Generic_Sniffs_Formatting_MultipleStatementAlignmentSniff +class MultipleStatementAlignmentSniff extends GenericMultipleStatementAlignmentSniff { @@ -31,13 +37,13 @@ class Drupal_Sniffs_Formatting_MultipleStatementAlignmentSniff extends Generic_S /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return int */ - public function checkAlignment(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function checkAlignment($phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -49,13 +55,13 @@ class Drupal_Sniffs_Formatting_MultipleStatementAlignmentSniff extends Generic_S $lastCode = $stackPtr; $lastSemi = null; - $find = PHP_CodeSniffer_Tokens::$assignmentTokens; + $find = Tokens::$assignmentTokens; unset($find[T_DOUBLE_ARROW]); for ($assign = $stackPtr; $assign < $phpcsFile->numTokens; $assign++) { if (isset($find[$tokens[$assign]['code']]) === false) { // A blank line indicates that the assignment block has ended. - if (isset(PHP_CodeSniffer_tokens::$emptyTokens[$tokens[$assign]['code']]) === false) { + if (isset(Tokens::$emptyTokens[$tokens[$assign]['code']]) === false) { if (($tokens[$assign]['line'] - $tokens[$lastCode]['line']) > 1) { break; } @@ -101,7 +107,7 @@ class Drupal_Sniffs_Formatting_MultipleStatementAlignmentSniff extends Generic_S }//end if $var = $phpcsFile->findPrevious( - PHP_CodeSniffer_Tokens::$emptyTokens, + Tokens::$emptyTokens, ($assign - 1), null, true diff --git a/coder_sniffer/Drupal/Sniffs/Formatting/SpaceInlineIfSniff.php b/coder_sniffer/Drupal/Sniffs/Formatting/SpaceInlineIfSniff.php index 138f5b19..8634c595 100644 --- a/coder_sniffer/Drupal/Sniffs/Formatting/SpaceInlineIfSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Formatting/SpaceInlineIfSniff.php @@ -1,12 +1,17 @@ <?php /** - * Drupal_Sniffs_Formatting_SpaceInlineIfSniff. + * \Drupal\Sniffs\Formatting\SpaceInlineIfSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Formatting; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** * Checks that there is no space between "?" and ":" inline if/else statements. * @@ -14,7 +19,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Formatting_SpaceInlineIfSniff implements PHP_CodeSniffer_Sniff +class SpaceInlineIfSniff implements Sniff { @@ -33,13 +38,13 @@ class Drupal_Sniffs_Formatting_SpaceInlineIfSniff implements PHP_CodeSniffer_Sni /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in + * the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); diff --git a/coder_sniffer/Drupal/Sniffs/Formatting/SpaceUnaryOperatorSniff.php b/coder_sniffer/Drupal/Sniffs/Formatting/SpaceUnaryOperatorSniff.php index 91bca8ca..6fb7e18a 100644 --- a/coder_sniffer/Drupal/Sniffs/Formatting/SpaceUnaryOperatorSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Formatting/SpaceUnaryOperatorSniff.php @@ -1,14 +1,20 @@ <?php /** - * Drupal_Sniffs_Formatting_SpaceUnaryOperatorSniff. + * \Drupal\Sniffs\Formatting\SpaceUnaryOperatorSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Formatting; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Util\Tokens; + /** - * Drupal_Sniffs_Formatting_SpaceUnaryOperatorSniff. + * \PHP_CodeSniffer\Standards\Generic\Sniffs\Formatting\SpaceUnaryOperatorSniff. * * Ensures there are no spaces on increment / decrement statements or on +/- sign * operators or "!" boolean negators. @@ -17,7 +23,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Formatting_SpaceUnaryOperatorSniff implements PHP_CodeSniffer_Sniff +class SpaceUnaryOperatorSniff implements Sniff { @@ -42,19 +48,19 @@ class Drupal_Sniffs_Formatting_SpaceUnaryOperatorSniff implements PHP_CodeSniffe /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in + * the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); // Check decrement / increment. if ($tokens[$stackPtr]['code'] === T_DEC || $tokens[$stackPtr]['code'] === T_INC) { - $previous = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true); + $previous = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); $modifyLeft = in_array( $tokens[$previous]['code'], array( diff --git a/coder_sniffer/Drupal/Sniffs/Functions/DiscouragedFunctionsSniff.php b/coder_sniffer/Drupal/Sniffs/Functions/DiscouragedFunctionsSniff.php index e82c67d1..d23f809e 100644 --- a/coder_sniffer/Drupal/Sniffs/Functions/DiscouragedFunctionsSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Functions/DiscouragedFunctionsSniff.php @@ -1,12 +1,16 @@ <?php /** - * Drupal_Sniffs_Functions_DiscouragedFunctionsSniff. + * \Drupal\Sniffs\Functions\DiscouragedFunctionsSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Functions; + +use PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\ForbiddenFunctionsSniff; + /** * Discourage the use of debug functions. * @@ -14,7 +18,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Functions_DiscouragedFunctionsSniff extends Generic_Sniffs_PHP_ForbiddenFunctionsSniff +class DiscouragedFunctionsSniff extends ForbiddenFunctionsSniff { /** diff --git a/coder_sniffer/Drupal/Sniffs/Functions/FunctionDeclarationSniff.php b/coder_sniffer/Drupal/Sniffs/Functions/FunctionDeclarationSniff.php index b539a647..c4d26a0d 100644 --- a/coder_sniffer/Drupal/Sniffs/Functions/FunctionDeclarationSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Functions/FunctionDeclarationSniff.php @@ -1,12 +1,17 @@ <?php /** - * Drupal_Sniffs_Functions_FunctionDeclarationSniff. + * \Drupal\Sniffs\Functions\FunctionDeclarationSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Functions; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** * Ensure that there is only one space after the function keyword and no space * before the opening parenthesis. @@ -18,7 +23,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Functions_FunctionDeclarationSniff implements PHP_CodeSniffer_Sniff +class FunctionDeclarationSniff implements Sniff { @@ -37,13 +42,13 @@ class Drupal_Sniffs_Functions_FunctionDeclarationSniff implements PHP_CodeSniffe /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); diff --git a/coder_sniffer/Drupal/Sniffs/InfoFiles/AutoAddedKeysSniff.php b/coder_sniffer/Drupal/Sniffs/InfoFiles/AutoAddedKeysSniff.php index ee72d42a..98e474e4 100644 --- a/coder_sniffer/Drupal/Sniffs/InfoFiles/AutoAddedKeysSniff.php +++ b/coder_sniffer/Drupal/Sniffs/InfoFiles/AutoAddedKeysSniff.php @@ -1,12 +1,18 @@ <?php /** - * Drupal_Sniffs_InfoFiles_RequiredSniff. + * \Drupal\Sniffs\InfoFiles\RequiredSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\InfoFiles; + +use Drupal\Sniffs\InfoFiles\ClassFilesSniff; +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** * "version", "project" and "timestamp" are added automatically by drupal.org * packaging scripts. @@ -15,7 +21,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_InfoFiles_AutoAddedKeysSniff implements PHP_CodeSniffer_Sniff +class AutoAddedKeysSniff implements Sniff { @@ -34,19 +40,19 @@ class Drupal_Sniffs_InfoFiles_AutoAddedKeysSniff implements PHP_CodeSniffer_Snif /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in the + * stack passed in $tokens. * * @return int */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { // Only run this sniff once per info file. if (preg_match('/\.info$/', $phpcsFile->getFilename()) === 1) { // Drupal 7 style info file. $contents = file_get_contents($phpcsFile->getFilename()); - $info = Drupal_Sniffs_InfoFiles_ClassFilesSniff::drupalParseInfoFormat($contents); + $info = ClassFilesSniff::drupalParseInfoFormat($contents); } else if (preg_match('/\.info\.yml$/', $phpcsFile->getFilename()) === 1) { // Drupal 8 style info.yml file. $contents = file_get_contents($phpcsFile->getFilename()); diff --git a/coder_sniffer/Drupal/Sniffs/InfoFiles/ClassFilesSniff.php b/coder_sniffer/Drupal/Sniffs/InfoFiles/ClassFilesSniff.php index 733e13fb..681e1989 100644 --- a/coder_sniffer/Drupal/Sniffs/InfoFiles/ClassFilesSniff.php +++ b/coder_sniffer/Drupal/Sniffs/InfoFiles/ClassFilesSniff.php @@ -1,12 +1,17 @@ <?php /** - * Drupal_Sniffs_InfoFiles_ClassFilesSniff. + * \Drupal\Sniffs\InfoFiles\ClassFilesSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\InfoFiles; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** * Checks files[] entries in info files. Only files containing classes/interfaces * should be listed. @@ -15,7 +20,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_InfoFiles_ClassFilesSniff implements PHP_CodeSniffer_Sniff +class ClassFilesSniff implements Sniff { @@ -34,13 +39,13 @@ class Drupal_Sniffs_InfoFiles_ClassFilesSniff implements PHP_CodeSniffer_Sniff /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in the + * stack passed in $tokens. * * @return int */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { // Only run this sniff once per info file. $fileExtension = strtolower(substr($phpcsFile->getFilename(), -4)); @@ -87,14 +92,14 @@ class Drupal_Sniffs_InfoFiles_ClassFilesSniff implements PHP_CodeSniffer_Sniff /** * Helper function that returns the position of the key in the info file. * - * @param string $key Key name to search for. - * @param string $value Corresponding value to search for. - * @param PHP_CodeSniffer_File $infoFile Info file to search in. + * @param string $key Key name to search for. + * @param string $value Corresponding value to search for. + * @param \PHP_CodeSniffer\Files\File $infoFile Info file to search in. * * @return int|false Returns the stack position if the file name is found, false * otherwise. */ - public static function getPtr($key, $value, PHP_CodeSniffer_File $infoFile) + public static function getPtr($key, $value, File $infoFile) { foreach ($infoFile->getTokens() as $ptr => $tokenInfo) { if (preg_match('@^[\s]*'.preg_quote($key).'[\s]*=[\s]*["\']?'.preg_quote($value).'["\']?@', $tokenInfo['content']) === 1) { diff --git a/coder_sniffer/Drupal/Sniffs/InfoFiles/DuplicateEntrySniff.php b/coder_sniffer/Drupal/Sniffs/InfoFiles/DuplicateEntrySniff.php index 974c408c..a6d52858 100644 --- a/coder_sniffer/Drupal/Sniffs/InfoFiles/DuplicateEntrySniff.php +++ b/coder_sniffer/Drupal/Sniffs/InfoFiles/DuplicateEntrySniff.php @@ -1,12 +1,17 @@ <?php /** - * Drupal_Sniffs_InfoFiles_DuplicateEntrySniff. + * \Drupal\Sniffs\InfoFiles\DuplicateEntrySniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\InfoFiles; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** * Make sure that entries in info files are specified only once. * @@ -14,7 +19,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_InfoFiles_DuplicateEntrySniff implements PHP_CodeSniffer_Sniff +class DuplicateEntrySniff implements Sniff { @@ -33,13 +38,13 @@ class Drupal_Sniffs_InfoFiles_DuplicateEntrySniff implements PHP_CodeSniffer_Sni /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in the + * stack passed in $tokens. * * @return int */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { // Only run this sniff once per info file. $fileExtension = strtolower(substr($phpcsFile->getFilename(), -4)); diff --git a/coder_sniffer/Drupal/Sniffs/InfoFiles/RequiredSniff.php b/coder_sniffer/Drupal/Sniffs/InfoFiles/RequiredSniff.php index 941c197f..67a03c56 100644 --- a/coder_sniffer/Drupal/Sniffs/InfoFiles/RequiredSniff.php +++ b/coder_sniffer/Drupal/Sniffs/InfoFiles/RequiredSniff.php @@ -1,12 +1,18 @@ <?php /** - * Drupal_Sniffs_InfoFiles_RequiredSniff. + * \Drupal\Sniffs\InfoFiles\RequiredSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\InfoFiles; + +use Drupal\Sniffs\InfoFiles\ClassFilesSniff; +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** * "name", "description" and "core are required fields in Drupal info files. Also * checks the "php" minimum requirement for Drupal 7. @@ -15,7 +21,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_InfoFiles_RequiredSniff implements PHP_CodeSniffer_Sniff +class RequiredSniff implements Sniff { @@ -34,13 +40,13 @@ class Drupal_Sniffs_InfoFiles_RequiredSniff implements PHP_CodeSniffer_Sniff /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in the + * stack passed in $tokens. * * @return int */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { // Only run this sniff once per info file. $fileExtension = strtolower(substr($phpcsFile->getFilename(), -4)); @@ -49,7 +55,7 @@ class Drupal_Sniffs_InfoFiles_RequiredSniff implements PHP_CodeSniffer_Sniff } $contents = file_get_contents($phpcsFile->getFilename()); - $info = Drupal_Sniffs_InfoFiles_ClassFilesSniff::drupalParseInfoFormat($contents); + $info = ClassFilesSniff::drupalParseInfoFormat($contents); if (isset($info['name']) === false) { $error = '"name" property is missing in the info file'; $phpcsFile->addError($error, $stackPtr, 'Name'); @@ -67,7 +73,7 @@ class Drupal_Sniffs_InfoFiles_RequiredSniff implements PHP_CodeSniffer_Sniff && $info['php'] <= '5.2' ) { $error = 'Drupal 7 core already requires PHP 5.2'; - $ptr = Drupal_Sniffs_InfoFiles_ClassFilesSniff::getPtr('php', $info['php'], $phpcsFile); + $ptr = ClassFilesSniff::getPtr('php', $info['php'], $phpcsFile); $phpcsFile->addError($error, $ptr, 'D7PHPVersion'); } diff --git a/coder_sniffer/Drupal/Sniffs/Methods/MethodDeclarationSniff.php b/coder_sniffer/Drupal/Sniffs/Methods/MethodDeclarationSniff.php index 63661a0b..d36b32db 100644 --- a/coder_sniffer/Drupal/Sniffs/Methods/MethodDeclarationSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Methods/MethodDeclarationSniff.php @@ -1,22 +1,29 @@ <?php /** - * Drupal_Sniffs_Methods_MethodDeclarationSniff. + * \Drupal\Sniffs\Methods\MethodDeclarationSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Methods; + +use PHP_CodeSniffer\Sniffs\AbstractScopeSniff; +use PHP_CodeSniffer\Standards\PSR2\Sniffs\Methods\MethodDeclarationSniff as PSR2MethodDeclarationSniff; + /** * Checks that the method declaration is correct. * - * Extending PSR2_Sniffs_Methods_MethodDeclarationSniff to also support traits. + * Extending + * \PHP_CodeSniffer\Standards\PSR2\Sniffs\Methods\MethodDeclarationSniff + * to also support traits. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Methods_MethodDeclarationSniff extends PSR2_Sniffs_Methods_MethodDeclarationSniff +class MethodDeclarationSniff extends PSR2MethodDeclarationSniff { @@ -25,7 +32,7 @@ class Drupal_Sniffs_Methods_MethodDeclarationSniff extends PSR2_Sniffs_Methods_M */ public function __construct() { - PHP_CodeSniffer_Standards_AbstractScopeSniff::__construct(array(T_CLASS, T_INTERFACE, T_TRAIT), array(T_FUNCTION)); + AbstractScopeSniff::__construct(array(T_CLASS, T_INTERFACE, T_TRAIT), array(T_FUNCTION)); }//end __construct() diff --git a/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidClassNameSniff.php b/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidClassNameSniff.php index 0d6a90a1..5f3ca71b 100644 --- a/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidClassNameSniff.php +++ b/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidClassNameSniff.php @@ -1,6 +1,6 @@ <?php /** - * Drupal_Sniffs_NamingConventions_ValidClassNameSniff. + * \Drupal\Sniffs\NamingConventions\ValidClassNameSniff. * * @category PHP * @package PHP_CodeSniffer @@ -11,8 +11,13 @@ * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\NamingConventions; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** - * Drupal_Sniffs_NamingConventions_ValidClassNameSniff. + * \Drupal\Sniffs\NamingConventions\ValidClassNameSniff. * * Ensures class and interface names start with a capital letter * and do not use _ separators. @@ -26,7 +31,7 @@ * @version Release: 1.2.0RC3 * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_NamingConventions_ValidClassNameSniff implements PHP_CodeSniffer_Sniff +class ValidClassNameSniff implements Sniff { @@ -48,13 +53,13 @@ class Drupal_Sniffs_NamingConventions_ValidClassNameSniff implements PHP_CodeSni /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The current file being processed. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The current file being processed. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); diff --git a/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidFunctionNameSniff.php b/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidFunctionNameSniff.php index b0b0f4af..5f6b1ab7 100644 --- a/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidFunctionNameSniff.php +++ b/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidFunctionNameSniff.php @@ -1,38 +1,45 @@ <?php /** - * Drupal_Sniffs_NamingConventions_ValidFunctionNameSniff. + * \Drupal\Sniffs\NamingConventions\ValidFunctionNameSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\NamingConventions; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff; +use PHP_CodeSniffer\Util\Common; + /** - * Drupal_Sniffs_NamingConventions_ValidFunctionNameSniff. + * \Drupal\Sniffs\NamingConventions\ValidFunctionNameSniff. * - * Extends Generic_Sniffs_NamingConventions_CamelCapsFunctionNameSniff to also check - * global function names outside the scope of classes and to not allow methods - * beginning with an underscore. + * Extends + * \PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff + * to also check global function names outside the scope of classes and to not + * allow methods beginning with an underscore. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_NamingConventions_ValidFunctionNameSniff extends Generic_Sniffs_NamingConventions_CamelCapsFunctionNameSniff +class ValidFunctionNameSniff extends CamelCapsFunctionNameSniff { /** * Processes the tokens within the scope. * - * @param PHP_CodeSniffer_File $phpcsFile The file being processed. - * @param int $stackPtr The position where this token was - * found. - * @param int $currScope The position of the current scope. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being processed. + * @param int $stackPtr The position where this token was + * found. + * @param int $currScope The position of the current scope. * * @return void */ - protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope) + protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope) { $methodName = $phpcsFile->getDeclarationName($stackPtr); if ($methodName === null) { @@ -57,7 +64,7 @@ class Drupal_Sniffs_NamingConventions_ValidFunctionNameSniff extends Generic_Sni } $methodProps = $phpcsFile->getMethodProperties($stackPtr); - if (PHP_CodeSniffer::isCamelCaps($methodName, false, true, $this->strict) === false) { + 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( @@ -82,13 +89,13 @@ class Drupal_Sniffs_NamingConventions_ValidFunctionNameSniff extends Generic_Sni /** * Processes the tokens outside the scope. * - * @param PHP_CodeSniffer_File $phpcsFile The file being processed. - * @param int $stackPtr The position where this token was - * found. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being processed. + * @param int $stackPtr The position where this token was + * found. * * @return void */ - protected function processTokenOutsideScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + protected function processTokenOutsideScope(File $phpcsFile, $stackPtr) { $functionName = $phpcsFile->getDeclarationName($stackPtr); if ($functionName === null) { diff --git a/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidGlobalSniff.php b/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidGlobalSniff.php index 1422c485..91666759 100644 --- a/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidGlobalSniff.php +++ b/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidGlobalSniff.php @@ -1,12 +1,18 @@ <?php /** - * Drupal_Sniffs_NamingConventions_ValidGlobalSniff. + * \Drupal\Sniffs\NamingConventions\ValidGlobalSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\NamingConventions; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Util\Tokens; + /** * Ensures that global variables start with an underscore. * @@ -14,7 +20,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_NamingConventions_ValidGlobalSniff implements PHP_CodeSniffer_Sniff +class ValidGlobalSniff implements Sniff { public $coreGlobals = array( @@ -83,19 +89,19 @@ class Drupal_Sniffs_NamingConventions_ValidGlobalSniff implements PHP_CodeSniffe /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The current file being processed. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The current file being processed. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $varToken = $stackPtr; // Find variable names until we hit a semicolon. - $ignore = PHP_CodeSniffer_Tokens::$emptyTokens; + $ignore = Tokens::$emptyTokens; $ignore[] = T_SEMICOLON; while (($varToken = $phpcsFile->findNext($ignore, ($varToken + 1), null, true, null, true)) !== false) { if ($tokens[$varToken]['code'] === T_VARIABLE diff --git a/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidVariableNameSniff.php b/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidVariableNameSniff.php index d092ea84..4f8cf0aa 100644 --- a/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidVariableNameSniff.php +++ b/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidVariableNameSniff.php @@ -1,14 +1,19 @@ <?php /** - * Drupal_Sniffs_NamingConventions_ValidVariableNameSniff. + * \Drupal\Sniffs\NamingConventions\ValidVariableNameSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\NamingConventions; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\AbstractVariableSniff; + /** - * Drupal_Sniffs_NamingConventions_ValidVariableNameSniff. + * \Drupal\Sniffs\NamingConventions\ValidVariableNameSniff. * * Checks the naming of member variables. * @@ -16,22 +21,20 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_NamingConventions_ValidVariableNameSniff - - extends PHP_CodeSniffer_Standards_AbstractVariableSniff +class ValidVariableNameSniff extends AbstractVariableSniff { /** * Processes class member variables. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - protected function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + protected function processMemberVar(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -71,12 +74,12 @@ class Drupal_Sniffs_NamingConventions_ValidVariableNameSniff /** * Processes normal variables. * - * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found. - * @param int $stackPtr The position where the token was found. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. + * @param int $stackPtr The position where the token was found. * * @return void */ - protected function processVariable(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + protected function processVariable(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -115,12 +118,12 @@ class Drupal_Sniffs_NamingConventions_ValidVariableNameSniff /** * Processes variables in double quoted strings. * - * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found. - * @param int $stackPtr The position where the token was found. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. + * @param int $stackPtr The position where the token was found. * * @return void */ - protected function processVariableInString(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + protected function processVariableInString(File $phpcsFile, $stackPtr) { // We don't care about variables in strings. return; diff --git a/coder_sniffer/Drupal/Sniffs/Scope/MethodScopeSniff.php b/coder_sniffer/Drupal/Sniffs/Scope/MethodScopeSniff.php index 6831beb5..bd8532e8 100644 --- a/coder_sniffer/Drupal/Sniffs/Scope/MethodScopeSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Scope/MethodScopeSniff.php @@ -7,22 +7,30 @@ * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Scope; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\AbstractScopeSniff; +use PHP_CodeSniffer\Util\Tokens; + /** * Verifies that class/interface/trait methods have scope modifiers. * - * Laregely copied from Squiz_Sniffs_Scope_MethodScopeSniff to work on traits - * and have a fixer. + * Laregely copied from + * \PHP_CodeSniffer\Standards\Squiz\Sniffs\Scope\MethodScopeSniff to work on + * traits and have a fixer. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Scope_MethodScopeSniff extends PHP_CodeSniffer_Standards_AbstractScopeSniff +class MethodScopeSniff extends AbstractScopeSniff { /** - * Constructs a Squiz_Sniffs_Scope_MethodScopeSniff. + * Constructs a + * \PHP_CodeSniffer\Standards\Squiz\Sniffs\Scope\MethodScopeSniff. */ public function __construct() { @@ -34,13 +42,13 @@ class Drupal_Sniffs_Scope_MethodScopeSniff extends PHP_CodeSniffer_Standards_Abs /** * Processes the function tokens within the class. * - * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found. - * @param int $stackPtr The position where the token was found. - * @param int $currScope The current scope opener token. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. + * @param int $stackPtr The position where the token was found. + * @param int $currScope The current scope opener token. * * @return void */ - protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope) + protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope) { $tokens = $phpcsFile->getTokens(); @@ -59,7 +67,7 @@ class Drupal_Sniffs_Scope_MethodScopeSniff extends PHP_CodeSniffer_Standards_Abs for ($i = ($stackPtr - 1); $i > 0; $i--) { if ($tokens[$i]['line'] < $tokens[$stackPtr]['line']) { break; - } else if (isset(PHP_CodeSniffer_Tokens::$scopeModifiers[$tokens[$i]['code']]) === true) { + } else if (isset(Tokens::$scopeModifiers[$tokens[$i]['code']]) === true) { $modifier = $i; break; } @@ -80,4 +88,20 @@ class Drupal_Sniffs_Scope_MethodScopeSniff extends PHP_CodeSniffer_Standards_Abs }//end processTokenWithinScope() + /** + * Processes a token that is found outside the scope that this test is + * listening to. + * + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. + * @param int $stackPtr The position in the stack where this + * token was found. + * + * @return void + */ + protected function processTokenOutsideScope(File $phpcsFile, $stackPtr) + { + + }//end processTokenOutsideScope() + + }//end class diff --git a/coder_sniffer/Drupal/Sniffs/Semantics/ConstantNameSniff.php b/coder_sniffer/Drupal/Sniffs/Semantics/ConstantNameSniff.php index d9903f5f..9fb999d0 100644 --- a/coder_sniffer/Drupal/Sniffs/Semantics/ConstantNameSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Semantics/ConstantNameSniff.php @@ -1,12 +1,17 @@ <?php /** - * Drupal_Sniffs_Semantics_ConstantNameSniff + * \Drupal\Sniffs\Semantics\ConstantNameSniff * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Semantics; + +use Drupal\Sniffs\Semantics\FunctionCall; +use PHP_CodeSniffer\Files\File; + /** * Checks that constants introduced with define() in module or install files start * with the module's name. @@ -15,7 +20,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Semantics_ConstantNameSniff extends Drupal_Sniffs_Semantics_FunctionCall +class ConstantNameSniff extends FunctionCall { @@ -34,18 +39,18 @@ class Drupal_Sniffs_Semantics_ConstantNameSniff extends Drupal_Sniffs_Semantics_ /** * Processes this function call. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the function call in - * the stack. - * @param int $openBracket The position of the opening - * parenthesis in the stack. - * @param int $closeBracket The position of the closing - * parenthesis in the stack. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the function call in + * the stack. + * @param int $openBracket The position of the opening + * parenthesis in the stack. + * @param int $closeBracket The position of the closing + * parenthesis in the stack. * * @return void */ public function processFunctionCall( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $openBracket, $closeBracket diff --git a/coder_sniffer/Drupal/Sniffs/Semantics/EmptyInstallSniff.php b/coder_sniffer/Drupal/Sniffs/Semantics/EmptyInstallSniff.php index a042fbcc..d747d705 100644 --- a/coder_sniffer/Drupal/Sniffs/Semantics/EmptyInstallSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Semantics/EmptyInstallSniff.php @@ -1,12 +1,18 @@ <?php /** - * Drupal_Sniffs_Semantics_EmptyInstallSniff. + * \Drupal\Sniffs\Semantics\EmptyInstallSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Semantics; + +use Drupal\Sniffs\Semantics\FunctionDefinition; +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Util\Tokens; + /** * Throws an error if hook_install() or hook_uninstall() definitions are empty. * @@ -14,22 +20,22 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Semantics_EmptyInstallSniff extends Drupal_Sniffs_Semantics_FunctionDefinition +class EmptyInstallSniff extends FunctionDefinition { /** * Process this function definition. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the function name in the stack. - * name in the stack. - * @param int $functionPtr The position of the function keyword in the stack. - * keyword in the stack. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the function name in the stack. + * name in the stack. + * @param int $functionPtr The position of the function keyword in the stack. + * keyword in the stack. * * @return void */ - public function processFunction(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $functionPtr) + public function processFunction(File $phpcsFile, $stackPtr, $functionPtr) { $fileExtension = strtolower(substr($phpcsFile->getFilename(), -7)); // Only check in *.install files. @@ -44,7 +50,7 @@ class Drupal_Sniffs_Semantics_EmptyInstallSniff extends Drupal_Sniffs_Semantics_ ) { // Check if there is a function body. $bodyPtr = $phpcsFile->findNext( - PHP_CodeSniffer_Tokens::$emptyTokens, + Tokens::$emptyTokens, ($tokens[$functionPtr]['scope_opener'] + 1), $tokens[$functionPtr]['scope_closer'], true diff --git a/coder_sniffer/Drupal/Sniffs/Semantics/FunctionAliasSniff.php b/coder_sniffer/Drupal/Sniffs/Semantics/FunctionAliasSniff.php index 39a2a87a..ee7e12af 100644 --- a/coder_sniffer/Drupal/Sniffs/Semantics/FunctionAliasSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Semantics/FunctionAliasSniff.php @@ -1,12 +1,17 @@ <?php /** - * Drupal_Sniffs_Semantics_FunctionAliasSniff + * \Drupal\Sniffs\Semantics\FunctionAliasSniff * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Semantics; + +use Drupal\Sniffs\Semantics\FunctionCall; +use PHP_CodeSniffer\Files\File; + /** * Checks that no PHP function name aliases are used. * @@ -14,7 +19,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Semantics_FunctionAliasSniff extends Drupal_Sniffs_Semantics_FunctionCall +class FunctionAliasSniff extends FunctionCall { /** @@ -191,18 +196,18 @@ class Drupal_Sniffs_Semantics_FunctionAliasSniff extends Drupal_Sniffs_Semantics /** * Processes this function call. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the function call in - * the stack. - * @param int $openBracket The position of the opening - * parenthesis in the stack. - * @param int $closeBracket The position of the closing - * parenthesis in the stack. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the function call in + * the stack. + * @param int $openBracket The position of the opening + * parenthesis in the stack. + * @param int $closeBracket The position of the closing + * parenthesis in the stack. * * @return void */ public function processFunctionCall( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $openBracket, $closeBracket diff --git a/coder_sniffer/Drupal/Sniffs/Semantics/FunctionCall.php b/coder_sniffer/Drupal/Sniffs/Semantics/FunctionCall.php index 2570d02f..daa4f234 100644 --- a/coder_sniffer/Drupal/Sniffs/Semantics/FunctionCall.php +++ b/coder_sniffer/Drupal/Sniffs/Semantics/FunctionCall.php @@ -1,12 +1,18 @@ <?php /** - * Drupal_Sniffs_Semantics_FunctionCall. + * \Drupal\Sniffs\Semantics\FunctionCall. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Semantics; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Util\Tokens; + /** * Helper class to sniff for specific function calls. * @@ -14,13 +20,13 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -abstract class Drupal_Sniffs_Semantics_FunctionCall implements PHP_CodeSniffer_Sniff +abstract class FunctionCall implements Sniff { /** * The currently processed file. * - * @var PHP_CodeSniffer_File + * @var \PHP_CodeSniffer\Files\File */ protected $phpcsFile; @@ -76,13 +82,13 @@ abstract class Drupal_Sniffs_Semantics_FunctionCall implements PHP_CodeSniffer_S /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $functionName = $tokens[$stackPtr]['content']; @@ -96,7 +102,7 @@ abstract class Drupal_Sniffs_Semantics_FunctionCall implements PHP_CodeSniffer_S } // Find the next non-empty token. - $openBracket = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true); + $openBracket = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); $this->phpcsFile = $phpcsFile; $this->functionCall = $stackPtr; @@ -112,17 +118,17 @@ abstract class Drupal_Sniffs_Semantics_FunctionCall implements PHP_CodeSniffer_S /** * Checks if this is a function call. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return bool */ - protected function isFunctionCall(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + protected function isFunctionCall(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); // Find the next non-empty token. - $openBracket = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true); + $openBracket = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) { // Not a function call. @@ -135,7 +141,7 @@ abstract class Drupal_Sniffs_Semantics_FunctionCall implements PHP_CodeSniffer_S } // Find the previous non-empty token. - $search = PHP_CodeSniffer_Tokens::$emptyTokens; + $search = Tokens::$emptyTokens; $search[] = T_BITWISE_AND; $previous = $phpcsFile->findPrevious($search, ($stackPtr - 1), null, true); if ($tokens[$previous]['code'] === T_FUNCTION) { @@ -175,14 +181,14 @@ abstract class Drupal_Sniffs_Semantics_FunctionCall implements PHP_CodeSniffer_S $tokens = $this->phpcsFile->getTokens(); // Start token of the first argument. - $start = $this->phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($this->openBracket + 1), null, true); + $start = $this->phpcsFile->findNext(Tokens::$emptyTokens, ($this->openBracket + 1), null, true); if ($start === $this->closeBracket) { // Function call has no arguments, so return false. return false; } // End token of the last argument. - $end = $this->phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($this->closeBracket - 1), null, true); + $end = $this->phpcsFile->findPrevious(Tokens::$emptyTokens, ($this->closeBracket - 1), null, true); $lastArgEnd = $end; $nextSeperator = $this->openBracket; $counter = 1; @@ -196,7 +202,7 @@ abstract class Drupal_Sniffs_Semantics_FunctionCall implements PHP_CodeSniffer_S } // Update the end token of the current argument. - $end = $this->phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($nextSeperator - 1), null, true); + $end = $this->phpcsFile->findPrevious(Tokens::$emptyTokens, ($nextSeperator - 1), null, true); // Save the calculated findings for the current argument. $this->arguments[$counter] = array( 'start' => $start, @@ -207,7 +213,7 @@ abstract class Drupal_Sniffs_Semantics_FunctionCall implements PHP_CodeSniffer_S } $counter++; - $start = $this->phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($nextSeperator + 1), null, true); + $start = $this->phpcsFile->findNext(Tokens::$emptyTokens, ($nextSeperator + 1), null, true); $end = $lastArgEnd; }//end while diff --git a/coder_sniffer/Drupal/Sniffs/Semantics/FunctionDefinition.php b/coder_sniffer/Drupal/Sniffs/Semantics/FunctionDefinition.php index 02ab3036..7d047acd 100644 --- a/coder_sniffer/Drupal/Sniffs/Semantics/FunctionDefinition.php +++ b/coder_sniffer/Drupal/Sniffs/Semantics/FunctionDefinition.php @@ -1,12 +1,18 @@ <?php /** - * Drupal_Sniffs_Semantics_FunctionDefinition. + * \Drupal\Sniffs\Semantics\FunctionDefinition. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Semantics; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Util\Tokens; + /** * Helper class to sniff for function definitions. * @@ -14,7 +20,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -abstract class Drupal_Sniffs_Semantics_FunctionDefinition implements PHP_CodeSniffer_Sniff +abstract class FunctionDefinition implements Sniff { @@ -33,18 +39,18 @@ abstract class Drupal_Sniffs_Semantics_FunctionDefinition implements PHP_CodeSni /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); // Check if this is a function definition. $functionPtr = $phpcsFile->findPrevious( - PHP_CodeSniffer_Tokens::$emptyTokens, + Tokens::$emptyTokens, ($stackPtr - 1), null, true @@ -59,15 +65,15 @@ abstract class Drupal_Sniffs_Semantics_FunctionDefinition implements PHP_CodeSni /** * Process this function definition. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the function name in the stack. - * name in the stack. - * @param int $functionPtr The position of the function keyword in the stack. - * keyword in the stack. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the function name in the stack. + * name in the stack. + * @param int $functionPtr The position of the function keyword in the stack. + * keyword in the stack. * * @return void */ - public abstract function processFunction(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $functionPtr); + public abstract 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 e5385857..cbf3f7fa 100644 --- a/coder_sniffer/Drupal/Sniffs/Semantics/FunctionTSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Semantics/FunctionTSniff.php @@ -1,12 +1,18 @@ <?php /** - * Drupal_Sniffs_Semantics_FunctionTSniff + * \Drupal\Sniffs\Semantics\FunctionTSniff * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Semantics; + +use Drupal\Sniffs\Semantics\FunctionCall; +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Util\Tokens; + /** * Check the usage of the t() function to not escape translateable strings with back * slashes. Also checks that the first argument does not use string concatenation. @@ -15,7 +21,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Semantics_FunctionTSniff extends Drupal_Sniffs_Semantics_FunctionCall +class FunctionTSniff extends FunctionCall { /** @@ -45,18 +51,18 @@ class Drupal_Sniffs_Semantics_FunctionTSniff extends Drupal_Sniffs_Semantics_Fun /** * Processes this function call. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the function call in - * the stack. - * @param int $openBracket The position of the opening - * parenthesis in the stack. - * @param int $closeBracket The position of the closing - * parenthesis in the stack. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the function call in + * the stack. + * @param int $openBracket The position of the opening + * parenthesis in the stack. + * @param int $closeBracket The position of the closing + * parenthesis in the stack. * * @return void */ public function processFunctionCall( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $openBracket, $closeBracket @@ -84,9 +90,9 @@ class Drupal_Sniffs_Semantics_FunctionTSniff extends Drupal_Sniffs_Semantics_Fun return; } - $concatAfter = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($closeBracket + 1), null, true, null, true); + $concatAfter = $phpcsFile->findNext(Tokens::$emptyTokens, ($closeBracket + 1), null, true, null, true); if ($concatAfter !== false && $tokens[$concatAfter]['code'] === T_STRING_CONCAT) { - $stringAfter = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($concatAfter + 1), null, true, null, true); + $stringAfter = $phpcsFile->findNext(Tokens::$emptyTokens, ($concatAfter + 1), null, true, null, true); if ($stringAfter !== false && $tokens[$stringAfter]['code'] === T_CONSTANT_ENCAPSED_STRING && $this->checkConcatString($tokens[$stringAfter]['content']) === false diff --git a/coder_sniffer/Drupal/Sniffs/Semantics/FunctionWatchdogSniff.php b/coder_sniffer/Drupal/Sniffs/Semantics/FunctionWatchdogSniff.php index 7117bdbc..05b952c0 100644 --- a/coder_sniffer/Drupal/Sniffs/Semantics/FunctionWatchdogSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Semantics/FunctionWatchdogSniff.php @@ -1,12 +1,17 @@ <?php /** - * Drupal_Sniffs_Semanitcs_FunctionWatchdogSniff. + * \Drupal\Sniffs\Semantics\FunctionWatchdogSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Semantics; + +use Drupal\Sniffs\Semantics\FunctionCall; +use PHP_CodeSniffer\Files\File; + /** * Checks that the second argument to watchdog() is not enclosed with t(). * @@ -14,7 +19,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Semantics_FunctionWatchdogSniff extends Drupal_Sniffs_Semantics_FunctionCall +class FunctionWatchdogSniff extends FunctionCall { @@ -33,18 +38,18 @@ class Drupal_Sniffs_Semantics_FunctionWatchdogSniff extends Drupal_Sniffs_Semant /** * Processes this function call. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the function call in - * the stack. - * @param int $openBracket The position of the opening - * parenthesis in the stack. - * @param int $closeBracket The position of the closing - * parenthesis in the stack. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the function call in + * the stack. + * @param int $openBracket The position of the opening + * parenthesis in the stack. + * @param int $closeBracket The position of the closing + * parenthesis in the stack. * * @return void */ public function processFunctionCall( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $openBracket, $closeBracket diff --git a/coder_sniffer/Drupal/Sniffs/Semantics/InstallHooksSniff.php b/coder_sniffer/Drupal/Sniffs/Semantics/InstallHooksSniff.php index 96b5315f..41aaf3e8 100644 --- a/coder_sniffer/Drupal/Sniffs/Semantics/InstallHooksSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Semantics/InstallHooksSniff.php @@ -1,12 +1,17 @@ <?php /** - * Drupal_Sniffs_Semantics_InstallHooksSniff + * \Drupal\Sniffs\Semantics\InstallHooksSniff * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Semantics; + +use Drupal\Sniffs\Semantics\FunctionDefinition; +use PHP_CodeSniffer\Files\File; + /** * Checks that hook_disable(), hook_enable(), hook_install(), hook_uninstall(), * hook_requirements() and hook_schema() are not defined in the module file. @@ -15,22 +20,22 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Semantics_InstallHooksSniff extends Drupal_Sniffs_Semantics_FunctionDefinition +class InstallHooksSniff extends FunctionDefinition { /** * Process this function definition. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the function name in the stack. - * name in the stack. - * @param int $functionPtr The position of the function keyword in the stack. - * keyword in the stack. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the function name in the stack. + * name in the stack. + * @param int $functionPtr The position of the function keyword in the stack. + * keyword in the stack. * * @return void */ - public function processFunction(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $functionPtr) + public function processFunction(File $phpcsFile, $stackPtr, $functionPtr) { $fileExtension = strtolower(substr($phpcsFile->getFilename(), -6)); // Only check in *.module files. diff --git a/coder_sniffer/Drupal/Sniffs/Semantics/LStringTranslatableSniff.php b/coder_sniffer/Drupal/Sniffs/Semantics/LStringTranslatableSniff.php index 6b48994c..a8edcef9 100644 --- a/coder_sniffer/Drupal/Sniffs/Semantics/LStringTranslatableSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Semantics/LStringTranslatableSniff.php @@ -1,12 +1,17 @@ <?php /** - * Drupal_Sniffs_Semanitcs_LStringTranslatableSniff. + * \Drupal\Sniffs\Semantics\LStringTranslatableSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Semantics; + +use Drupal\Sniffs\Semantics\FunctionCall; +use PHP_CodeSniffer\Files\File; + /** * Checks that string literals passed to l() are translatable. * @@ -14,7 +19,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Semantics_LStringTranslatableSniff extends Drupal_Sniffs_Semantics_FunctionCall +class LStringTranslatableSniff extends FunctionCall { @@ -33,18 +38,18 @@ class Drupal_Sniffs_Semantics_LStringTranslatableSniff extends Drupal_Sniffs_Sem /** * Processes this function call. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the function call in - * the stack. - * @param int $openBracket The position of the opening - * parenthesis in the stack. - * @param int $closeBracket The position of the closing - * parenthesis in the stack. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the function call in + * the stack. + * @param int $openBracket The position of the opening + * parenthesis in the stack. + * @param int $closeBracket The position of the closing + * parenthesis in the stack. * * @return void */ public function processFunctionCall( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $openBracket, $closeBracket diff --git a/coder_sniffer/Drupal/Sniffs/Semantics/PregSecuritySniff.php b/coder_sniffer/Drupal/Sniffs/Semantics/PregSecuritySniff.php index f976d764..67ba73c5 100644 --- a/coder_sniffer/Drupal/Sniffs/Semantics/PregSecuritySniff.php +++ b/coder_sniffer/Drupal/Sniffs/Semantics/PregSecuritySniff.php @@ -1,12 +1,17 @@ <?php /** - * Drupal_Sniffs_Semantics_PregSecuritySniff. + * \Drupal\Sniffs\Semantics\PregSecuritySniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Semantics; + +use Drupal\Sniffs\Semantics\FunctionCall; +use PHP_CodeSniffer\Files\File; + /** * Check the usage of the preg functions to ensure the insecure /e flag isn't * used: https://www.drupal.org/node/750148 @@ -15,7 +20,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Semantics_PregSecuritySniff extends Drupal_Sniffs_Semantics_FunctionCall +class PregSecuritySniff extends FunctionCall { @@ -42,18 +47,18 @@ class Drupal_Sniffs_Semantics_PregSecuritySniff extends Drupal_Sniffs_Semantics_ /** * Processes this function call. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the function call in - * the stack. - * @param int $openBracket The position of the opening - * parenthesis in the stack. - * @param int $closeBracket The position of the closing - * parenthesis in the stack. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the function call in + * the stack. + * @param int $openBracket The position of the opening + * parenthesis in the stack. + * @param int $closeBracket The position of the closing + * parenthesis in the stack. * * @return void */ public function processFunctionCall( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $openBracket, $closeBracket diff --git a/coder_sniffer/Drupal/Sniffs/Semantics/RemoteAddressSniff.php b/coder_sniffer/Drupal/Sniffs/Semantics/RemoteAddressSniff.php index b68aac6f..14020e29 100644 --- a/coder_sniffer/Drupal/Sniffs/Semantics/RemoteAddressSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Semantics/RemoteAddressSniff.php @@ -1,12 +1,17 @@ <?php /** - * Drupal_Sniffs_Semantics_RemoteAddressSniff. + * \Drupal\Sniffs\Semantics\RemoteAddressSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Semantics; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** * Make sure that the function ip_address() is used instead of * $_SERVER['REMOTE_ADDR']. @@ -15,7 +20,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Semantics_RemoteAddressSniff implements PHP_CodeSniffer_Sniff +class RemoteAddressSniff implements Sniff { @@ -34,13 +39,13 @@ class Drupal_Sniffs_Semantics_RemoteAddressSniff implements PHP_CodeSniffer_Snif /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The current file being processed. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \HP_CodeSniffer\Files\File $phpcsFile The current file being processed. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $string = $phpcsFile->getTokensAsString($stackPtr, 4); if ($string === '$_SERVER["REMOTE_ADDR"]' || $string === '$_SERVER[\'REMOTE_ADDR\']') { diff --git a/coder_sniffer/Drupal/Sniffs/Semantics/TInHookMenuSniff.php b/coder_sniffer/Drupal/Sniffs/Semantics/TInHookMenuSniff.php index bb25f377..08cfc804 100644 --- a/coder_sniffer/Drupal/Sniffs/Semantics/TInHookMenuSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Semantics/TInHookMenuSniff.php @@ -1,12 +1,18 @@ <?php /** - * Drupal_Sniffs_Semanitcs_TInHookMenuSniff. + * \Drupal\Sniffs\Semantics\TInHookMenuSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Semantics; + +use Drupal\Sniffs\Semantics\FunctionDefinition; +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Util\Tokens; + /** * Checks that t() is not used in hook_menu(). * @@ -14,22 +20,22 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Semantics_TInHookMenuSniff extends Drupal_Sniffs_Semantics_FunctionDefinition +class TInHookMenuSniff extends FunctionDefinition { /** * Process this function definition. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the function name in the stack. - * name in the stack. - * @param int $functionPtr The position of the function keyword in the stack. - * keyword in the stack. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the function name in the stack. + * name in the stack. + * @param int $functionPtr The position of the function keyword in the stack. + * keyword in the stack. * * @return void */ - public function processFunction(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $functionPtr) + public function processFunction(File $phpcsFile, $stackPtr, $functionPtr) { $fileExtension = strtolower(substr($phpcsFile->getFilename(), -6)); // Only check in *.module files. @@ -52,7 +58,7 @@ class Drupal_Sniffs_Semantics_TInHookMenuSniff extends Drupal_Sniffs_Semantics_F while ($string !== false) { if ($tokens[$string]['content'] === 't') { $opener = $phpcsFile->findNext( - PHP_CodeSniffer_Tokens::$emptyTokens, + Tokens::$emptyTokens, ($string + 1), null, true diff --git a/coder_sniffer/Drupal/Sniffs/Semantics/TInHookSchemaSniff.php b/coder_sniffer/Drupal/Sniffs/Semantics/TInHookSchemaSniff.php index e10ce0aa..490df8ec 100644 --- a/coder_sniffer/Drupal/Sniffs/Semantics/TInHookSchemaSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Semantics/TInHookSchemaSniff.php @@ -1,12 +1,18 @@ <?php /** - * Drupal_Sniffs_Semanitcs_TInHookSchemaSniff. + * \Drupal\Sniffs\Semantics\TInHookSchemaSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Semantics; + +use Drupal\Sniffs\Semantics\FunctionDefinition; +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Util\Tokens; + /** * Checks that t() is not used in hook_schema(). * @@ -14,22 +20,22 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Semantics_TInHookSchemaSniff extends Drupal_Sniffs_Semantics_FunctionDefinition +class TInHookSchemaSniff extends FunctionDefinition { /** * Process this function definition. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the function name in the stack. - * name in the stack. - * @param int $functionPtr The position of the function keyword in the stack. - * keyword in the stack. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the function name in the stack. + * name in the stack. + * @param int $functionPtr The position of the function keyword in the stack. + * keyword in the stack. * * @return void */ - public function processFunction(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $functionPtr) + public function processFunction(File $phpcsFile, $stackPtr, $functionPtr) { $fileExtension = strtolower(substr($phpcsFile->getFilename(), -7)); // Only check in *.install files. @@ -52,7 +58,7 @@ class Drupal_Sniffs_Semantics_TInHookSchemaSniff extends Drupal_Sniffs_Semantics while ($string !== false) { if ($tokens[$string]['content'] === 't') { $opener = $phpcsFile->findNext( - PHP_CodeSniffer_Tokens::$emptyTokens, + Tokens::$emptyTokens, ($string + 1), null, true diff --git a/coder_sniffer/Drupal/Sniffs/Strings/UnnecessaryStringConcatSniff.php b/coder_sniffer/Drupal/Sniffs/Strings/UnnecessaryStringConcatSniff.php index 69d12a81..d96dfa46 100644 --- a/coder_sniffer/Drupal/Sniffs/Strings/UnnecessaryStringConcatSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Strings/UnnecessaryStringConcatSniff.php @@ -1,44 +1,46 @@ <?php /** - * Generic_Sniffs_Strings_UnnecessaryStringConcatSniff. + * \Drupal\Sniffs\Strings\UnnecessaryStringConcatSniff. * * @category PHP * @package PHP_CodeSniffer * @author Greg Sherwood <gsherwood@squiz.net> - * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600) - * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence - * @version CVS: $Id: UnnecessaryStringConcatSniff.php 304603 2010-10-22 03:07:04Z squiz $ + * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600) + * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\Strings; + +use Drupal\Sniffs\Files\LineLengthSniff; +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Standards\Generic\Sniffs\Strings\UnnecessaryStringConcatSniff as GenericUnnecessaryStringConcatSniff; +use PHP_CodeSniffer\Util\Tokens; + /** - * Generic_Sniffs_Strings_UnnecessaryStringConcatSniff. - * - * Checks that two strings are not concatenated together; suggests - * using one string instead. + * Checks that two strings are not concatenated together; suggests using one string instead. * * @category PHP * @package PHP_CodeSniffer * @author Greg Sherwood <gsherwood@squiz.net> - * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600) - * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence - * @version Release: 1.3.1 + * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600) + * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_Strings_UnnecessaryStringConcatSniff extends Generic_Sniffs_Strings_UnnecessaryStringConcatSniff +class UnnecessaryStringConcatSniff extends GenericUnnecessaryStringConcatSniff { /** * Processes this sniff, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { // Work out which type of file this is for. $tokens = $phpcsFile->getTokens(); @@ -58,7 +60,7 @@ class Drupal_Sniffs_Strings_UnnecessaryStringConcatSniff extends Generic_Sniffs_ return; } - $stringTokens = PHP_CodeSniffer_Tokens::$stringTokens; + $stringTokens = Tokens::$stringTokens; if (in_array($tokens[$prev]['code'], $stringTokens) === true && in_array($tokens[$next]['code'], $stringTokens) === true ) { @@ -77,7 +79,7 @@ class Drupal_Sniffs_Strings_UnnecessaryStringConcatSniff extends Generic_Sniffs_ // Before we throw an error check if the string is longer than // the line length limit. - $lineLengthLimitSniff = new Drupal_Sniffs_Files_LineLengthSniff; + $lineLengthLimitSniff = new LineLengthSniff; $lineLenght = $lineLengthLimitSniff->getLineLength($phpcsFile, $tokens[$prev]['line']); $stringLength = ($lineLenght + strlen($tokens[$next]['content']) - 4); diff --git a/coder_sniffer/Drupal/Sniffs/WhiteSpace/CloseBracketSpacingSniff.php b/coder_sniffer/Drupal/Sniffs/WhiteSpace/CloseBracketSpacingSniff.php index 84753b3d..720ba3c6 100644 --- a/coder_sniffer/Drupal/Sniffs/WhiteSpace/CloseBracketSpacingSniff.php +++ b/coder_sniffer/Drupal/Sniffs/WhiteSpace/CloseBracketSpacingSniff.php @@ -1,21 +1,28 @@ <?php /** - * Drupal_Sniffs_WhiteSpace_CloseBracketSpacingSniff. + * \Drupal\Sniffs\WhiteSpace\CloseBracketSpacingSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\WhiteSpace; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Util\Tokens; + /** * Checks that there is no white space before a closing bracket, for ")" and "}". - * Square Brackets are handled by Squiz_Sniffs_Arrays_ArrayBracketSpacingSniff. + * Square Brackets are handled by + * \PHP_CodeSniffer\Standards\Squiz\Sniffs\Arrays\ArrayBracketSpacingSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_WhiteSpace_CloseBracketSpacingSniff implements PHP_CodeSniffer_Sniff +class CloseBracketSpacingSniff implements Sniff { /** @@ -48,13 +55,13 @@ class Drupal_Sniffs_WhiteSpace_CloseBracketSpacingSniff implements PHP_CodeSniff /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -68,7 +75,7 @@ class Drupal_Sniffs_WhiteSpace_CloseBracketSpacingSniff implements PHP_CodeSniff if (isset($tokens[($stackPtr - 1)]) === true && $tokens[($stackPtr - 1)]['code'] === T_WHITESPACE ) { - $before = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true); + $before = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); if ($before !== false && $tokens[$stackPtr]['line'] === $tokens[$before]['line']) { $error = 'There should be no white space before a closing "%s"'; $fix = $phpcsFile->addFixableError( diff --git a/coder_sniffer/Drupal/Sniffs/WhiteSpace/CommaSniff.php b/coder_sniffer/Drupal/Sniffs/WhiteSpace/CommaSniff.php index 87c069f3..69f1fba7 100644 --- a/coder_sniffer/Drupal/Sniffs/WhiteSpace/CommaSniff.php +++ b/coder_sniffer/Drupal/Sniffs/WhiteSpace/CommaSniff.php @@ -1,14 +1,19 @@ <?php /** - * Drupal_Sniffs_WhiteSpace_CommaSniff. + * \Drupal\Sniffs\WhiteSpace\CommaSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\WhiteSpace; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** - * Drupal_Sniffs_WhiteSpace_CommaSniff. + * \Drupal\Sniffs\WhiteSpace\CommaSniff. * * Checks that there is one space after a comma. * @@ -16,7 +21,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_WhiteSpace_CommaSniff implements PHP_CodeSniffer_Sniff +class CommaSniff implements Sniff { @@ -35,13 +40,13 @@ class Drupal_Sniffs_WhiteSpace_CommaSniff implements PHP_CodeSniffer_Sniff /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); diff --git a/coder_sniffer/Drupal/Sniffs/WhiteSpace/EmptyLinesSniff.php b/coder_sniffer/Drupal/Sniffs/WhiteSpace/EmptyLinesSniff.php index ae8fabf6..0d09618d 100644 --- a/coder_sniffer/Drupal/Sniffs/WhiteSpace/EmptyLinesSniff.php +++ b/coder_sniffer/Drupal/Sniffs/WhiteSpace/EmptyLinesSniff.php @@ -1,14 +1,19 @@ <?php /** - * Drupal_Sniffs_WhiteSpace_EmptyLinesSniff. + * \Drupal\Sniffs\WhiteSpace\EmptyLinesSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\WhiteSpace; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** - * Drupal_Sniffs_WhiteSpace_EmptyLinesSniff. + * \Drupal\Sniffs\WhiteSpace\EmptyLinesSniff. * * Checks that there are not more than 2 empty lines following each other. * @@ -16,7 +21,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_WhiteSpace_EmptyLinesSniff implements PHP_CodeSniffer_Sniff +class EmptyLinesSniff implements Sniff { /** @@ -46,13 +51,13 @@ class Drupal_Sniffs_WhiteSpace_EmptyLinesSniff implements PHP_CodeSniffer_Sniff /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); if ($tokens[$stackPtr]['content'] === $phpcsFile->eolChar diff --git a/coder_sniffer/Drupal/Sniffs/WhiteSpace/NamespaceSniff.php b/coder_sniffer/Drupal/Sniffs/WhiteSpace/NamespaceSniff.php index 3da0e5ab..ddee5245 100644 --- a/coder_sniffer/Drupal/Sniffs/WhiteSpace/NamespaceSniff.php +++ b/coder_sniffer/Drupal/Sniffs/WhiteSpace/NamespaceSniff.php @@ -1,12 +1,17 @@ <?php /** - * Drupal_Sniffs_WhiteSpace_NamespaceSniff. + * \Drupal\Sniffs\WhiteSpace\NamespaceSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\WhiteSpace; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** * Checks that there is exactly one space after the namespace keyword. * @@ -14,7 +19,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_WhiteSpace_NamespaceSniff implements PHP_CodeSniffer_Sniff +class NamespaceSniff implements Sniff { @@ -33,13 +38,13 @@ class Drupal_Sniffs_WhiteSpace_NamespaceSniff implements PHP_CodeSniffer_Sniff /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); diff --git a/coder_sniffer/Drupal/Sniffs/WhiteSpace/ObjectOperatorIndentSniff.php b/coder_sniffer/Drupal/Sniffs/WhiteSpace/ObjectOperatorIndentSniff.php index 50f20b9e..ab72a1c0 100644 --- a/coder_sniffer/Drupal/Sniffs/WhiteSpace/ObjectOperatorIndentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/WhiteSpace/ObjectOperatorIndentSniff.php @@ -1,6 +1,6 @@ <?php /** - * Drupal_Sniffs_WhiteSpace_ObjectOperatorIndentSniff. + * \Drupal\Sniffs\WhiteSpace\ObjectOperatorIndentSniff. * * @category PHP * @package PHP_CodeSniffer @@ -10,8 +10,14 @@ * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\WhiteSpace; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Util\Tokens; + /** - * Drupal_Sniffs_WhiteSpace_ObjectOperatorIndentSniff. + * \Drupal\Sniffs\WhiteSpace\ObjectOperatorIndentSniff. * * Checks that object operators are indented 2 spaces if they are the first * thing on a line. @@ -24,7 +30,7 @@ * @version Release: 1.2.0RC3 * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_WhiteSpace_ObjectOperatorIndentSniff implements PHP_CodeSniffer_Sniff +class ObjectOperatorIndentSniff implements Sniff { @@ -43,13 +49,13 @@ class Drupal_Sniffs_WhiteSpace_ObjectOperatorIndentSniff implements PHP_CodeSnif /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile All the tokens found in the document. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -59,7 +65,7 @@ class Drupal_Sniffs_WhiteSpace_ObjectOperatorIndentSniff implements PHP_CodeSnif return; } - $previousLine = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 2), null, true, null, true); + $previousLine = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 2), null, true, null, true); if ($previousLine === false) { return; @@ -127,13 +133,13 @@ class Drupal_Sniffs_WhiteSpace_ObjectOperatorIndentSniff implements PHP_CodeSnif /** * Returns the first non whitespace token on the line. * - * @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile All the tokens found in the document. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return int */ - protected function findStartOfline(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + protected function findStartOfline(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); diff --git a/coder_sniffer/Drupal/Sniffs/WhiteSpace/ObjectOperatorSpacingSniff.php b/coder_sniffer/Drupal/Sniffs/WhiteSpace/ObjectOperatorSpacingSniff.php index 3d42e2f6..ba787fd8 100644 --- a/coder_sniffer/Drupal/Sniffs/WhiteSpace/ObjectOperatorSpacingSniff.php +++ b/coder_sniffer/Drupal/Sniffs/WhiteSpace/ObjectOperatorSpacingSniff.php @@ -1,23 +1,30 @@ <?php /** - * Drupal_Sniffs_WhiteSpace_ObjectOperatorSpacingSniff. + * \Drupal\Sniffs\WhiteSpace\ObjectOperatorSpacingSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\WhiteSpace; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Util\Tokens; + /** * Ensure that there are no white spaces before and after the object operator. * - * Largely copied from Squiz_Sniffs_WhiteSpace_ObjectOperatorSpacingSniff but - * modified to not throw errors on multi line statements. + * Largely copied from + * \PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\ObjectOperatorSpacingSniff + * but modified to not throw errors on multi line statements. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_WhiteSpace_ObjectOperatorSpacingSniff implements PHP_CodeSniffer_Sniff +class ObjectOperatorSpacingSniff implements Sniff { @@ -36,13 +43,13 @@ class Drupal_Sniffs_WhiteSpace_ObjectOperatorSpacingSniff implements PHP_CodeSni /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); if ($tokens[($stackPtr - 1)]['code'] !== T_WHITESPACE) { @@ -68,7 +75,7 @@ class Drupal_Sniffs_WhiteSpace_ObjectOperatorSpacingSniff implements PHP_CodeSni $phpcsFile->recordMetric($stackPtr, 'Spacing before object operator', $before); $phpcsFile->recordMetric($stackPtr, 'Spacing after object operator', $after); - $prevToken = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true); + $prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); // Line breaks are allowed before an object operator. if ($before !== 0 && $tokens[$stackPtr]['line'] === $tokens[$prevToken]['line']) { $error = 'Space found before object operator'; diff --git a/coder_sniffer/Drupal/Sniffs/WhiteSpace/OpenBracketSpacingSniff.php b/coder_sniffer/Drupal/Sniffs/WhiteSpace/OpenBracketSpacingSniff.php index 07c5b6e3..6c35ecf7 100644 --- a/coder_sniffer/Drupal/Sniffs/WhiteSpace/OpenBracketSpacingSniff.php +++ b/coder_sniffer/Drupal/Sniffs/WhiteSpace/OpenBracketSpacingSniff.php @@ -1,21 +1,27 @@ <?php /** - * Drupal_Sniffs_WhiteSpace_OpenBracketSpacingSniff. + * \Drupal\Sniffs\WhiteSpace\OpenBracketSpacingSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\WhiteSpace; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** * Checks that there is no white space after an opening bracket, for "(" and "{". - * Square Brackets are handled by Squiz_Sniffs_Arrays_ArrayBracketSpacingSniff. + * Square Brackets are handled by + * \PHP_CodeSniffer\Standards\Squiz\Sniffs\Arrays\ArrayBracketSpacingSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_WhiteSpace_OpenBracketSpacingSniff implements PHP_CodeSniffer_Sniff +class OpenBracketSpacingSniff implements Sniff { /** @@ -48,13 +54,13 @@ class Drupal_Sniffs_WhiteSpace_OpenBracketSpacingSniff implements PHP_CodeSniffe /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); diff --git a/coder_sniffer/Drupal/Sniffs/WhiteSpace/OpenTagNewlineSniff.php b/coder_sniffer/Drupal/Sniffs/WhiteSpace/OpenTagNewlineSniff.php index 6dfd7ec5..c4f4e7c5 100644 --- a/coder_sniffer/Drupal/Sniffs/WhiteSpace/OpenTagNewlineSniff.php +++ b/coder_sniffer/Drupal/Sniffs/WhiteSpace/OpenTagNewlineSniff.php @@ -1,13 +1,17 @@ <?php - /** - * Drupal_Sniffs_WhiteSpace_OpenTagNewlineSniff. + * \Drupal\Sniffs\WhiteSpace\OpenTagNewlineSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\WhiteSpace; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** * Checks that there is exactly one newline after the PHP open tag. * @@ -15,7 +19,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_WhiteSpace_OpenTagNewlineSniff implements PHP_CodeSniffer_Sniff +class OpenTagNewlineSniff implements Sniff { @@ -34,15 +38,15 @@ class Drupal_Sniffs_WhiteSpace_OpenTagNewlineSniff implements PHP_CodeSniffer_Sn /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where the - * token was found. - * @param int $stackPtr The position in the PHP_CodeSniffer - * file's token stack where the token - * was found. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where the + * token was found. + * @param int $stackPtr The position in the PHP_CodeSniffer + * file's token stack where the token + * was found. * * @return int End of the stack to skip the rest of the file. */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); diff --git a/coder_sniffer/Drupal/Sniffs/WhiteSpace/OperatorSpacingSniff.php b/coder_sniffer/Drupal/Sniffs/WhiteSpace/OperatorSpacingSniff.php index e705541d..92b85181 100644 --- a/coder_sniffer/Drupal/Sniffs/WhiteSpace/OperatorSpacingSniff.php +++ b/coder_sniffer/Drupal/Sniffs/WhiteSpace/OperatorSpacingSniff.php @@ -1,12 +1,18 @@ <?php /** - * Drupal_Sniffs_WhiteSpace_OperatorSpacingSniff. + * \Drupal\Sniffs\WhiteSpace\OperatorSpacingSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\WhiteSpace; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Util\Tokens; + /** * Overrides Squiz_Sniffs_WhiteSpace_OperatorSpacingSniff to allow the plus operator * on numbers like "$i = +1;". @@ -15,7 +21,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_WhiteSpace_OperatorSpacingSniff implements PHP_CodeSniffer_Sniff +class OperatorSpacingSniff implements Sniff { /** @@ -43,9 +49,9 @@ class Drupal_Sniffs_WhiteSpace_OperatorSpacingSniff implements PHP_CodeSniffer_S */ public function register() { - $comparison = PHP_CodeSniffer_Tokens::$comparisonTokens; - $operators = PHP_CodeSniffer_Tokens::$operators; - $assignment = PHP_CodeSniffer_Tokens::$assignmentTokens; + $comparison = Tokens::$comparisonTokens; + $operators = Tokens::$operators; + $assignment = Tokens::$assignmentTokens; $inlineIf = array( T_INLINE_THEN, T_INLINE_ELSE, @@ -61,13 +67,13 @@ class Drupal_Sniffs_WhiteSpace_OperatorSpacingSniff implements PHP_CodeSniffer_S /** * Processes this sniff, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The current file being checked. - * @param int $stackPtr The position of the current token in - * the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The current file being checked. + * @param int $stackPtr The position of the current token in + * the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -184,22 +190,22 @@ class Drupal_Sniffs_WhiteSpace_OperatorSpacingSniff implements PHP_CodeSniffer_S return; } - if (isset(PHP_CodeSniffer_Tokens::$operators[$tokens[$prev]['code']]) === true) { + if (isset(Tokens::$operators[$tokens[$prev]['code']]) === true) { // Just trying to operate on a negative value; eg. ($var * -1). return; } - if (isset(PHP_CodeSniffer_Tokens::$comparisonTokens[$tokens[$prev]['code']]) === true) { + if (isset(Tokens::$comparisonTokens[$tokens[$prev]['code']]) === true) { // Just trying to compare a negative value; eg. ($var === -1). return; } - if (isset(PHP_CodeSniffer_Tokens::$booleanOperators[$tokens[$prev]['code']]) === true) { + if (isset(Tokens::$booleanOperators[$tokens[$prev]['code']]) === true) { // Just trying to compare a negative value; eg. ($var || -1 === $b). return; } - if (isset(PHP_CodeSniffer_Tokens::$assignmentTokens[$tokens[$prev]['code']]) === true) { + if (isset(Tokens::$assignmentTokens[$tokens[$prev]['code']]) === true) { // Just trying to assign a negative value; eg. ($var = -1). return; } @@ -234,7 +240,7 @@ class Drupal_Sniffs_WhiteSpace_OperatorSpacingSniff implements PHP_CodeSniffer_S } $phpcsFile->recordMetric($stackPtr, 'Space before operator', 0); - } else if (isset(PHP_CodeSniffer_Tokens::$assignmentTokens[$tokens[$stackPtr]['code']]) === false) { + } else if (isset(Tokens::$assignmentTokens[$tokens[$stackPtr]['code']]) === false) { // Don't throw an error for assignments, because other standards allow // multiple spaces there to align multiple assignments. if ($tokens[($stackPtr - 2)]['line'] !== $tokens[$stackPtr]['line']) { diff --git a/coder_sniffer/Drupal/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php b/coder_sniffer/Drupal/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php index ab5d0142..a06da0e8 100644 --- a/coder_sniffer/Drupal/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php +++ b/coder_sniffer/Drupal/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php @@ -1,14 +1,20 @@ <?php /** - * Drupal_Sniffs_Whitespace_ScopeClosingBraceSniff. + * \Drupal\Sniffs\WhiteSpace\ScopeClosingBraceSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://Drupal.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\WhiteSpace; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Util\Tokens; + /** - * Copied from PEAR_Sniffs_WhiteSpace_ScopeClosingBraceSniff to allow empty methods + * Copied from \PHP_CodeSniffer\Standards\PEAR\Sniffs\WhiteSpace\ScopeClosingBraceSniff to allow empty methods * and classes. * * Checks that the closing braces of scopes are aligned correctly. @@ -17,7 +23,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_WhiteSpace_ScopeClosingBraceSniff implements PHP_CodeSniffer_Sniff +class ScopeClosingBraceSniff implements Sniff { /** @@ -35,7 +41,7 @@ class Drupal_Sniffs_WhiteSpace_ScopeClosingBraceSniff implements PHP_CodeSniffer */ public function register() { - return PHP_CodeSniffer_Tokens::$scopeOpeners; + return Tokens::$scopeOpeners; }//end register() @@ -43,13 +49,13 @@ class Drupal_Sniffs_WhiteSpace_ScopeClosingBraceSniff implements PHP_CodeSniffer /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile All the tokens found in the document. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); diff --git a/coder_sniffer/Drupal/Sniffs/WhiteSpace/ScopeIndentSniff.php b/coder_sniffer/Drupal/Sniffs/WhiteSpace/ScopeIndentSniff.php index 2fff41dc..7c414eb9 100644 --- a/coder_sniffer/Drupal/Sniffs/WhiteSpace/ScopeIndentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/WhiteSpace/ScopeIndentSniff.php @@ -1,15 +1,24 @@ <?php /** - * Drupal_Sniffs_Whitespace_ScopeIndentSniff. + * \Drupal\Sniffs\WhiteSpace\ScopeIndentSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace Drupal\Sniffs\WhiteSpace; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Config; +use PHP_CodeSniffer\Util\Tokens; + /** - * Largely copied from Generic_Sniffs_Whitespace_ScopeIndentSniff, modified to make - * the exact mode working with comments and multi line statements. + * Largely copied from + * \PHP_CodeSniffer\Standards\Generic\Sniffs\WhiteSpace\ScopeIndentSniff, + * modified to make the exact mode working with comments and multi line + * statements. * * Checks that control structures are structured correctly, and their content * is indented correctly. This sniff will throw errors if tabs are used @@ -19,7 +28,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class Drupal_Sniffs_WhiteSpace_ScopeIndentSniff implements PHP_CodeSniffer_Sniff +class ScopeIndentSniff implements Sniff { /** @@ -120,28 +129,28 @@ class Drupal_Sniffs_WhiteSpace_ScopeIndentSniff implements PHP_CodeSniffer_Sniff /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile All the tokens found in the document. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { - $debug = PHP_CodeSniffer::getConfigData('scope_indent_debug'); + $debug = Config::getConfigData('scope_indent_debug'); if ($debug !== null) { $this->_debug = (bool) $debug; } if ($this->_tabWidth === null) { - $cliValues = $phpcsFile->phpcs->cli->getCommandLineValues(); - if (isset($cliValues['tabWidth']) === false || $cliValues['tabWidth'] === 0) { + $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; } else { - $this->_tabWidth = $cliValues['tabWidth']; + $this->_tabWidth = $config->tabWidth; } } @@ -718,7 +727,7 @@ class Drupal_Sniffs_WhiteSpace_ScopeIndentSniff implements PHP_CodeSniffer_Sniff }//end if if ($checkToken !== null - && isset(PHP_CodeSniffer_Tokens::$scopeOpeners[$tokens[$checkToken]['code']]) === true + && isset(Tokens::$scopeOpeners[$tokens[$checkToken]['code']]) === true && in_array($tokens[$checkToken]['code'], $this->nonIndentingScopes) === false && isset($tokens[$checkToken]['scope_opener']) === true ) { @@ -768,7 +777,7 @@ class Drupal_Sniffs_WhiteSpace_ScopeIndentSniff implements PHP_CodeSniffer_Sniff // Method prefix indentation has to be exact or else if will break // the rest of the function declaration, and potentially future ones. if ($checkToken !== null - && isset(PHP_CodeSniffer_Tokens::$methodPrefixes[$tokens[$checkToken]['code']]) === true + && isset(Tokens::$methodPrefixes[$tokens[$checkToken]['code']]) === true && $tokens[($checkToken + 1)]['code'] !== T_DOUBLE_COLON ) { $exact = true; @@ -820,7 +829,7 @@ class Drupal_Sniffs_WhiteSpace_ScopeIndentSniff implements PHP_CodeSniffer_Sniff ) { if ($tokenIndent > $checkIndent) { // Ignore multi line statements. - $before = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($checkToken - 1), null, true); + $before = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($checkToken - 1), null, true); if ($before !== false && in_array( $tokens[$before]['code'], array( @@ -1065,7 +1074,7 @@ class Drupal_Sniffs_WhiteSpace_ScopeIndentSniff implements PHP_CodeSniffer_Sniff } $condition = $tokens[$tokens[$i]['scope_condition']]['code']; - if (isset(PHP_CodeSniffer_Tokens::$scopeOpeners[$condition]) === true + if (isset(Tokens::$scopeOpeners[$condition]) === true && in_array($condition, $this->nonIndentingScopes) === false ) { if ($this->_debug === true) { @@ -1186,7 +1195,7 @@ class Drupal_Sniffs_WhiteSpace_ScopeIndentSniff implements PHP_CodeSniffer_Sniff echo "\t* using parenthesis *".PHP_EOL; } - $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($parens - 1), null, true); + $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($parens - 1), null, true); $object = 0; $condition = 0; } else if ($object > 0 && $object >= $condition) { diff --git a/coder_sniffer/Drupal/Test/Array/ArrayUnitTest.inc b/coder_sniffer/Drupal/Test/Arrays/ArrayUnitTest.inc similarity index 100% rename from coder_sniffer/Drupal/Test/Array/ArrayUnitTest.inc rename to coder_sniffer/Drupal/Test/Arrays/ArrayUnitTest.inc diff --git a/coder_sniffer/Drupal/Test/Array/ArrayUnitTest.inc.fixed b/coder_sniffer/Drupal/Test/Arrays/ArrayUnitTest.inc.fixed similarity index 100% rename from coder_sniffer/Drupal/Test/Array/ArrayUnitTest.inc.fixed rename to coder_sniffer/Drupal/Test/Arrays/ArrayUnitTest.inc.fixed diff --git a/coder_sniffer/Drupal/Test/Array/ArrayUnitTest.php b/coder_sniffer/Drupal/Test/Arrays/ArrayUnitTest.php similarity index 81% rename from coder_sniffer/Drupal/Test/Array/ArrayUnitTest.php rename to coder_sniffer/Drupal/Test/Arrays/ArrayUnitTest.php index 15ef9082..5d979514 100644 --- a/coder_sniffer/Drupal/Test/Array/ArrayUnitTest.php +++ b/coder_sniffer/Drupal/Test/Arrays/ArrayUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_Array_ArrayUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\Arrays; + +use Drupal\Test\CoderSniffUnitTest; + +class ArrayUnitTest extends CoderSniffUnitTest { /** @@ -11,7 +15,7 @@ class Drupal_Sniffs_Array_ArrayUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array( 13 => 1, @@ -32,7 +36,7 @@ class Drupal_Sniffs_Array_ArrayUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array( 17 => 1, diff --git a/coder_sniffer/Drupal/Test/Array/DisallowLongArraySyntaxUnitTest.php b/coder_sniffer/Drupal/Test/Arrays/DisallowLongArraySyntaxUnitTest.php similarity index 80% rename from coder_sniffer/Drupal/Test/Array/DisallowLongArraySyntaxUnitTest.php rename to coder_sniffer/Drupal/Test/Arrays/DisallowLongArraySyntaxUnitTest.php index fe97217f..2d1b356e 100644 --- a/coder_sniffer/Drupal/Test/Array/DisallowLongArraySyntaxUnitTest.php +++ b/coder_sniffer/Drupal/Test/Arrays/DisallowLongArraySyntaxUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_Array_DisallowLongArraySyntaxUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\Arrays; + +use Drupal\Test\CoderSniffUnitTest; + +class DisallowLongArraySyntaxUnitTest extends CoderSniffUnitTest { /** @@ -11,7 +15,7 @@ class Drupal_Sniffs_Array_DisallowLongArraySyntaxUnitTest extends CoderSniffUnit * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { switch ($testFile) { case 'DisallowLongArraySyntaxUnitTest.2.inc': @@ -32,7 +36,7 @@ class Drupal_Sniffs_Array_DisallowLongArraySyntaxUnitTest extends CoderSniffUnit * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); @@ -44,7 +48,7 @@ class Drupal_Sniffs_Array_DisallowLongArraySyntaxUnitTest extends CoderSniffUnit * * @return array The list of test files. */ - protected function getTestFiles() { + protected function getTestFiles($testFileBase) { return array( __DIR__ . '/disallow_long_array_d7/DisallowLongArraySyntaxUnitTest.1.inc', __DIR__ . '/disallow_long_array_d8/DisallowLongArraySyntaxUnitTest.2.inc', diff --git a/coder_sniffer/Drupal/Test/Array/disallow_long_array_d7/DisallowLongArraySyntaxUnitTest.1.inc b/coder_sniffer/Drupal/Test/Arrays/disallow_long_array_d7/DisallowLongArraySyntaxUnitTest.1.inc similarity index 100% rename from coder_sniffer/Drupal/Test/Array/disallow_long_array_d7/DisallowLongArraySyntaxUnitTest.1.inc rename to coder_sniffer/Drupal/Test/Arrays/disallow_long_array_d7/DisallowLongArraySyntaxUnitTest.1.inc diff --git a/coder_sniffer/Drupal/Test/Array/disallow_long_array_d7/disallow_long_array_d7.info b/coder_sniffer/Drupal/Test/Arrays/disallow_long_array_d7/disallow_long_array_d7.info similarity index 100% rename from coder_sniffer/Drupal/Test/Array/disallow_long_array_d7/disallow_long_array_d7.info rename to coder_sniffer/Drupal/Test/Arrays/disallow_long_array_d7/disallow_long_array_d7.info diff --git a/coder_sniffer/Drupal/Test/Array/disallow_long_array_d8/DisallowLongArraySyntaxUnitTest.2.inc b/coder_sniffer/Drupal/Test/Arrays/disallow_long_array_d8/DisallowLongArraySyntaxUnitTest.2.inc similarity index 100% rename from coder_sniffer/Drupal/Test/Array/disallow_long_array_d8/DisallowLongArraySyntaxUnitTest.2.inc rename to coder_sniffer/Drupal/Test/Arrays/disallow_long_array_d8/DisallowLongArraySyntaxUnitTest.2.inc diff --git a/coder_sniffer/Drupal/Test/Array/disallow_long_array_d8/DisallowLongArraySyntaxUnitTest.2.inc.fixed b/coder_sniffer/Drupal/Test/Arrays/disallow_long_array_d8/DisallowLongArraySyntaxUnitTest.2.inc.fixed similarity index 100% rename from coder_sniffer/Drupal/Test/Array/disallow_long_array_d8/DisallowLongArraySyntaxUnitTest.2.inc.fixed rename to coder_sniffer/Drupal/Test/Arrays/disallow_long_array_d8/DisallowLongArraySyntaxUnitTest.2.inc.fixed diff --git a/coder_sniffer/Drupal/Test/Array/disallow_long_array_d8/disallow_long_array_d8.info.yml b/coder_sniffer/Drupal/Test/Arrays/disallow_long_array_d8/disallow_long_array_d8.info.yml similarity index 100% rename from coder_sniffer/Drupal/Test/Array/disallow_long_array_d8/disallow_long_array_d8.info.yml rename to coder_sniffer/Drupal/Test/Arrays/disallow_long_array_d8/disallow_long_array_d8.info.yml diff --git a/coder_sniffer/Drupal/Test/Classes/ClassCreateInstanceUnitTest.php b/coder_sniffer/Drupal/Test/Classes/ClassCreateInstanceUnitTest.php index d30627d8..2d7b867a 100644 --- a/coder_sniffer/Drupal/Test/Classes/ClassCreateInstanceUnitTest.php +++ b/coder_sniffer/Drupal/Test/Classes/ClassCreateInstanceUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_Classes_ClassCreateInstanceUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\Classes; + +use Drupal\Test\CoderSniffUnitTest; + +class ClassCreateInstanceUnitTest extends CoderSniffUnitTest { @@ -12,7 +16,7 @@ class Drupal_Sniffs_Classes_ClassCreateInstanceUnitTest extends CoderSniffUnitTe * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array( 3 => 1, @@ -41,7 +45,7 @@ class Drupal_Sniffs_Classes_ClassCreateInstanceUnitTest extends CoderSniffUnitTe * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); diff --git a/coder_sniffer/Drupal/Test/Classes/ClassDeclarationUnitTest.php b/coder_sniffer/Drupal/Test/Classes/ClassDeclarationUnitTest.php index 6e713def..5a5b339e 100644 --- a/coder_sniffer/Drupal/Test/Classes/ClassDeclarationUnitTest.php +++ b/coder_sniffer/Drupal/Test/Classes/ClassDeclarationUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_Classes_ClassDeclarationUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\Classes; + +use Drupal\Test\CoderSniffUnitTest; + +class ClassDeclarationUnitTest extends CoderSniffUnitTest { @@ -12,7 +16,7 @@ class Drupal_Sniffs_Classes_ClassDeclarationUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array( 11 => 1, @@ -31,7 +35,7 @@ class Drupal_Sniffs_Classes_ClassDeclarationUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); diff --git a/coder_sniffer/Drupal/Test/Classes/FullyQualifiedNamespaceUnitTest.php b/coder_sniffer/Drupal/Test/Classes/FullyQualifiedNamespaceUnitTest.php index 4a51b016..01012c03 100644 --- a/coder_sniffer/Drupal/Test/Classes/FullyQualifiedNamespaceUnitTest.php +++ b/coder_sniffer/Drupal/Test/Classes/FullyQualifiedNamespaceUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_Classes_FullyQualifiedNamespaceUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\Classes; + +use Drupal\Test\CoderSniffUnitTest;; + +class FullyQualifiedNamespaceUnitTest extends CoderSniffUnitTest { @@ -12,7 +16,7 @@ class Drupal_Sniffs_Classes_FullyQualifiedNamespaceUnitTest extends CoderSniffUn * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { switch ($testFile) { case 'FullyQualifiedNamespaceUnitTest.inc': @@ -34,7 +38,7 @@ class Drupal_Sniffs_Classes_FullyQualifiedNamespaceUnitTest extends CoderSniffUn * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); @@ -46,7 +50,7 @@ class Drupal_Sniffs_Classes_FullyQualifiedNamespaceUnitTest extends CoderSniffUn * * @return array The list of test files. */ - protected function getTestFiles() { + protected function getTestFiles($testFileBase) { return [__DIR__.'/FullyQualifiedNamespaceUnitTest.inc', __DIR__.'/FullyQualifiedNamespaceUnitTest.api.php']; } diff --git a/coder_sniffer/Drupal/Test/Classes/PropertyDeclarationUnitTest.php b/coder_sniffer/Drupal/Test/Classes/PropertyDeclarationUnitTest.php index 051d6bb0..043143ae 100644 --- a/coder_sniffer/Drupal/Test/Classes/PropertyDeclarationUnitTest.php +++ b/coder_sniffer/Drupal/Test/Classes/PropertyDeclarationUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_Classes_PropertyDeclarationUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\Classes; + +use Drupal\Test\CoderSniffUnitTest; + +class PropertyDeclarationUnitTest extends CoderSniffUnitTest { @@ -12,7 +16,7 @@ class Drupal_Sniffs_Classes_PropertyDeclarationUnitTest extends CoderSniffUnitTe * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array(16 => 2); @@ -27,7 +31,7 @@ class Drupal_Sniffs_Classes_PropertyDeclarationUnitTest extends CoderSniffUnitTe * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); diff --git a/coder_sniffer/Drupal/Test/Classes/UnusedUseStatementUnitTest.php b/coder_sniffer/Drupal/Test/Classes/UnusedUseStatementUnitTest.php index ab507857..7f09f148 100644 --- a/coder_sniffer/Drupal/Test/Classes/UnusedUseStatementUnitTest.php +++ b/coder_sniffer/Drupal/Test/Classes/UnusedUseStatementUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_Classes_UnusedUseStatementUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\Classes; + +use Drupal\Test\CoderSniffUnitTest; + +class UnusedUseStatementUnitTest extends CoderSniffUnitTest { @@ -12,7 +16,7 @@ class Drupal_Sniffs_Classes_UnusedUseStatementUnitTest extends CoderSniffUnitTes * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array(); @@ -27,7 +31,7 @@ class Drupal_Sniffs_Classes_UnusedUseStatementUnitTest extends CoderSniffUnitTes * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array( 5 => 1, diff --git a/coder_sniffer/Drupal/Test/Classes/UseLeadingBackslashUnitTest.php b/coder_sniffer/Drupal/Test/Classes/UseLeadingBackslashUnitTest.php index fab71a31..70f7c5fa 100644 --- a/coder_sniffer/Drupal/Test/Classes/UseLeadingBackslashUnitTest.php +++ b/coder_sniffer/Drupal/Test/Classes/UseLeadingBackslashUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_Classes_UseLeadingBackslashUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\Classes; + +use Drupal\Test\CoderSniffUnitTest; + +class UseLeadingBackslashUnitTest extends CoderSniffUnitTest { @@ -12,7 +16,7 @@ class Drupal_Sniffs_Classes_UseLeadingBackslashUnitTest extends CoderSniffUnitTe * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array(8 => 1); @@ -27,7 +31,7 @@ class Drupal_Sniffs_Classes_UseLeadingBackslashUnitTest extends CoderSniffUnitTe * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); diff --git a/coder_sniffer/Drupal/Test/CoderSniffUnitTest.php b/coder_sniffer/Drupal/Test/CoderSniffUnitTest.php index 4f883d5d..c5a948b9 100644 --- a/coder_sniffer/Drupal/Test/CoderSniffUnitTest.php +++ b/coder_sniffer/Drupal/Test/CoderSniffUnitTest.php @@ -1,22 +1,51 @@ <?php -/** - * An abstract class that all sniff unit tests must extend. - */ - /** * An abstract class that all sniff unit tests must extend. * - * This is a modified copy of AbstractSniffUnitTest used in PHP_CodeSniffer. + * A sniff unit test checks a .inc file for expected violations of a single + * coding standard. Expected errors and warnings that are not found, or + * warnings and errors that are not expected, are considered test failures. + * + * @author Greg Sherwood <gsherwood@squiz.net> + * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600) + * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence */ -abstract class CoderSniffUnitTest extends PHPUnit_Framework_TestCase + +namespace Drupal\Test; + +use PHP_CodeSniffer\Config; +use PHP_CodeSniffer\Ruleset; +use PHP_CodeSniffer\Files\LocalFile; +use PHP_CodeSniffer\RuntimeException; +use PHP_CodeSniffer\Util\Common; +use PHP_CodeSniffer\Autoload; +use PHP_CodeSniffer\Util\Tokens; + +abstract class CoderSniffUnitTest extends \PHPUnit_Framework_TestCase { /** - * The PHP_CodeSniffer object used for testing. + * Enable or disable the backup and restoration of the $GLOBALS array. + * Overwrite this attribute in a child class of TestCase. + * Setting this attribute in setUp() has no effect! + * + * @var boolean + */ + protected $backupGlobals = false; + + /** + * The path to the standard's main directory. + * + * @var string + */ + public $standardsDir = null; + + /** + * The path to the standard's test directory. * - * @var PHP_CodeSniffer + * @var string */ - protected static $phpcs = null; + public $testsDir = null; /** @@ -26,19 +55,54 @@ abstract class CoderSniffUnitTest extends PHPUnit_Framework_TestCase */ protected function setUp() { - if (!defined('PHP_CODESNIFFER_IN_TESTS')) { - define('PHP_CODESNIFFER_IN_TESTS', true); + $class = get_class($this); + + $this->rootDir = __DIR__ . '/../../'; + $this->testsDir = __DIR__.'/'; + $this->standardsDir = __DIR__.'/../'; + // Required to pull in all the defines from the tokens file. + $tokens = new Tokens(); + if (!defined('PHP_CODESNIFFER_VERBOSITY')) { + define('PHP_CODESNIFFER_VERBOSITY', 0); } - if (self::$phpcs === null) { - self::$phpcs = new PHP_CodeSniffer(0, 0, 'utf-8'); + if (!defined('PHP_CODESNIFFER_CBF')) { + define('PHP_CODESNIFFER_CBF', 0); } + }//end setUp() - // Make sure our sniffs are known by setting the additional installed paths. - $GLOBALS['PHP_CODESNIFFER_CONFIG_DATA'] = [ - 'installed_paths' => dirname(dirname(__DIR__)), - ]; - }//end setUp() + /** + * Get a list of all test files to check. + * + * These will have the same base as the sniff name but different extensions. + * We ignore the .php file as it is the class. + * + * @param string $testFileBase The base path that the unit tests files will have. + * + * @return string[] + */ + protected function getTestFiles($testFileBase) + { + $testFiles = array(); + + $dir = substr($testFileBase, 0, strrpos($testFileBase, DIRECTORY_SEPARATOR)); + $di = new \DirectoryIterator($dir); + + foreach ($di as $file) { + $path = $file->getPathname(); + if (substr($path, 0, strlen($testFileBase)) === $testFileBase) { + if ($path !== $testFileBase.'php' && substr($path, -5) !== 'fixed') { + $testFiles[] = $path; + } + } + } + + // Put them in order. + sort($testFiles); + + return $testFiles; + + }//end getTestFiles() /** @@ -59,58 +123,96 @@ abstract class CoderSniffUnitTest extends PHPUnit_Framework_TestCase * @return void * @throws PHPUnit_Framework_Error */ - public final function testSniff() + final public function testSniff() { // Skip this test if we can't run in this environment. if ($this->shouldSkipTest() === true) { $this->markTestSkipped(); } - $testFiles = $this->getTestFiles(); - $sniffCodes = $this->getSniffCodes(); + $sniffCode = Common::getSniffCode(get_class($this)); + list($standardName, $categoryName, $sniffName) = explode('.', $sniffCode); + + // In the case where we are running all the sniffs, the standard will + // be the root class name. + if ($this->allSniffCodes()) { + list($standardName) = explode('\\', get_class($this)); + } + + $testFileBase = $this->rootDir.$standardName.DIRECTORY_SEPARATOR.'Test'.DIRECTORY_SEPARATOR.$categoryName.DIRECTORY_SEPARATOR.$sniffName.'UnitTest.'; + + $this->standardsDir = $this->rootDir.$standardName.DIRECTORY_SEPARATOR; + // $testFileBase = $this->testsDir.$categoryName.DIRECTORY_SEPARATOR.$sniffName.'UnitTest.'; - // Determine the standard to be used from the class name. - $class_name_parts = explode('_', get_class($this)); - $standard = $class_name_parts[0]; + // Get a list of all test files to check. + $testFiles = $this->getTestFiles($testFileBase); + + $config = new Config(); + $config->cache = false; + $GLOBALS['PHP_CODESNIFFER_CONFIG'] = $config; + + // $config->standards = array($standardName); + $config->ignored = array(); + $config->standards = array($this->standardsDir); $failureMessages = array(); foreach ($testFiles as $testFile) { - self::$phpcs->initStandard("coder_sniffer/$standard", $sniffCodes); - $filename = basename($testFile); + // Setup to test the selected Sniff. + if ($this->allSniffCodes()) { + $config->sniffs = []; + } + else { + $config->sniffs = array($sniffCode); + } + $ruleset = new Ruleset($config); + $GLOBALS['PHP_CODESNIFFER_RULESET'] = $ruleset; + + $filename = basename($testFile); + $oldConfig = $config->getSettings(); try { - $cliValues = $this->getCliValues($filename); - self::$phpcs->cli->setCommandLineValues($cliValues); - $phpcsFile = self::$phpcs->processFile($testFile); - } catch (Exception $e) { + $this->setCliValues($filename, $config); + $phpcsFile = new LocalFile($testFile, $ruleset, $config); + $phpcsFile->process(); + } catch (RuntimeException $e) { $this->fail('An unexpected exception has been caught: '.$e->getMessage()); } $failures = $this->generateFailureMessages($phpcsFile); $failureMessages = array_merge($failureMessages, $failures); - // Attempt to fix the errors. - // Re-initialize the standard to use all sniffs for the fixer. - self::$phpcs->initStandard("coder_sniffer/$standard"); - self::$phpcs->cli->setCommandLineValues($cliValues); - $phpcsFile = self::$phpcs->processFile($testFile); - - $phpcsFile->fixer->fixFile(); - $fixable = $phpcsFile->getFixableCount(); - if ($fixable > 0) { - $failureMessages[] = "Failed to fix $fixable fixable violations in $filename"; - } + if ($phpcsFile->getFixableCount() > 0) { + // Reinit to use all sniffs. + $config->sniffs = []; + $ruleset = new Ruleset($config); + try { + $this->setCliValues($filename, $config); + $phpcsFile = new LocalFile($testFile, $ruleset, $config); + $phpcsFile->process(); + } catch (RuntimeException $e) { + $this->fail('An unexpected exception has been caught: '.$e->getMessage()); + } + // Attempt to fix the errors. + $phpcsFile->fixer->fixFile(); + $fixable = $phpcsFile->getFixableCount(); + if ($fixable > 0) { + $failureMessages[] = "Failed to fix $fixable fixable violations in $filename"; + } - // Check for a .fixed file to check for accuracy of fixes. - $fixedFile = $testFile.'.fixed'; - if (file_exists($fixedFile) === true) { - $diff = $phpcsFile->fixer->generateDiff($fixedFile); - if (trim($diff) !== '') { - $filename = basename($testFile); - $fixedFilename = basename($fixedFile); - $failureMessages[] = "Fixed version of $filename does not match expected version in $fixedFilename; the diff is\n$diff"; + // Check for a .fixed file to check for accuracy of fixes. + $fixedFile = $testFile.'.fixed'; + if (file_exists($fixedFile) === true) { + $diff = $phpcsFile->fixer->generateDiff($fixedFile); + if (trim($diff) !== '') { + $filename = basename($testFile); + $fixedFilename = basename($fixedFile); + $failureMessages[] = "Fixed version of $filename does not match expected version in $fixedFilename; the diff is\n$diff"; + } } } + + // Restore the config. + $config->setSettings($oldConfig); }//end foreach if (empty($failureMessages) === false) { @@ -119,50 +221,6 @@ abstract class CoderSniffUnitTest extends PHPUnit_Framework_TestCase }//end testSniff() - /** - * Returns a list of test files that should be checked. - * - * @return array The list of test files. - */ - protected function getTestFiles() { - $rc = new ReflectionClass(get_class($this)); - // Cut off the "php" file extension of the test class file. - $testFileBase = substr($rc->getFileName(), 0, -3); - - // Get a list of all test files to check. These will have the same base - // name but different extensions. We ignore the .php file as it is the class. - $testFiles = array(); - - $dir = substr($testFileBase, 0, strrpos($testFileBase, DIRECTORY_SEPARATOR)); - $di = new DirectoryIterator($dir); - - foreach ($di as $file) { - $path = $file->getPathname(); - if (substr($path, 0, strlen($testFileBase)) === $testFileBase) { - if ($path !== $testFileBase.'php' && substr($path, -5) !== 'fixed') { - $testFiles[] = $path; - } - } - } - - // Get them in order. - sort($testFiles); - return $testFiles; - } - - /** - * Returns a list of sniff codes that should be checked in this test. - * - * @return array The list of sniff codes. - */ - protected function getSniffCodes() { - // The basis for determining file locations. - $basename = substr(get_class($this), 0, -8); - - // The code of the sniff we are testing. - $parts = explode('_', $basename); - return array($parts[0].'.'.$parts[2].'.'.$parts[3]); - } /** * Generate a list of test failures for a given sniffed file. @@ -172,7 +230,7 @@ abstract class CoderSniffUnitTest extends PHPUnit_Framework_TestCase * @return array * @throws PHP_CodeSniffer_Exception */ - public function generateFailureMessages(PHP_CodeSniffer_File $file) + public function generateFailureMessages(LocalFile $file) { $testFile = $file->getFilename(); @@ -182,11 +240,11 @@ abstract class CoderSniffUnitTest extends PHPUnit_Framework_TestCase $expectedWarnings = $this->getWarningList(basename($testFile)); if (is_array($expectedErrors) === false) { - throw new PHP_CodeSniffer_Exception('getErrorList() must return an array'); + throw new RuntimeException('getErrorList() must return an array'); } if (is_array($expectedWarnings) === false) { - throw new PHP_CodeSniffer_Exception('getWarningList() must return an array'); + throw new RuntimeException('getWarningList() must return an array'); } /* @@ -198,6 +256,8 @@ abstract class CoderSniffUnitTest extends PHPUnit_Framework_TestCase $allProblems = array(); $failureMessages = array(); + $GLOBALS['PHP_CODESNIFFER_SNIFF_CODES'] = []; + $GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES'] = []; foreach ($foundErrors as $line => $lineErrors) { foreach ($lineErrors as $column => $errors) { @@ -218,6 +278,17 @@ abstract class CoderSniffUnitTest extends PHPUnit_Framework_TestCase $errorsTemp = array(); foreach ($errors as $foundError) { $errorsTemp[] = $foundError['message'].' ('.$foundError['source'].')'; + + $source = $foundError['source']; + if (in_array($source, $GLOBALS['PHP_CODESNIFFER_SNIFF_CODES']) === false) { + $GLOBALS['PHP_CODESNIFFER_SNIFF_CODES'][] = $source; + } + + if ($foundError['fixable'] === true + && in_array($source, $GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES']) === false + ) { + $GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES'][] = $source; + } } $allProblems[$line]['found_errors'] = array_merge($foundErrorsTemp, $errorsTemp); @@ -300,16 +371,6 @@ abstract class CoderSniffUnitTest extends PHPUnit_Framework_TestCase $expectedErrors = $problems['expected_errors']; $expectedWarnings = $problems['expected_warnings']; - - // Uncomment the following generate line error pairs for the bad unit - // test. - /*if ($numErrors) { - print "$line => " . $numErrors . ",\n"; - } - if ($numWarnings) { - print "$line => " . $numWarnings . ",\n"; - }*/ - $errors = ''; $foundString = ''; @@ -367,15 +428,16 @@ abstract class CoderSniffUnitTest extends PHPUnit_Framework_TestCase /** * Get a list of CLI values to set before the file is tested. * - * @param string $filename The name of the file being tested. + * @param string $filename The name of the file being tested. + * @param \PHP_CodeSniffer\Config $config The config data for the run. * * @return array */ - public function getCliValues($filename) + public function setCliValues($filename, $config) { - return array(); + return; - }//end getCliValues() + }//end setCliValues() /** @@ -384,9 +446,9 @@ abstract class CoderSniffUnitTest extends PHPUnit_Framework_TestCase * The key of the array should represent the line number and the value * should represent the number of errors that should occur on that line. * - * @return array(int => int) + * @return array<int, int> */ - protected abstract function getErrorList($testFile); + abstract protected function getErrorList($testFile = NULL); /** @@ -397,7 +459,18 @@ abstract class CoderSniffUnitTest extends PHPUnit_Framework_TestCase * * @return array(int => int) */ - protected abstract function getWarningList($testFile); + abstract protected function getWarningList($testFile = NULL); + + + /** + * Returns a list of sniff codes that should be checked in this test. + * + * @return array The list of sniff codes. + */ + protected function allSniffCodes() { + return FALSE; + } + }//end class diff --git a/coder_sniffer/Drupal/Test/Commenting/ClassCommentUnitTest.php b/coder_sniffer/Drupal/Test/Commenting/ClassCommentUnitTest.php index b096084f..d777c324 100644 --- a/coder_sniffer/Drupal/Test/Commenting/ClassCommentUnitTest.php +++ b/coder_sniffer/Drupal/Test/Commenting/ClassCommentUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_Commenting_ClassCommentUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\Commenting; + +use Drupal\Test\CoderSniffUnitTest; + +class ClassCommentUnitTest extends CoderSniffUnitTest { /** @@ -11,7 +15,7 @@ class Drupal_Sniffs_Commenting_ClassCommentUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array( 8 => 1, @@ -28,7 +32,7 @@ class Drupal_Sniffs_Commenting_ClassCommentUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); diff --git a/coder_sniffer/Drupal/Test/Commenting/DataTypeNamespaceUnitTest.php b/coder_sniffer/Drupal/Test/Commenting/DataTypeNamespaceUnitTest.php index 5e958169..65f1f1e6 100644 --- a/coder_sniffer/Drupal/Test/Commenting/DataTypeNamespaceUnitTest.php +++ b/coder_sniffer/Drupal/Test/Commenting/DataTypeNamespaceUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_Commenting_DataTypeNamespaceUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\Commenting; + +use Drupal\Test\CoderSniffUnitTest; + +class DataTypeNamespaceUnitTest extends CoderSniffUnitTest { /** @@ -11,7 +15,7 @@ class Drupal_Sniffs_Commenting_DataTypeNamespaceUnitTest extends CoderSniffUnitT * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array( 15 => 1, @@ -30,7 +34,7 @@ class Drupal_Sniffs_Commenting_DataTypeNamespaceUnitTest extends CoderSniffUnitT * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); diff --git a/coder_sniffer/Drupal/Test/Commenting/DocCommentAlignmentUnitTest.php b/coder_sniffer/Drupal/Test/Commenting/DocCommentAlignmentUnitTest.php index 85277fc6..7426326d 100644 --- a/coder_sniffer/Drupal/Test/Commenting/DocCommentAlignmentUnitTest.php +++ b/coder_sniffer/Drupal/Test/Commenting/DocCommentAlignmentUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_Commenting_DocCommentAlignmentUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\Commenting; + +use Drupal\Test\CoderSniffUnitTest; + +class DocCommentAlignmentUnitTest extends CoderSniffUnitTest { /** @@ -11,7 +15,7 @@ class Drupal_Sniffs_Commenting_DocCommentAlignmentUnitTest extends CoderSniffUni * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array( 14 => 1, @@ -29,7 +33,7 @@ class Drupal_Sniffs_Commenting_DocCommentAlignmentUnitTest extends CoderSniffUni * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); diff --git a/coder_sniffer/Drupal/Test/Commenting/DocCommentStarUnitTest.php b/coder_sniffer/Drupal/Test/Commenting/DocCommentStarUnitTest.php index 5a610480..dd4d8b89 100644 --- a/coder_sniffer/Drupal/Test/Commenting/DocCommentStarUnitTest.php +++ b/coder_sniffer/Drupal/Test/Commenting/DocCommentStarUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_Commenting_DocCommentStarUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\Commenting; + +use Drupal\Test\CoderSniffUnitTest; + +class DocCommentStarUnitTest extends CoderSniffUnitTest { /** @@ -11,7 +15,7 @@ class Drupal_Sniffs_Commenting_DocCommentStarUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { switch ($testFile) { case 'DocCommentStarUnitTest.inc': @@ -34,7 +38,7 @@ class Drupal_Sniffs_Commenting_DocCommentStarUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); diff --git a/coder_sniffer/Drupal/Test/Commenting/DocCommentUnitTest.inc b/coder_sniffer/Drupal/Test/Commenting/DocCommentUnitTest.inc index 52872036..f1348579 100644 --- a/coder_sniffer/Drupal/Test/Commenting/DocCommentUnitTest.inc +++ b/coder_sniffer/Drupal/Test/Commenting/DocCommentUnitTest.inc @@ -96,3 +96,10 @@ function test12() { */ public function givenOrganisations(TableNode $organisation_table) { } + +/**+ + * This has a typo after the comment start. + */ +function test13() { + +} diff --git a/coder_sniffer/Drupal/Test/Commenting/DocCommentUnitTest.inc.fixed b/coder_sniffer/Drupal/Test/Commenting/DocCommentUnitTest.inc.fixed index d4f71d32..0bacbcee 100644 --- a/coder_sniffer/Drupal/Test/Commenting/DocCommentUnitTest.inc.fixed +++ b/coder_sniffer/Drupal/Test/Commenting/DocCommentUnitTest.inc.fixed @@ -104,3 +104,11 @@ function test12() { */ public function givenOrganisations(TableNode $organisation_table) { } + +/** + * + + * This has a typo after the comment start. + */ +function test13() { + +} diff --git a/coder_sniffer/Drupal/Test/Commenting/DocCommentUnitTest.php b/coder_sniffer/Drupal/Test/Commenting/DocCommentUnitTest.php index b2db4515..595802b5 100644 --- a/coder_sniffer/Drupal/Test/Commenting/DocCommentUnitTest.php +++ b/coder_sniffer/Drupal/Test/Commenting/DocCommentUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_Commenting_DocCommentUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\Commenting; + +use Drupal\Test\CoderSniffUnitTest; + +class DocCommentUnitTest extends CoderSniffUnitTest { /** @@ -11,7 +15,7 @@ class Drupal_Sniffs_Commenting_DocCommentUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { switch ($testFile) { case 'DocCommentUnitTest.inc': @@ -24,6 +28,8 @@ class Drupal_Sniffs_Commenting_DocCommentUnitTest extends CoderSniffUnitTest 36 => 2, 45 => 1, 66 => 1, + 100 => 4, + 101 => 1, ); default: return array(); @@ -40,7 +46,7 @@ class Drupal_Sniffs_Commenting_DocCommentUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); diff --git a/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.10.inc b/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.10.inc index 12f25187..ffb5ee9d 100644 --- a/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.10.inc +++ b/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.10.inc @@ -1,14 +1,7 @@ <?php - /** * @file */ - -namespace Blah; - -/** - * Bla. - */ -trait Pum { - +function foo_bar($foo) { + return NULL; } diff --git a/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.10.inc.fixed b/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.10.inc.fixed index 0a148ed8..443fe4a7 100644 --- a/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.10.inc.fixed +++ b/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.10.inc.fixed @@ -1,10 +1,12 @@ <?php -namespace Blah; - /** - * Bla. + * @file */ -trait Pum { +/** + * + */ +function foo_bar($foo) { + return NULL; } diff --git a/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.11.inc b/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.11.inc index ffb5ee9d..17bad8e3 100644 --- a/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.11.inc +++ b/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.11.inc @@ -2,6 +2,6 @@ /** * @file */ -function foo_bar($foo) { - return NULL; +class Foo { + } diff --git a/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.11.inc.fixed b/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.11.inc.fixed index 443fe4a7..a188fc47 100644 --- a/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.11.inc.fixed +++ b/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.11.inc.fixed @@ -7,6 +7,6 @@ /** * */ -function foo_bar($foo) { - return NULL; +class Foo { + } diff --git a/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.12.inc b/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.12.inc deleted file mode 100644 index 17bad8e3..00000000 --- a/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.12.inc +++ /dev/null @@ -1,7 +0,0 @@ -<?php -/** - * @file - */ -class Foo { - -} diff --git a/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.12.inc.fixed b/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.12.inc.fixed deleted file mode 100644 index a188fc47..00000000 --- a/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.12.inc.fixed +++ /dev/null @@ -1,12 +0,0 @@ -<?php - -/** - * @file - */ - -/** - * - */ -class Foo { - -} diff --git a/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.5.inc b/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.5.inc index 5d6d9264..b10b4cc4 100644 --- a/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.5.inc +++ b/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.5.inc @@ -1,6 +1,6 @@ -<?php - -/**+ - * @file - * Typo after comment start. - */ +<nav aria-labelledby="breadcrumb_title" class="breadcrumb" role="navigation"> +<p class="hide" id="breadcrumb_title"><?php echo t('You are here'); ?> </p> + <ul class="breadcrumb"> + <li><?php echo implode('</li><li> ', $variables['breadcrumb']); ?></li> + </ul> +</nav> diff --git a/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.5.inc.fixed b/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.5.inc.fixed index 6d0cdda2..5b0a7c66 100644 --- a/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.5.inc.fixed +++ b/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.5.inc.fixed @@ -2,7 +2,11 @@ /** * @file - * +. - * - * Typo after comment start. */ +?> +<nav aria-labelledby="breadcrumb_title" class="breadcrumb" role="navigation"> +<p class="hide" id="breadcrumb_title"><?php echo t('You are here'); ?> </p> + <ul class="breadcrumb"> + <li><?php echo implode('</li><li> ', $variables['breadcrumb']); ?></li> + </ul> +</nav> diff --git a/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.6.inc b/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.6.inc index b10b4cc4..7c219195 100644 --- a/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.6.inc +++ b/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.6.inc @@ -1,6 +1,14 @@ -<nav aria-labelledby="breadcrumb_title" class="breadcrumb" role="navigation"> -<p class="hide" id="breadcrumb_title"><?php echo t('You are here'); ?> </p> - <ul class="breadcrumb"> - <li><?php echo implode('</li><li> ', $variables['breadcrumb']); ?></li> - </ul> -</nav> +<?php + +/** + * @file + */ + +namespace Blah; + +/** + * Bla. + */ +class Pum { + +} diff --git a/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.6.inc.fixed b/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.6.inc.fixed index 5b0a7c66..364567a4 100644 --- a/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.6.inc.fixed +++ b/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.6.inc.fixed @@ -1,12 +1,10 @@ <?php +namespace Blah; + /** - * @file + * Bla. */ -?> -<nav aria-labelledby="breadcrumb_title" class="breadcrumb" role="navigation"> -<p class="hide" id="breadcrumb_title"><?php echo t('You are here'); ?> </p> - <ul class="breadcrumb"> - <li><?php echo implode('</li><li> ', $variables['breadcrumb']); ?></li> - </ul> -</nav> +class Pum { + +} diff --git a/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.7.inc b/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.7.inc index 7c219195..941f59d3 100644 --- a/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.7.inc +++ b/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.7.inc @@ -1,11 +1,5 @@ <?php -/** - * @file - */ - -namespace Blah; - /** * Bla. */ diff --git a/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.7.inc.fixed b/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.7.inc.fixed index 364567a4..941f59d3 100644 --- a/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.7.inc.fixed +++ b/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.7.inc.fixed @@ -1,7 +1,5 @@ <?php -namespace Blah; - /** * Bla. */ diff --git a/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.8.inc b/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.8.inc index 941f59d3..e843c83a 100644 --- a/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.8.inc +++ b/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.8.inc @@ -1,8 +1,14 @@ <?php +/** + * @file + */ + +namespace Blah; + /** * Bla. */ -class Pum { +interface Pum { } diff --git a/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.8.inc.fixed b/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.8.inc.fixed index 941f59d3..743f1574 100644 --- a/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.8.inc.fixed +++ b/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.8.inc.fixed @@ -1,8 +1,10 @@ <?php +namespace Blah; + /** * Bla. */ -class Pum { +interface Pum { } diff --git a/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.9.inc b/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.9.inc index e843c83a..12f25187 100644 --- a/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.9.inc +++ b/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.9.inc @@ -9,6 +9,6 @@ namespace Blah; /** * Bla. */ -interface Pum { +trait Pum { } diff --git a/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.9.inc.fixed b/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.9.inc.fixed index 743f1574..0a148ed8 100644 --- a/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.9.inc.fixed +++ b/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.9.inc.fixed @@ -5,6 +5,6 @@ namespace Blah; /** * Bla. */ -interface Pum { +trait Pum { } diff --git a/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.php b/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.php index 1de41cdc..202b31b3 100644 --- a/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.php +++ b/coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_Commenting_FileCommentUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\Commenting; + +use Drupal\Test\CoderSniffUnitTest; + +class FileCommentUnitTest extends CoderSniffUnitTest { /** @@ -11,7 +15,7 @@ class Drupal_Sniffs_Commenting_FileCommentUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { switch ($testFile) { case 'FileCommentUnitTest.inc': @@ -35,32 +39,28 @@ class Drupal_Sniffs_Commenting_FileCommentUnitTest extends CoderSniffUnitTest 3 => 1, ); case 'FileCommentUnitTest.5.inc': - return array( - 3 => 1, - ); - case 'FileCommentUnitTest.6.inc': return array( 1 => 1, ); - case 'FileCommentUnitTest.7.inc': + case 'FileCommentUnitTest.6.inc': return array( 3 => 1, ); - case 'FileCommentUnitTest.8.inc': + case 'FileCommentUnitTest.7.inc': return array(); - case 'FileCommentUnitTest.9.inc': + case 'FileCommentUnitTest.8.inc': return array( 3 => 1, ); - case 'FileCommentUnitTest.10.inc': + case 'FileCommentUnitTest.9.inc': return array( 3 => 1, ); - case 'FileCommentUnitTest.11.inc': + case 'FileCommentUnitTest.10.inc': return array( 4 => 1, ); - case 'FileCommentUnitTest.12.inc': + case 'FileCommentUnitTest.11.inc': return array( 4 => 1, ); @@ -77,7 +77,7 @@ class Drupal_Sniffs_Commenting_FileCommentUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); diff --git a/coder_sniffer/Drupal/Test/Commenting/FunctionCommentUnitTest.php b/coder_sniffer/Drupal/Test/Commenting/FunctionCommentUnitTest.php index d3889031..f492a00a 100644 --- a/coder_sniffer/Drupal/Test/Commenting/FunctionCommentUnitTest.php +++ b/coder_sniffer/Drupal/Test/Commenting/FunctionCommentUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_Commenting_FunctionCommentUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\Commenting; + +use Drupal\Test\CoderSniffUnitTest; + +class FunctionCommentUnitTest extends CoderSniffUnitTest { /** @@ -11,7 +15,7 @@ class Drupal_Sniffs_Commenting_FunctionCommentUnitTest extends CoderSniffUnitTes * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { switch ($testFile) { case 'FunctionCommentUnitTest.inc': @@ -83,7 +87,7 @@ class Drupal_Sniffs_Commenting_FunctionCommentUnitTest extends CoderSniffUnitTes * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); diff --git a/coder_sniffer/Drupal/Test/Commenting/InlineCommentUnitTest.php b/coder_sniffer/Drupal/Test/Commenting/InlineCommentUnitTest.php index 96fa2400..e577f605 100644 --- a/coder_sniffer/Drupal/Test/Commenting/InlineCommentUnitTest.php +++ b/coder_sniffer/Drupal/Test/Commenting/InlineCommentUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_Commenting_InlineCommentUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\Commenting; + +use Drupal\Test\CoderSniffUnitTest; + +class InlineCommentUnitTest extends CoderSniffUnitTest { /** @@ -11,7 +15,7 @@ class Drupal_Sniffs_Commenting_InlineCommentUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array( 8 => 1, @@ -38,7 +42,7 @@ class Drupal_Sniffs_Commenting_InlineCommentUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array( 16 => 1, diff --git a/coder_sniffer/Drupal/Test/Commenting/PostStatementCommentUnitTest.php b/coder_sniffer/Drupal/Test/Commenting/PostStatementCommentUnitTest.php index a2be3e54..be137af8 100644 --- a/coder_sniffer/Drupal/Test/Commenting/PostStatementCommentUnitTest.php +++ b/coder_sniffer/Drupal/Test/Commenting/PostStatementCommentUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_Commenting_PostStatementCommentUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\Commenting; + +use Drupal\Test\CoderSniffUnitTest; + +class PostStatementCommentUnitTest extends CoderSniffUnitTest { /** @@ -11,7 +15,7 @@ class Drupal_Sniffs_Commenting_PostStatementCommentUnitTest extends CoderSniffUn * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { switch ($testFile) { case 'PostStatementCommentUnitTest.inc': @@ -36,7 +40,7 @@ class Drupal_Sniffs_Commenting_PostStatementCommentUnitTest extends CoderSniffUn * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); diff --git a/coder_sniffer/Drupal/Test/Commenting/VariableCommentUnitTest.php b/coder_sniffer/Drupal/Test/Commenting/VariableCommentUnitTest.php index 3f6ffa3f..340b878f 100644 --- a/coder_sniffer/Drupal/Test/Commenting/VariableCommentUnitTest.php +++ b/coder_sniffer/Drupal/Test/Commenting/VariableCommentUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_Commenting_VariableCommentUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\Commenting; + +use Drupal\Test\CoderSniffUnitTest; + +class VariableCommentUnitTest extends CoderSniffUnitTest { /** @@ -11,7 +15,7 @@ class Drupal_Sniffs_Commenting_VariableCommentUnitTest extends CoderSniffUnitTes * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array( 16 => 1, @@ -32,7 +36,7 @@ class Drupal_Sniffs_Commenting_VariableCommentUnitTest extends CoderSniffUnitTes * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); diff --git a/coder_sniffer/Drupal/Test/ControlStructures/ControlSignatureUnitTest.php b/coder_sniffer/Drupal/Test/ControlStructures/ControlSignatureUnitTest.php index 721901c4..4dee5ff2 100644 --- a/coder_sniffer/Drupal/Test/ControlStructures/ControlSignatureUnitTest.php +++ b/coder_sniffer/Drupal/Test/ControlStructures/ControlSignatureUnitTest.php @@ -1,9 +1,13 @@ <?php +namespace Drupal\Sniffs\ControlStructures; + +use Drupal\Test\CoderSniffUnitTest; + /** - * Class Drupal_Sniffs_ControlStructures_ControlSignatureUnitTest + * Class ControlSignatureUnitTest */ -class Drupal_Sniffs_ControlStructures_ControlSignatureUnitTest extends CoderSniffUnitTest +class ControlSignatureUnitTest extends CoderSniffUnitTest { /** @@ -14,7 +18,7 @@ class Drupal_Sniffs_ControlStructures_ControlSignatureUnitTest extends CoderSnif * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array( 6 => 1, @@ -32,7 +36,7 @@ class Drupal_Sniffs_ControlStructures_ControlSignatureUnitTest extends CoderSnif * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); diff --git a/coder_sniffer/Drupal/Test/ControlStructures/ElseIfUnitTest.php b/coder_sniffer/Drupal/Test/ControlStructures/ElseIfUnitTest.php index ff99e715..2c50ba60 100644 --- a/coder_sniffer/Drupal/Test/ControlStructures/ElseIfUnitTest.php +++ b/coder_sniffer/Drupal/Test/ControlStructures/ElseIfUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_ControlStructures_ElseIfUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\ControlStructures; + +use Drupal\Test\CoderSniffUnitTest; + +class ElseIfUnitTest extends CoderSniffUnitTest { /** @@ -11,7 +15,7 @@ class Drupal_Sniffs_ControlStructures_ElseIfUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array( 6 => 1, @@ -29,7 +33,7 @@ class Drupal_Sniffs_ControlStructures_ElseIfUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); diff --git a/coder_sniffer/Drupal/Test/Files/EndFileNewlineUnitTest.php b/coder_sniffer/Drupal/Test/Files/EndFileNewlineUnitTest.php index d6bbdcae..cbd51c35 100644 --- a/coder_sniffer/Drupal/Test/Files/EndFileNewlineUnitTest.php +++ b/coder_sniffer/Drupal/Test/Files/EndFileNewlineUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_Files_EndFileNewlineUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\Files; + +use Drupal\Test\CoderSniffUnitTest; + +class EndFileNewlineUnitTest extends CoderSniffUnitTest { @@ -12,7 +16,7 @@ class Drupal_Sniffs_Files_EndFileNewlineUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { // All the good files have no error. if (strpos($testFile, 'good') !== false) { @@ -36,7 +40,7 @@ class Drupal_Sniffs_Files_EndFileNewlineUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); diff --git a/coder_sniffer/Drupal/Test/Files/FileEncodingUnitTest.php b/coder_sniffer/Drupal/Test/Files/FileEncodingUnitTest.php index 1750cf8a..9b3b043d 100644 --- a/coder_sniffer/Drupal/Test/Files/FileEncodingUnitTest.php +++ b/coder_sniffer/Drupal/Test/Files/FileEncodingUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Tests_Files_FileEncodingUnitTest extends CoderSniffUnitTest +namespace PHP_CodeSniffer\Standards\Drupal\Tests\Files; + +use Drupal\Test\CoderSniffUnitTest; + +class FileEncodingUnitTest extends CoderSniffUnitTest { @@ -14,7 +18,7 @@ class Drupal_Tests_Files_FileEncodingUnitTest extends CoderSniffUnitTest * * @return array<int, int> */ - public function getErrorList($testFile='') + public function getErrorList($testFile = NULL) { return array(); @@ -31,7 +35,7 @@ class Drupal_Tests_Files_FileEncodingUnitTest extends CoderSniffUnitTest * * @return array<int, int> */ - public function getWarningList($testFile='') + public function getWarningList($testFile = NULL) { return array( 1 => 1, diff --git a/coder_sniffer/Drupal/Test/Files/LineLengthUnitTest.php b/coder_sniffer/Drupal/Test/Files/LineLengthUnitTest.php index 98739e92..e4fa6b4e 100644 --- a/coder_sniffer/Drupal/Test/Files/LineLengthUnitTest.php +++ b/coder_sniffer/Drupal/Test/Files/LineLengthUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_Files_LineLengthUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\Files; + +use Drupal\Test\CoderSniffUnitTest; + +class LineLengthUnitTest extends CoderSniffUnitTest { /** @@ -11,7 +15,7 @@ class Drupal_Sniffs_Files_LineLengthUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array(); @@ -26,7 +30,7 @@ class Drupal_Sniffs_Files_LineLengthUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); diff --git a/coder_sniffer/Drupal/Test/Files/TxtFileLineLengthUnitTest.php b/coder_sniffer/Drupal/Test/Files/TxtFileLineLengthUnitTest.php index a288d2cf..6db34623 100644 --- a/coder_sniffer/Drupal/Test/Files/TxtFileLineLengthUnitTest.php +++ b/coder_sniffer/Drupal/Test/Files/TxtFileLineLengthUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_Files_TxtFileLineLengthUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\Files; + +use Drupal\Test\CoderSniffUnitTest; + +class TxtFileLineLengthUnitTest extends CoderSniffUnitTest { @@ -12,7 +16,7 @@ class Drupal_Sniffs_Files_TxtFileLineLengthUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array(); @@ -27,7 +31,7 @@ class Drupal_Sniffs_Files_TxtFileLineLengthUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(1 => 1); diff --git a/coder_sniffer/Drupal/Test/Formatting/MultipleStatementAlignmentUnitTest.php b/coder_sniffer/Drupal/Test/Formatting/MultipleStatementAlignmentUnitTest.php index a7894bcb..9d60d6df 100644 --- a/coder_sniffer/Drupal/Test/Formatting/MultipleStatementAlignmentUnitTest.php +++ b/coder_sniffer/Drupal/Test/Formatting/MultipleStatementAlignmentUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_Formatting_MultipleStatementAlignmentUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\Formatting; + +use Drupal\Test\CoderSniffUnitTest; + +class MultipleStatementAlignmentUnitTest extends CoderSniffUnitTest { /** @@ -11,7 +15,7 @@ class Drupal_Sniffs_Formatting_MultipleStatementAlignmentUnitTest extends CoderS * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array( 8 => 1, @@ -37,7 +41,7 @@ class Drupal_Sniffs_Formatting_MultipleStatementAlignmentUnitTest extends CoderS * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); diff --git a/coder_sniffer/Drupal/Test/Formatting/SpaceUnaryOperatorUnitTest.php b/coder_sniffer/Drupal/Test/Formatting/SpaceUnaryOperatorUnitTest.php index e9f7dd50..5b46334b 100644 --- a/coder_sniffer/Drupal/Test/Formatting/SpaceUnaryOperatorUnitTest.php +++ b/coder_sniffer/Drupal/Test/Formatting/SpaceUnaryOperatorUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_Formatting_SpaceUnaryOperatorUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\Formatting; + +use Drupal\Test\CoderSniffUnitTest; + +class SpaceUnaryOperatorUnitTest extends CoderSniffUnitTest { /** @@ -11,7 +15,7 @@ class Drupal_Sniffs_Formatting_SpaceUnaryOperatorUnitTest extends CoderSniffUnit * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array( 3 => 1, @@ -32,7 +36,7 @@ class Drupal_Sniffs_Formatting_SpaceUnaryOperatorUnitTest extends CoderSniffUnit * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); diff --git a/coder_sniffer/Drupal/Test/InfoFiles/AutoAddedKeysUnitTest.php b/coder_sniffer/Drupal/Test/InfoFiles/AutoAddedKeysUnitTest.php index 3fd23435..99bd9ca5 100644 --- a/coder_sniffer/Drupal/Test/InfoFiles/AutoAddedKeysUnitTest.php +++ b/coder_sniffer/Drupal/Test/InfoFiles/AutoAddedKeysUnitTest.php @@ -1,10 +1,14 @@ <?php +namespace Drupal\Sniffs\InfoFiles; + +use Drupal\Test\CoderSniffUnitTest; + /** * A sniff unit test checks a .inc file for expected violations of a single * coding standard. Expected errors and warnings are stored in this class. */ -class Drupal_Sniffs_InfoFiles_AutoAddedKeysUnitTest extends CoderSniffUnitTest +class AutoAddedKeysUnitTest extends CoderSniffUnitTest { @@ -16,7 +20,7 @@ class Drupal_Sniffs_InfoFiles_AutoAddedKeysUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array(); @@ -31,7 +35,7 @@ class Drupal_Sniffs_InfoFiles_AutoAddedKeysUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(1 => 3); @@ -41,8 +45,8 @@ class Drupal_Sniffs_InfoFiles_AutoAddedKeysUnitTest extends CoderSniffUnitTest * Returns a list of test files that should be checked. * * @return array The list of test files. - */ - protected function getTestFiles() { + ' */ + protected function getTestFiles($testFileBase) { return array(__DIR__ . '/test.info', __DIR__ . '/test.info.yml'); } diff --git a/coder_sniffer/Drupal/Test/InfoFiles/ClassFilesUnitTest.php b/coder_sniffer/Drupal/Test/InfoFiles/ClassFilesUnitTest.php index fb838167..b1937eee 100644 --- a/coder_sniffer/Drupal/Test/InfoFiles/ClassFilesUnitTest.php +++ b/coder_sniffer/Drupal/Test/InfoFiles/ClassFilesUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_InfoFiles_ClassFilesUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\InfoFiles; + +use Drupal\Test\CoderSniffUnitTest; + +class ClassFilesUnitTest extends CoderSniffUnitTest { @@ -12,7 +16,7 @@ class Drupal_Sniffs_InfoFiles_ClassFilesUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array(); @@ -27,7 +31,7 @@ class Drupal_Sniffs_InfoFiles_ClassFilesUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); @@ -38,7 +42,7 @@ class Drupal_Sniffs_InfoFiles_ClassFilesUnitTest extends CoderSniffUnitTest * * @return array The list of test files. */ - protected function getTestFiles() { + protected function getTestFiles($testFileBase) { return array(__DIR__ . '/class_files.info'); } diff --git a/coder_sniffer/Drupal/Test/InfoFiles/DuplicateEntryUnitTest.php b/coder_sniffer/Drupal/Test/InfoFiles/DuplicateEntryUnitTest.php index 29aa7294..f403eb21 100644 --- a/coder_sniffer/Drupal/Test/InfoFiles/DuplicateEntryUnitTest.php +++ b/coder_sniffer/Drupal/Test/InfoFiles/DuplicateEntryUnitTest.php @@ -1,12 +1,16 @@ <?php +namespace Drupal\Sniffs\InfoFiles; + +use Drupal\Test\CoderSniffUnitTest; + /** * Unit test class for the DuplicateEntry sniff. * * A sniff unit test checks a .inc file for expected violations of a single * coding standard. Expected errors and warnings are stored in this class. */ -class Drupal_Sniffs_InfoFiles_DuplicateEntryUnitTest extends CoderSniffUnitTest +class DuplicateEntryUnitTest extends CoderSniffUnitTest { @@ -18,7 +22,7 @@ class Drupal_Sniffs_InfoFiles_DuplicateEntryUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array( 1 => 1, @@ -35,7 +39,7 @@ class Drupal_Sniffs_InfoFiles_DuplicateEntryUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); @@ -46,7 +50,7 @@ class Drupal_Sniffs_InfoFiles_DuplicateEntryUnitTest extends CoderSniffUnitTest * * @return array The list of test files. */ - protected function getTestFiles() { + protected function getTestFiles($testFileBase) { return array(__DIR__ . '/test.info'); } diff --git a/coder_sniffer/Drupal/Test/NamingConventions/ValidFunctionNameUnitTest.php b/coder_sniffer/Drupal/Test/NamingConventions/ValidFunctionNameUnitTest.php index 8fe2f7d8..401dc536 100644 --- a/coder_sniffer/Drupal/Test/NamingConventions/ValidFunctionNameUnitTest.php +++ b/coder_sniffer/Drupal/Test/NamingConventions/ValidFunctionNameUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_NamingConventions_ValidFunctionNameUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\NamingConventions; + +use Drupal\Test\CoderSniffUnitTest; + +class ValidFunctionNameUnitTest extends CoderSniffUnitTest { /** @@ -11,7 +15,7 @@ class Drupal_Sniffs_NamingConventions_ValidFunctionNameUnitTest extends CoderSni * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array( 3 => 1, @@ -30,7 +34,7 @@ class Drupal_Sniffs_NamingConventions_ValidFunctionNameUnitTest extends CoderSni * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); diff --git a/coder_sniffer/Drupal/Test/NamingConventions/ValidVariableNameUnitTest.php b/coder_sniffer/Drupal/Test/NamingConventions/ValidVariableNameUnitTest.php index 7766b37d..6f4171c1 100644 --- a/coder_sniffer/Drupal/Test/NamingConventions/ValidVariableNameUnitTest.php +++ b/coder_sniffer/Drupal/Test/NamingConventions/ValidVariableNameUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_NamingConventions_ValidVariableNameUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\NamingConventions; + +use Drupal\Test\CoderSniffUnitTest; + +class ValidVariableNameUnitTest extends CoderSniffUnitTest { /** @@ -11,7 +15,7 @@ class Drupal_Sniffs_NamingConventions_ValidVariableNameUnitTest extends CoderSni * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array( 3 => 1, @@ -28,7 +32,7 @@ class Drupal_Sniffs_NamingConventions_ValidVariableNameUnitTest extends CoderSni * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); diff --git a/coder_sniffer/Drupal/Test/Scope/MethodScopeUnitTest.php b/coder_sniffer/Drupal/Test/Scope/MethodScopeUnitTest.php index 2e6e28eb..f90c4497 100644 --- a/coder_sniffer/Drupal/Test/Scope/MethodScopeUnitTest.php +++ b/coder_sniffer/Drupal/Test/Scope/MethodScopeUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_Scope_MethodScopeUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\Scope; + +use Drupal\Test\CoderSniffUnitTest; + +class MethodScopeUnitTest extends CoderSniffUnitTest { @@ -12,7 +16,7 @@ class Drupal_Sniffs_Scope_MethodScopeUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array( 8 => 1, @@ -30,7 +34,7 @@ class Drupal_Sniffs_Scope_MethodScopeUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); diff --git a/coder_sniffer/Drupal/Test/Semantics/ConstantNameUnitTest.php b/coder_sniffer/Drupal/Test/Semantics/ConstantNameUnitTest.php index 756aa18f..c5adfe65 100644 --- a/coder_sniffer/Drupal/Test/Semantics/ConstantNameUnitTest.php +++ b/coder_sniffer/Drupal/Test/Semantics/ConstantNameUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_Semantics_ConstantNameUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\Semantics; + +use Drupal\Test\CoderSniffUnitTest; + +class ConstantNameUnitTest extends CoderSniffUnitTest { @@ -9,7 +13,7 @@ class Drupal_Sniffs_Semantics_ConstantNameUnitTest extends CoderSniffUnitTest * * @return array The list of test files. */ - protected function getTestFiles() + protected function getTestFiles($testFileBase) { $dir = dirname(__FILE__); return array($dir.'/constant_test.install', $dir.'/constant_test.module'); @@ -25,7 +29,7 @@ class Drupal_Sniffs_Semantics_ConstantNameUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array(); @@ -40,7 +44,7 @@ class Drupal_Sniffs_Semantics_ConstantNameUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(3 => 1); diff --git a/coder_sniffer/Drupal/Test/Semantics/FunctionTUnitTest.php b/coder_sniffer/Drupal/Test/Semantics/FunctionTUnitTest.php index bf9de9fd..4e68b69e 100644 --- a/coder_sniffer/Drupal/Test/Semantics/FunctionTUnitTest.php +++ b/coder_sniffer/Drupal/Test/Semantics/FunctionTUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_Semantics_FunctionTUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\Semantics; + +use Drupal\Test\CoderSniffUnitTest; + +class FunctionTUnitTest extends CoderSniffUnitTest { @@ -12,7 +16,7 @@ class Drupal_Sniffs_Semantics_FunctionTUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array( 29 => 1, @@ -29,7 +33,7 @@ class Drupal_Sniffs_Semantics_FunctionTUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array( 4 => 1, diff --git a/coder_sniffer/Drupal/Test/Semantics/FunctionWatchdogUnitTest.php b/coder_sniffer/Drupal/Test/Semantics/FunctionWatchdogUnitTest.php index e405cfc6..9cdc5f53 100644 --- a/coder_sniffer/Drupal/Test/Semantics/FunctionWatchdogUnitTest.php +++ b/coder_sniffer/Drupal/Test/Semantics/FunctionWatchdogUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_Semantics_FunctionWatchdogUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\Semantics; + +use Drupal\Test\CoderSniffUnitTest; + +class FunctionWatchdogUnitTest extends CoderSniffUnitTest { @@ -12,7 +16,7 @@ class Drupal_Sniffs_Semantics_FunctionWatchdogUnitTest extends CoderSniffUnitTes * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array(3 => 1); @@ -27,7 +31,7 @@ class Drupal_Sniffs_Semantics_FunctionWatchdogUnitTest extends CoderSniffUnitTes * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); diff --git a/coder_sniffer/Drupal/Test/WhiteSpace/CloseBracketSpacingUnitTest.php b/coder_sniffer/Drupal/Test/WhiteSpace/CloseBracketSpacingUnitTest.php index f5ac4f3b..31ecfb34 100644 --- a/coder_sniffer/Drupal/Test/WhiteSpace/CloseBracketSpacingUnitTest.php +++ b/coder_sniffer/Drupal/Test/WhiteSpace/CloseBracketSpacingUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_WhiteSpace_CloseBracketSpacingUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\WhiteSpace; + +use Drupal\Test\CoderSniffUnitTest; + +class CloseBracketSpacingUnitTest extends CoderSniffUnitTest { /** @@ -11,7 +15,7 @@ class Drupal_Sniffs_WhiteSpace_CloseBracketSpacingUnitTest extends CoderSniffUni * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array( 3 => 1, @@ -29,7 +33,7 @@ class Drupal_Sniffs_WhiteSpace_CloseBracketSpacingUnitTest extends CoderSniffUni * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); diff --git a/coder_sniffer/Drupal/Test/WhiteSpace/CommaUnitTest.php b/coder_sniffer/Drupal/Test/WhiteSpace/CommaUnitTest.php index b052f956..bbe9527b 100644 --- a/coder_sniffer/Drupal/Test/WhiteSpace/CommaUnitTest.php +++ b/coder_sniffer/Drupal/Test/WhiteSpace/CommaUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_WhiteSpace_CommaUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\WhiteSpace; + +use Drupal\Test\CoderSniffUnitTest; + +class CommaUnitTest extends CoderSniffUnitTest { /** @@ -11,7 +15,7 @@ class Drupal_Sniffs_WhiteSpace_CommaUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array( 3 => 1, @@ -33,7 +37,7 @@ class Drupal_Sniffs_WhiteSpace_CommaUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); diff --git a/coder_sniffer/Drupal/Test/WhiteSpace/NamespaceUnitTest.php b/coder_sniffer/Drupal/Test/WhiteSpace/NamespaceUnitTest.php index f57a722e..47f0ffa5 100644 --- a/coder_sniffer/Drupal/Test/WhiteSpace/NamespaceUnitTest.php +++ b/coder_sniffer/Drupal/Test/WhiteSpace/NamespaceUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_WhiteSpace_NamespaceUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\WhiteSpace; + +use Drupal\Test\CoderSniffUnitTest; + +class NamespaceUnitTest extends CoderSniffUnitTest { /** @@ -11,7 +15,7 @@ class Drupal_Sniffs_WhiteSpace_NamespaceUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array( 3 => 1, @@ -28,7 +32,7 @@ class Drupal_Sniffs_WhiteSpace_NamespaceUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); diff --git a/coder_sniffer/Drupal/Test/WhiteSpace/ObjectOperatorIndentUnitTest.php b/coder_sniffer/Drupal/Test/WhiteSpace/ObjectOperatorIndentUnitTest.php index 674b77e0..4f0b1d5b 100644 --- a/coder_sniffer/Drupal/Test/WhiteSpace/ObjectOperatorIndentUnitTest.php +++ b/coder_sniffer/Drupal/Test/WhiteSpace/ObjectOperatorIndentUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_WhiteSpace_ObjectOperatorIndentUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\WhiteSpace; + +use Drupal\Test\CoderSniffUnitTest; + +class ObjectOperatorIndentUnitTest extends CoderSniffUnitTest { /** @@ -11,7 +15,7 @@ class Drupal_Sniffs_WhiteSpace_ObjectOperatorIndentUnitTest extends CoderSniffUn * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array( 24 => 1, @@ -31,7 +35,7 @@ class Drupal_Sniffs_WhiteSpace_ObjectOperatorIndentUnitTest extends CoderSniffUn * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); diff --git a/coder_sniffer/Drupal/Test/WhiteSpace/ObjectOperatorSpacingUnitTest.php b/coder_sniffer/Drupal/Test/WhiteSpace/ObjectOperatorSpacingUnitTest.php index 1eee18c3..b760b65a 100644 --- a/coder_sniffer/Drupal/Test/WhiteSpace/ObjectOperatorSpacingUnitTest.php +++ b/coder_sniffer/Drupal/Test/WhiteSpace/ObjectOperatorSpacingUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_WhiteSpace_ObjectOperatorSpacingUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\WhiteSpace; + +use Drupal\Test\CoderSniffUnitTest; + +class ObjectOperatorSpacingUnitTest extends CoderSniffUnitTest { /** @@ -11,7 +15,7 @@ class Drupal_Sniffs_WhiteSpace_ObjectOperatorSpacingUnitTest extends CoderSniffU * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array( 9 => 1, @@ -29,7 +33,7 @@ class Drupal_Sniffs_WhiteSpace_ObjectOperatorSpacingUnitTest extends CoderSniffU * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); diff --git a/coder_sniffer/Drupal/Test/WhiteSpace/OpenBracketSpacingUnitTest.php b/coder_sniffer/Drupal/Test/WhiteSpace/OpenBracketSpacingUnitTest.php index a56847ec..515aaf5c 100644 --- a/coder_sniffer/Drupal/Test/WhiteSpace/OpenBracketSpacingUnitTest.php +++ b/coder_sniffer/Drupal/Test/WhiteSpace/OpenBracketSpacingUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_WhiteSpace_OpenBracketSpacingUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\WhiteSpace; + +use Drupal\Test\CoderSniffUnitTest; + +class OpenBracketSpacingUnitTest extends CoderSniffUnitTest { /** @@ -11,7 +15,7 @@ class Drupal_Sniffs_WhiteSpace_OpenBracketSpacingUnitTest extends CoderSniffUnit * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array( 3 => 1, @@ -29,7 +33,7 @@ class Drupal_Sniffs_WhiteSpace_OpenBracketSpacingUnitTest extends CoderSniffUnit * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); diff --git a/coder_sniffer/Drupal/Test/WhiteSpace/OpenTagNewlineUnitTest.php b/coder_sniffer/Drupal/Test/WhiteSpace/OpenTagNewlineUnitTest.php index 6d6f9cff..d9e6ac0d 100644 --- a/coder_sniffer/Drupal/Test/WhiteSpace/OpenTagNewlineUnitTest.php +++ b/coder_sniffer/Drupal/Test/WhiteSpace/OpenTagNewlineUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_WhiteSpace_OpenTagNewlineUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\WhiteSpace; + +use Drupal\Test\CoderSniffUnitTest; + +class OpenTagNewlineUnitTest extends CoderSniffUnitTest { /** @@ -11,7 +15,7 @@ class Drupal_Sniffs_WhiteSpace_OpenTagNewlineUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array( 1 => 1, @@ -28,7 +32,7 @@ class Drupal_Sniffs_WhiteSpace_OpenTagNewlineUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); diff --git a/coder_sniffer/Drupal/Test/WhiteSpace/ScopeIndentUnitTest.php b/coder_sniffer/Drupal/Test/WhiteSpace/ScopeIndentUnitTest.php index 9478a8e2..26eb3256 100644 --- a/coder_sniffer/Drupal/Test/WhiteSpace/ScopeIndentUnitTest.php +++ b/coder_sniffer/Drupal/Test/WhiteSpace/ScopeIndentUnitTest.php @@ -1,6 +1,10 @@ <?php -class Drupal_Sniffs_WhiteSpace_ScopeIndentUnitTest extends CoderSniffUnitTest +namespace Drupal\Sniffs\WhiteSpace; + +use Drupal\Test\CoderSniffUnitTest; + +class ScopeIndentUnitTest extends CoderSniffUnitTest { /** @@ -11,7 +15,7 @@ class Drupal_Sniffs_WhiteSpace_ScopeIndentUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array( 6 => 1, @@ -32,7 +36,7 @@ class Drupal_Sniffs_WhiteSpace_ScopeIndentUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); diff --git a/coder_sniffer/Drupal/Test/bad/BadUnitTest.php b/coder_sniffer/Drupal/Test/bad/BadUnitTest.php index 07a68237..e930e3a8 100644 --- a/coder_sniffer/Drupal/Test/bad/BadUnitTest.php +++ b/coder_sniffer/Drupal/Test/bad/BadUnitTest.php @@ -3,10 +3,14 @@ * Unit test class for all bad files. */ +namespace Drupal\bad; + +use Drupal\Test\CoderSniffUnitTest; + /** * Unit test class for all bad files. */ -class Drupal_BadUnitTest extends CoderSniffUnitTest +class BadUnitTest extends CoderSniffUnitTest { @@ -18,7 +22,7 @@ class Drupal_BadUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { switch ($testFile) { case 'bad.css': @@ -383,7 +387,7 @@ class Drupal_BadUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { switch ($testFile) { case 'bad.module': @@ -429,10 +433,10 @@ class Drupal_BadUnitTest extends CoderSniffUnitTest * * @return array The list of test files. */ - protected function getTestFiles() + protected function getTestFiles($testFileBase) { $dir = dirname(__FILE__); - $di = new DirectoryIterator($dir); + $di = new \DirectoryIterator($dir); foreach ($di as $file) { $path = $file->getPathname(); @@ -453,10 +457,10 @@ class Drupal_BadUnitTest extends CoderSniffUnitTest * * @return array The list of sniff codes. */ - protected function getSniffCodes() + protected function allSniffCodes() { // We want to test all sniffs defined in the standard. - return array(); + return TRUE; }//end getSniffCodes() diff --git a/coder_sniffer/Drupal/Test/good/GoodUnitTest.php b/coder_sniffer/Drupal/Test/good/GoodUnitTest.php index c5f9188a..cd623ebb 100644 --- a/coder_sniffer/Drupal/Test/good/GoodUnitTest.php +++ b/coder_sniffer/Drupal/Test/good/GoodUnitTest.php @@ -3,10 +3,14 @@ * Unit test class for all good files that must not throw errors/warnings. */ +namespace Drupal\good; + +use Drupal\Test\CoderSniffUnitTest; + /** * Unit test class for all good files that must not throw errors/warnings. */ -class Drupal_GoodUnitTest extends CoderSniffUnitTest +class GoodUnitTest extends CoderSniffUnitTest { @@ -18,7 +22,7 @@ class Drupal_GoodUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array(); @@ -33,7 +37,7 @@ class Drupal_GoodUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); @@ -44,9 +48,9 @@ class Drupal_GoodUnitTest extends CoderSniffUnitTest * * @return array The list of test files. */ - protected function getTestFiles() { + protected function getTestFiles($testFileBase) { $dir = dirname(__FILE__); - $di = new DirectoryIterator($dir); + $di = new \DirectoryIterator($dir); foreach ($di as $file) { $path = $file->getPathname(); @@ -65,9 +69,9 @@ class Drupal_GoodUnitTest extends CoderSniffUnitTest * * @return array The list of sniff codes. */ - protected function getSniffCodes() { + protected function allSniffCodes() { // We want to test all sniffs defined in the standard. - return array(); + return TRUE; } diff --git a/coder_sniffer/Drupal/Test/phpunit-bootstrap.php b/coder_sniffer/Drupal/Test/phpunit-bootstrap.php index 0b7572eb..233c9cd2 100644 --- a/coder_sniffer/Drupal/Test/phpunit-bootstrap.php +++ b/coder_sniffer/Drupal/Test/phpunit-bootstrap.php @@ -2,3 +2,4 @@ require 'vendor/autoload.php'; require 'CoderSniffUnitTest.php'; +require 'vendor/squizlabs/php_codesniffer/autoload.php'; diff --git a/coder_sniffer/Drupal/ruleset.xml b/coder_sniffer/Drupal/ruleset.xml index 5e2b0d98..ba8d5d79 100644 --- a/coder_sniffer/Drupal/ruleset.xml +++ b/coder_sniffer/Drupal/ruleset.xml @@ -110,6 +110,9 @@ <rule ref="PEAR.Functions.FunctionCallSignature.EmptyLine"> <severity>0</severity> </rule> + <rule ref="PEAR.Functions.FunctionCallSignature.OpeningIndent"> + <severity>0</severity> + </rule> <rule ref="PEAR.Functions.ValidDefaultValue" /> diff --git a/coder_sniffer/DrupalPractice/Project.php b/coder_sniffer/DrupalPractice/Project.php index 14871d75..45923bce 100644 --- a/coder_sniffer/DrupalPractice/Project.php +++ b/coder_sniffer/DrupalPractice/Project.php @@ -1,12 +1,16 @@ <?php /** - * DrupalPractice_Project + * \DrupalPractice\Project * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace DrupalPractice; + +use PHP_CodeSniffer\Files\File; +use \Drupal\Sniffs\InfoFiles\ClassFilesSniff; use Symfony\Component\Yaml\Yaml; /** @@ -16,19 +20,19 @@ use Symfony\Component\Yaml\Yaml; * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class DrupalPractice_Project +class Project { /** * Determines the project short name a file might be associated with. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. * * @return string|false Returns the project machine name or false if it could not * be derived. */ - public static function getName(PHP_CodeSniffer_File $phpcsFile) + public static function getName(File $phpcsFile) { // Cache the project name per file as this might get called often. static $cache; @@ -60,12 +64,12 @@ class DrupalPractice_Project /** * Determines the info file a file might be associated with. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. * * @return string|false The project info file name or false if it could not * be derived. */ - public static function getInfoFile(PHP_CodeSniffer_File $phpcsFile) + public static function getInfoFile(File $phpcsFile) { // Cache the project name per file as this might get called often. static $cache; @@ -95,7 +99,7 @@ class DrupalPractice_Project } // Sort the info file names and take the shortest info file. - usort($infoFiles, array('DrupalPractice_Project', 'compareLength')); + usort($infoFiles, array(__NAMESPACE__.'\Project', 'compareLength')); $infoFile = $infoFiles[0]; $cache[$phpcsFile->getFilename()] = $infoFile; return $infoFile; @@ -106,12 +110,12 @@ class DrupalPractice_Project /** * Determines the *.services.yml file in a module. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. * * @return string|false The Services YML file name or false if it could not * be derived. */ - public static function getServicesYmlFile(PHP_CodeSniffer_File $phpcsFile) + public static function getServicesYmlFile(File $phpcsFile) { // Cache the services file per file as this might get called often. static $cache; @@ -138,7 +142,7 @@ class DrupalPractice_Project } // Sort the YML file names and take the shortest info file. - usort($ymlFiles, array('DrupalPractice_Project', 'compareLength')); + usort($ymlFiles, array(__NAMESPACE__.'\Project', 'compareLength')); $ymlFile = $ymlFiles[0]; $cache[$phpcsFile->getFilename()] = $ymlFile; return $ymlFile; @@ -149,13 +153,13 @@ class DrupalPractice_Project /** * Return true if the given class is a Drupal service registered in *.services.yml. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $classPtr The position of the class declaration - * in the token stack. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $classPtr The position of the class declaration + * in the token stack. * * @return bool */ - public static function isServiceClass(PHP_CodeSniffer_File $phpcsFile, $classPtr) + public static function isServiceClass(File $phpcsFile, $classPtr) { // Cache the information per file as this might get called often. static $cache; @@ -228,12 +232,12 @@ class DrupalPractice_Project /** * Determines the Drupal core version a file might be associated with. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. * * @return string|false The core version string or false if it could not * be derived. */ - public static function getCoreVersion(PHP_CodeSniffer_File $phpcsFile) + public static function getCoreVersion(File $phpcsFile) { $infoFile = static::getInfoFile($phpcsFile); if ($infoFile === false) { @@ -244,7 +248,7 @@ class DrupalPractice_Project // Drupal 6 and 7 use the .info file extension. if ($pathParts['extension'] === 'info') { - $info_settings = Drupal_Sniffs_InfoFiles_ClassFilesSniff::drupalParseInfoFormat(file_get_contents($infoFile)); + $info_settings = ClassFilesSniff::drupalParseInfoFormat(file_get_contents($infoFile)); if (isset($info_settings['core']) === true) { return $info_settings['core']; } diff --git a/coder_sniffer/DrupalPractice/Sniffs/CodeAnalysis/VariableAnalysisSniff.php b/coder_sniffer/DrupalPractice/Sniffs/CodeAnalysis/VariableAnalysisSniff.php index 980021eb..0ed2cd21 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/CodeAnalysis/VariableAnalysisSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/CodeAnalysis/VariableAnalysisSniff.php @@ -10,6 +10,11 @@ * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace DrupalPractice\Sniffs\CodeAnalysis; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** * Holds details of a scope. * @@ -103,7 +108,7 @@ class VariableInfo * @copyright 2011 Sam Graham <php-codesniffer-variableanalysis BLAHBLAH illusori.co.uk> * @link http://pear.php.net/package/PHP_CodeSniffer */ -class DrupalPractice_Sniffs_CodeAnalysis_VariableAnalysisSniff implements PHP_CodeSniffer_Sniff +class VariableAnalysisSniff implements Sniff { /** * The current phpcsFile being checked. @@ -606,13 +611,13 @@ class DrupalPractice_Sniffs_CodeAnalysis_VariableAnalysisSniff implements PHP_Co /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $token = $tokens[$stackPtr]; @@ -897,14 +902,14 @@ class DrupalPractice_Sniffs_CodeAnalysis_VariableAnalysisSniff implements PHP_Co /** * Marks a variable as read and throws a PHPCS warning if it is undefined. * - * @param PHP_CodeSniffer_File $phpcsFile - * @param string $varName - * @param int $stackPtr - * @param string $currScope + * @param \PHP_CodeSniffer\Files\File $phpcsFile + * @param string $varName + * @param int $stackPtr + * @param string $currScope * * @return bool */ - function markVariableReadAndWarnIfUndefined(PHP_CodeSniffer_File $phpcsFile, $varName, $stackPtr, $currScope) + function markVariableReadAndWarnIfUndefined(File $phpcsFile, $varName, $stackPtr, $currScope) { $this->markVariableRead($varName, $stackPtr, $currScope); @@ -926,12 +931,12 @@ class DrupalPractice_Sniffs_CodeAnalysis_VariableAnalysisSniff implements PHP_Co /** * Returns the function declaration pointer. * - * @param PHP_CodeSniffer_File $phpcsFile - * @param int $stackPtr + * @param \PHP_CodeSniffer\Files\File $phpcsFile + * @param int $stackPtr * * @return int|false */ - function findFunctionPrototype(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + function findFunctionPrototype(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -969,12 +974,12 @@ class DrupalPractice_Sniffs_CodeAnalysis_VariableAnalysisSniff implements PHP_Co /** * Find the scope the given pointer is in. * - * @param PHP_CodeSniffer_File $phpcsFile - * @param int $stackPtr + * @param \PHP_CodeSniffer\Files\File $phpcsFile + * @param int $stackPtr * * @return int|false */ - function findVariableScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + function findVariableScope(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $token = $tokens[$stackPtr]; @@ -1010,12 +1015,12 @@ class DrupalPractice_Sniffs_CodeAnalysis_VariableAnalysisSniff implements PHP_Co /** * Checks if the next token is an assignment. * - * @param PHP_CodeSniffer_File $phpcsFile - * @param int $stackPtr + * @param \PHP_CodeSniffer\Files\File $phpcsFile + * @param int $stackPtr * * @return bool */ - function isNextThingAnAssign(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + function isNextThingAnAssign(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -1041,12 +1046,12 @@ class DrupalPractice_Sniffs_CodeAnalysis_VariableAnalysisSniff implements PHP_Co /** * Find the end of the assignment. * - * @param PHP_CodeSniffer_File $phpcsFile - * @param int $stackPtr + * @param \PHP_CodeSniffer\Files\File $phpcsFile + * @param int $stackPtr * * @return int */ - function findWhereAssignExecuted(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + function findWhereAssignExecuted(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -1085,12 +1090,12 @@ class DrupalPractice_Sniffs_CodeAnalysis_VariableAnalysisSniff implements PHP_Co /** * Find the parenthesis if the pointer is in some. * - * @param PHP_CodeSniffer_File $phpcsFile - * @param int $stackPtr + * @param \PHP_CodeSniffer\Files\File $phpcsFile + * @param int $stackPtr * * @return int|false */ - function findContainingBrackets(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + function findContainingBrackets(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -1107,12 +1112,12 @@ class DrupalPractice_Sniffs_CodeAnalysis_VariableAnalysisSniff implements PHP_Co /** * Checks if the given pointer is in a function call. * - * @param PHP_CodeSniffer_File $phpcsFile - * @param int $stackPtr + * @param \PHP_CodeSniffer\Files\File $phpcsFile + * @param int $stackPtr * * @return int|false */ - function findFunctionCall(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + function findFunctionCall(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -1139,12 +1144,12 @@ class DrupalPractice_Sniffs_CodeAnalysis_VariableAnalysisSniff implements PHP_Co /** * Get the arguments of a function call. * - * @param PHP_CodeSniffer_File $phpcsFile - * @param int $stackPtr + * @param \PHP_CodeSniffer\Files\File $phpcsFile + * @param int $stackPtr * * @return array|false */ - function findFunctionCallArguments(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + function findFunctionCallArguments(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -1199,15 +1204,15 @@ class DrupalPractice_Sniffs_CodeAnalysis_VariableAnalysisSniff implements PHP_Co /** * Checks the function prototype. * - * @param PHP_CodeSniffer_File $phpcsFile - * @param int $stackPtr - * @param string $varName - * @param string $currScope + * @param \PHP_CodeSniffer\Files\File $phpcsFile + * @param int $stackPtr + * @param string $varName + * @param string $currScope * * @return bool */ protected function checkForFunctionPrototype( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $varName, $currScope @@ -1320,15 +1325,15 @@ class DrupalPractice_Sniffs_CodeAnalysis_VariableAnalysisSniff implements PHP_Co /** * Checks if we are in a catch() block. * - * @param PHP_CodeSniffer_File $phpcsFile - * @param int $stackPtr - * @param string $varName - * @param string $currScope + * @param \PHP_CodeSniffer\Files\File $phpcsFile + * @param int $stackPtr + * @param string $varName + * @param string $currScope * * @return bool */ protected function checkForCatchBlock( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $varName, $currScope @@ -1375,15 +1380,15 @@ class DrupalPractice_Sniffs_CodeAnalysis_VariableAnalysisSniff implements PHP_Co /** * Checks if $this is used within a class. * - * @param PHP_CodeSniffer_File $phpcsFile - * @param int $stackPtr - * @param string $varName - * @param string $currScope + * @param \PHP_CodeSniffer\Files\File $phpcsFile + * @param int $stackPtr + * @param string $varName + * @param string $currScope * * @return bool */ protected function checkForThisWithinClass( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $varName, $currScope @@ -1410,15 +1415,15 @@ class DrupalPractice_Sniffs_CodeAnalysis_VariableAnalysisSniff implements PHP_Co /** * Checks if the variable is a PHP super global. * - * @param PHP_CodeSniffer_File $phpcsFile - * @param int $stackPtr - * @param string $varName - * @param string $currScope + * @param \PHP_CodeSniffer\Files\File $phpcsFile + * @param int $stackPtr + * @param string $varName + * @param string $currScope * * @return bool */ protected function checkForSuperGlobal( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $varName, $currScope @@ -1455,15 +1460,15 @@ class DrupalPractice_Sniffs_CodeAnalysis_VariableAnalysisSniff implements PHP_Co /** * Checks if the variable is a static class member. * - * @param PHP_CodeSniffer_File $phpcsFile - * @param int $stackPtr - * @param string $varName - * @param string $currScope + * @param \PHP_CodeSniffer\Files\File $phpcsFile + * @param int $stackPtr + * @param string $varName + * @param string $currScope * * @return bool */ protected function checkForStaticMember( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $varName, $currScope @@ -1535,15 +1540,15 @@ class DrupalPractice_Sniffs_CodeAnalysis_VariableAnalysisSniff implements PHP_Co /** * Checks if the variable is being assigned to. * - * @param PHP_CodeSniffer_File $phpcsFile - * @param int $stackPtr - * @param string $varName - * @param string $currScope + * @param \PHP_CodeSniffer\Files\File $phpcsFile + * @param int $stackPtr + * @param string $varName + * @param string $currScope * * @return bool */ protected function checkForAssignment( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $varName, $currScope @@ -1578,15 +1583,15 @@ class DrupalPractice_Sniffs_CodeAnalysis_VariableAnalysisSniff implements PHP_Co /** * Check if this is a list language construct assignment. * - * @param PHP_CodeSniffer_File $phpcsFile - * @param int $stackPtr - * @param string $varName - * @param string $currScope + * @param \PHP_CodeSniffer\Files\File $phpcsFile + * @param int $stackPtr + * @param string $varName + * @param string $currScope * * @return bool */ protected function checkForListAssignment( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $varName, $currScope @@ -1620,15 +1625,15 @@ class DrupalPractice_Sniffs_CodeAnalysis_VariableAnalysisSniff implements PHP_Co /** * Check if this variable is declared globally. * - * @param PHP_CodeSniffer_File $phpcsFile - * @param int $stackPtr - * @param string $varName - * @param string $currScope + * @param \PHP_CodeSniffer\Files\File $phpcsFile + * @param int $stackPtr + * @param string $varName + * @param string $currScope * * @return bool */ protected function checkForGlobalDeclaration( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $varName, $currScope @@ -1667,15 +1672,15 @@ class DrupalPractice_Sniffs_CodeAnalysis_VariableAnalysisSniff implements PHP_Co /** * Check is this is a static variable declaration. * - * @param PHP_CodeSniffer_File $phpcsFile - * @param int $stackPtr - * @param string $varName - * @param string $currScope + * @param \PHP_CodeSniffer\Files\File $phpcsFile + * @param int $stackPtr + * @param string $varName + * @param string $currScope * * @return bool */ protected function checkForStaticDeclaration( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $varName, $currScope @@ -1759,15 +1764,15 @@ class DrupalPractice_Sniffs_CodeAnalysis_VariableAnalysisSniff implements PHP_Co /** * Check if this is a foreach loop variable. * - * @param PHP_CodeSniffer_File $phpcsFile - * @param int $stackPtr - * @param string $varName - * @param string $currScope + * @param \PHP_CodeSniffer\Files\File $phpcsFile + * @param int $stackPtr + * @param string $varName + * @param string $currScope * * @return bool */ protected function checkForForeachLoopVar( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $varName, $currScope @@ -1809,15 +1814,15 @@ class DrupalPractice_Sniffs_CodeAnalysis_VariableAnalysisSniff implements PHP_Co /** * Check if this is a "&" function call. * - * @param PHP_CodeSniffer_File $phpcsFile - * @param int $stackPtr - * @param string $varName - * @param string $currScope + * @param \PHP_CodeSniffer\Files\File $phpcsFile + * @param int $stackPtr + * @param string $varName + * @param string $currScope * * @return bool */ protected function checkForPassByReferenceFunctionCall( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $varName, $currScope @@ -1890,15 +1895,15 @@ class DrupalPractice_Sniffs_CodeAnalysis_VariableAnalysisSniff implements PHP_Co /** * Check if the variable is an object property. * - * @param PHP_CodeSniffer_File $phpcsFile - * @param int $stackPtr - * @param string $varName - * @param string $currScope + * @param \PHP_CodeSniffer\Files\File $phpcsFile + * @param int $stackPtr + * @param string $varName + * @param string $currScope * * @return bool */ protected function checkForSymbolicObjectProperty( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $varName, $currScope @@ -1929,14 +1934,14 @@ class DrupalPractice_Sniffs_CodeAnalysis_VariableAnalysisSniff implements PHP_Co /** * Called to process class member vars. * - * @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this - * token was found. - * @param int $stackPtr The position where the token was found. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where this + * token was found. + * @param int $stackPtr The position where the token was found. * * @return void */ protected function processMemberVar( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr ) { // TODO: don't care for now. @@ -1949,14 +1954,14 @@ class DrupalPractice_Sniffs_CodeAnalysis_VariableAnalysisSniff implements PHP_Co /** * Called to process normal member vars. * - * @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this - * token was found. - * @param int $stackPtr The position where the token was found. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where this + * token was found. + * @param int $stackPtr The position where the token was found. * * @return void */ protected function processVariable( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr ) { $tokens = $phpcsFile->getTokens(); @@ -2065,15 +2070,15 @@ class DrupalPractice_Sniffs_CodeAnalysis_VariableAnalysisSniff implements PHP_Co * Note that there may be more than one variable in the string, which will * result only in one call for the string. * - * @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this - * token was found. - * @param int $stackPtr The position where the double quoted - * string was found. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where this + * token was found. + * @param int $stackPtr The position where the double quoted + * string was found. * * @return void */ protected function processVariableInString( - PHP_CodeSniffer_File + File $phpcsFile, $stackPtr ) { @@ -2106,15 +2111,15 @@ class DrupalPractice_Sniffs_CodeAnalysis_VariableAnalysisSniff implements PHP_Co /** * Check variables in a compact() call. * - * @param PHP_CodeSniffer_File $phpcsFile - * @param int $stackPtr - * @param array $arguments - * @param string $currScope + * @param \PHP_CodeSniffer\Files\File $phpcsFile + * @param int $stackPtr + * @param array $arguments + * @param string $currScope * * @return void */ protected function processCompactArguments( - PHP_CodeSniffer_File + File $phpcsFile, $stackPtr, $arguments, @@ -2182,15 +2187,15 @@ class DrupalPractice_Sniffs_CodeAnalysis_VariableAnalysisSniff implements PHP_Co /** * Called to process variables named in a call to compact(). * - * @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this - * token was found. - * @param int $stackPtr The position where the call to compact() - * was found. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where this + * token was found. + * @param int $stackPtr The position where the call to compact() + * was found. * * @return void */ protected function processCompact( - PHP_CodeSniffer_File + File $phpcsFile, $stackPtr ) { @@ -2212,14 +2217,14 @@ class DrupalPractice_Sniffs_CodeAnalysis_VariableAnalysisSniff implements PHP_Co * Note that although triggered by the closing curly brace of the scope, $stackPtr is * the scope conditional, not the closing curly brace. * - * @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this - * token was found. - * @param int $stackPtr The position of the scope conditional. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where this + * token was found. + * @param int $stackPtr The position of the scope conditional. * * @return void */ protected function processScopeClose( - PHP_CodeSniffer_File + File $phpcsFile, $stackPtr ) { diff --git a/coder_sniffer/DrupalPractice/Sniffs/Commenting/AuthorTagSniff.php b/coder_sniffer/DrupalPractice/Sniffs/Commenting/AuthorTagSniff.php index f9c7dc13..df78d6df 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/Commenting/AuthorTagSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/Commenting/AuthorTagSniff.php @@ -1,12 +1,17 @@ <?php /** - * DrupalPractice_Sniffs_Commenting_AuthorTagSniff. + * \DrupalPractice\Sniffs\Commenting\AuthorTagSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace DrupalPractice\Sniffs\Commenting; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** * Checks the usage of @author tags. * @@ -14,7 +19,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class DrupalPractice_Sniffs_Commenting_AuthorTagSniff implements PHP_CodeSniffer_Sniff +class AuthorTagSniff implements Sniff { @@ -33,13 +38,13 @@ class DrupalPractice_Sniffs_Commenting_AuthorTagSniff implements PHP_CodeSniffer /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); diff --git a/coder_sniffer/DrupalPractice/Sniffs/Commenting/CommentEmptyLineSniff.php b/coder_sniffer/DrupalPractice/Sniffs/Commenting/CommentEmptyLineSniff.php index 1ffd149b..0cb4e96e 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/Commenting/CommentEmptyLineSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/Commenting/CommentEmptyLineSniff.php @@ -1,13 +1,18 @@ <?php /** - * DrupalPractice_Sniffs_Commenting_CommentEmptyLineSniff + * \DrupalPractice\Sniffs\Commenting\CommentEmptyLineSniff * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace DrupalPractice\Sniffs\Commenting; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** * Throws a warning if there is a blank line after an inline comment. * @@ -15,7 +20,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class DrupalPractice_Sniffs_Commenting_CommentEmptyLineSniff implements PHP_CodeSniffer_Sniff +class CommentEmptyLineSniff implements Sniff { @@ -34,13 +39,13 @@ class DrupalPractice_Sniffs_Commenting_CommentEmptyLineSniff implements PHP_Code /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); diff --git a/coder_sniffer/DrupalPractice/Sniffs/Commenting/ExpectedExceptionSniff.php b/coder_sniffer/DrupalPractice/Sniffs/Commenting/ExpectedExceptionSniff.php index abf6f3a2..e1a85e10 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/Commenting/ExpectedExceptionSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/Commenting/ExpectedExceptionSniff.php @@ -1,12 +1,17 @@ <?php /** - * DrupalPractice_Sniffs_Commenting_ExpectedExceptionSniff. + * \DrupalPractice\Sniffs\Commenting\ExpectedExceptionSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace DrupalPractice\Sniffs\Commenting; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** * Checks that the PHPunit @expectedExcpetion tags are not used. * @@ -16,7 +21,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class DrupalPractice_Sniffs_Commenting_ExpectedExceptionSniff implements PHP_CodeSniffer_Sniff +class ExpectedExceptionSniff implements Sniff { @@ -35,13 +40,13 @@ class DrupalPractice_Sniffs_Commenting_ExpectedExceptionSniff implements PHP_Cod /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); diff --git a/coder_sniffer/DrupalPractice/Sniffs/Constants/GlobalConstantSniff.php b/coder_sniffer/DrupalPractice/Sniffs/Constants/GlobalConstantSniff.php index b0284dc4..9e40e495 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/Constants/GlobalConstantSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/Constants/GlobalConstantSniff.php @@ -1,12 +1,18 @@ <?php /** - * DrupalPractice_Sniffs_Constants_GlobalConstantSniff + * \DrupalPractice\Sniffs\Constants\GlobalConstantSniff * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace DrupalPractice\Sniffs\Constants; + +use DrupalPractice\Project; +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** * Checks that globally defined constants are not used in Drupal 8 and higher. * @@ -14,7 +20,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class DrupalPractice_Sniffs_Constants_GlobalConstantSniff implements PHP_CodeSniffer_Sniff +class GlobalConstantSniff implements Sniff { @@ -33,13 +39,13 @@ class DrupalPractice_Sniffs_Constants_GlobalConstantSniff implements PHP_CodeSni /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The current file being processed. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The current file being processed. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -48,7 +54,7 @@ class DrupalPractice_Sniffs_Constants_GlobalConstantSniff implements PHP_CodeSni return; } - $coreVersion = DrupalPractice_Project::getCoreVersion($phpcsFile); + $coreVersion = Project::getCoreVersion($phpcsFile); if ($coreVersion !== '8.x') { return; } diff --git a/coder_sniffer/DrupalPractice/Sniffs/Constants/GlobalDefineSniff.php b/coder_sniffer/DrupalPractice/Sniffs/Constants/GlobalDefineSniff.php index ef7cf7e7..20fb979b 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/Constants/GlobalDefineSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/Constants/GlobalDefineSniff.php @@ -1,12 +1,18 @@ <?php /** - * DrupalPractice_Sniffs_Constants_GlobalDefineSniff + * \DrupalPractice\Sniffs\Constants\GlobalDefineSniff * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace DrupalPractice\Sniffs\Constants; + +use PHP_CodeSniffer\Files\File; +use Drupal\Sniffs\Semantics\FunctionCall; +use DrupalPractice\Project; + /** * Checks that global define() constants are not used in modules in Drupal 8. * @@ -14,7 +20,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class DrupalPractice_Sniffs_Constants_GlobalDefineSniff extends Drupal_Sniffs_Semantics_FunctionCall +class GlobalDefineSniff extends FunctionCall { @@ -33,18 +39,18 @@ class DrupalPractice_Sniffs_Constants_GlobalDefineSniff extends Drupal_Sniffs_Se /** * Processes this function call. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the function call in - * the stack. - * @param int $openBracket The position of the opening - * parenthesis in the stack. - * @param int $closeBracket The position of the closing - * parenthesis in the stack. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the function call in + * the stack. + * @param int $openBracket The position of the opening + * parenthesis in the stack. + * @param int $closeBracket The position of the closing + * parenthesis in the stack. * * @return void */ public function processFunctionCall( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $openBracket, $closeBracket @@ -56,7 +62,7 @@ class DrupalPractice_Sniffs_Constants_GlobalDefineSniff extends Drupal_Sniffs_Se return; } - $coreVersion = DrupalPractice_Project::getCoreVersion($phpcsFile); + $coreVersion = Project::getCoreVersion($phpcsFile); if ($coreVersion !== '8.x') { return; } diff --git a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/CheckPlainSniff.php b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/CheckPlainSniff.php index 64eeb0bb..438a3833 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/CheckPlainSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/CheckPlainSniff.php @@ -1,12 +1,17 @@ <?php /** - * Drupal_Sniffs_FunctionCalls_CheckPlainSniff + * \DrupalPractice\Sniffs\FunctionCalls\CheckPlainSniff * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace DrupalPractice\Sniffs\FunctionCalls; + +use PHP_CodeSniffer\Files\File; +use Drupal\Sniffs\Semantics\FunctionCall; + /** * Check that check_plain() is not used on literal strings. * @@ -14,7 +19,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class DrupalPractice_Sniffs_FunctionCalls_CheckPlainSniff extends Drupal_Sniffs_Semantics_FunctionCall +class CheckPlainSniff extends FunctionCall { @@ -33,18 +38,18 @@ class DrupalPractice_Sniffs_FunctionCalls_CheckPlainSniff extends Drupal_Sniffs_ /** * Processes this function call. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the function call in - * the stack. - * @param int $openBracket The position of the opening - * parenthesis in the stack. - * @param int $closeBracket The position of the closing - * parenthesis in the stack. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the function call in + * the stack. + * @param int $openBracket The position of the opening + * parenthesis in the stack. + * @param int $closeBracket The position of the closing + * parenthesis in the stack. * * @return void */ public function processFunctionCall( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $openBracket, $closeBracket diff --git a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/CurlSslVerifierSniff.php b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/CurlSslVerifierSniff.php index da4d764f..14bc814f 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/CurlSslVerifierSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/CurlSslVerifierSniff.php @@ -1,12 +1,17 @@ <?php /** - * Drupal_Sniffs_FunctionCalls_CurlSslVerifierSniff + * \DrupalPractice\Sniffs\FunctionCalls\CurlSslVerifierSniff * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace DrupalPractice\Sniffs\FunctionCalls; + +use PHP_CodeSniffer\Files\File; +use Drupal\Sniffs\Semantics\FunctionCall; + /** * Make sure that CURLOPT_SSL_VERIFYPEER is not disabled, since that is a * security issue. @@ -15,7 +20,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class DrupalPractice_Sniffs_FunctionCalls_CurlSslVerifierSniff extends Drupal_Sniffs_Semantics_FunctionCall +class CurlSslVerifierSniff extends FunctionCall { @@ -34,18 +39,18 @@ class DrupalPractice_Sniffs_FunctionCalls_CurlSslVerifierSniff extends Drupal_Sn /** * Processes this function call. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the function call in - * the stack. - * @param int $openBracket The position of the opening - * parenthesis in the stack. - * @param int $closeBracket The position of the closing - * parenthesis in the stack. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the function call in + * the stack. + * @param int $openBracket The position of the opening + * parenthesis in the stack. + * @param int $closeBracket The position of the closing + * parenthesis in the stack. * * @return void */ public function processFunctionCall( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $openBracket, $closeBracket diff --git a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/DbQuerySniff.php b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/DbQuerySniff.php index c571f4ef..e08a5291 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/DbQuerySniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/DbQuerySniff.php @@ -1,12 +1,18 @@ <?php /** - * Drupal_Sniffs_FunctionCalls_DbQuerySniff + * \DrupalPractice\Sniffs\FunctionCalls\DbQuerySniff * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace DrupalPractice\Sniffs\FunctionCalls; + +use PHP_CodeSniffer\Files\File; +use Drupal\Sniffs\Semantics\FunctionCall; +use DrupalPractice\Project; + /** * Check that UPDATE/DELETE queries are not used in db_query() in Drupal 7. * @@ -14,7 +20,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class DrupalPractice_Sniffs_FunctionCalls_DbQuerySniff extends Drupal_Sniffs_Semantics_FunctionCall +class DbQuerySniff extends FunctionCall { @@ -33,24 +39,24 @@ class DrupalPractice_Sniffs_FunctionCalls_DbQuerySniff extends Drupal_Sniffs_Sem /** * Processes this function call. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the function call in - * the stack. - * @param int $openBracket The position of the opening - * parenthesis in the stack. - * @param int $closeBracket The position of the closing - * parenthesis in the stack. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the function call in + * the stack. + * @param int $openBracket The position of the opening + * parenthesis in the stack. + * @param int $closeBracket The position of the closing + * parenthesis in the stack. * * @return void */ public function processFunctionCall( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $openBracket, $closeBracket ) { // This check only applies to Drupal 7, not Drupal 6. - if (DrupalPractice_Project::getCoreVersion($phpcsFile) !== '7.x') { + if (Project::getCoreVersion($phpcsFile) !== '7.x') { return; } diff --git a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/DbSelectBracesSniff.php b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/DbSelectBracesSniff.php index 50832688..fe9704d0 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/DbSelectBracesSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/DbSelectBracesSniff.php @@ -1,12 +1,17 @@ <?php /** - * Drupal_Sniffs_FunctionCalls_DbSelectBracesSniff + * \DrupalPractice\Sniffs\FunctionCalls\DbSelectBracesSniff * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace DrupalPractice\Sniffs\FunctionCalls; + +use PHP_CodeSniffer\Files\File; +use Drupal\Sniffs\Semantics\FunctionCall; + /** * Check that db_select() calls do not use {} braces for the table name. * @@ -14,7 +19,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class DrupalPractice_Sniffs_FunctionCalls_DbSelectBracesSniff extends Drupal_Sniffs_Semantics_FunctionCall +class DbSelectBracesSniff extends FunctionCall { @@ -33,18 +38,18 @@ class DrupalPractice_Sniffs_FunctionCalls_DbSelectBracesSniff extends Drupal_Sni /** * Processes this function call. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the function call in - * the stack. - * @param int $openBracket The position of the opening - * parenthesis in the stack. - * @param int $closeBracket The position of the closing - * parenthesis in the stack. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the function call in + * the stack. + * @param int $openBracket The position of the opening + * parenthesis in the stack. + * @param int $closeBracket The position of the closing + * parenthesis in the stack. * * @return void */ public function processFunctionCall( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $openBracket, $closeBracket diff --git a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/DefaultValueSanitizeSniff.php b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/DefaultValueSanitizeSniff.php index 921df640..227c1860 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/DefaultValueSanitizeSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/DefaultValueSanitizeSniff.php @@ -1,12 +1,18 @@ <?php /** - * DrupalPractice_Sniffs_FunctionCalls_DefaultValueSanitizeSniff + * \DrupalPractice\Sniffs\FunctionCalls\DefaultValueSanitizeSniff * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace DrupalPractice\Sniffs\FunctionCalls; + +use PHP_CodeSniffer\Files\File; +use Drupal\Sniffs\Semantics\FunctionCall; +use PHP_CodeSniffer\Util\Tokens; + /** * Check that sanitization functions such as check_plain() are not used on Form * API #default_value elements. @@ -15,7 +21,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class DrupalPractice_Sniffs_FunctionCalls_DefaultValueSanitizeSniff extends Drupal_Sniffs_Semantics_FunctionCall +class DefaultValueSanitizeSniff extends FunctionCall { @@ -40,18 +46,18 @@ class DrupalPractice_Sniffs_FunctionCalls_DefaultValueSanitizeSniff extends Drup /** * Processes this function call. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the function call in - * the stack. - * @param int $openBracket The position of the opening - * parenthesis in the stack. - * @param int $closeBracket The position of the closing - * parenthesis in the stack. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the function call in + * the stack. + * @param int $openBracket The position of the opening + * parenthesis in the stack. + * @param int $closeBracket The position of the closing + * parenthesis in the stack. * * @return void */ public function processFunctionCall( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $openBracket, $closeBracket @@ -60,12 +66,12 @@ class DrupalPractice_Sniffs_FunctionCalls_DefaultValueSanitizeSniff extends Drup // We assume that the sequence '#default_value' => check_plain(...) is // wrong because the Form API already sanitizes #default_value. - $arrow = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true); + $arrow = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); if ($arrow === false || $tokens[$arrow]['code'] !== T_DOUBLE_ARROW) { return; } - $arrayKey = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($arrow - 1), null, true); + $arrayKey = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($arrow - 1), null, true); if ($arrayKey === false || $tokens[$arrayKey]['code'] !== T_CONSTANT_ENCAPSED_STRING || substr($tokens[$arrayKey]['content'], 1, -1) !== '#default_value' diff --git a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/FormErrorTSniff.php b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/FormErrorTSniff.php index 5ad2830d..b0bacc3b 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/FormErrorTSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/FormErrorTSniff.php @@ -1,12 +1,17 @@ <?php /** - * DrupalPractice_Sniffs_FunctionCalls_FormErrorTSniff + * \DrupalPractice\Sniffs\FunctionCalls\FormErrorTSniff * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace DrupalPractice\Sniffs\FunctionCalls; + +use PHP_CodeSniffer\Files\File; +use Drupal\Sniffs\Semantics\FunctionCall; + /** * Verifiies that messages passed to form_set_error() run through t(). * @@ -14,7 +19,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class DrupalPractice_Sniffs_FunctionCalls_FormErrorTSniff extends Drupal_Sniffs_Semantics_FunctionCall +class FormErrorTSniff extends FunctionCall { @@ -36,18 +41,18 @@ class DrupalPractice_Sniffs_FunctionCalls_FormErrorTSniff extends Drupal_Sniffs_ /** * Processes this function call. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the function call in - * the stack. - * @param int $openBracket The position of the opening - * parenthesis in the stack. - * @param int $closeBracket The position of the closing - * parenthesis in the stack. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the function call in + * the stack. + * @param int $openBracket The position of the opening + * parenthesis in the stack. + * @param int $closeBracket The position of the closing + * parenthesis in the stack. * * @return void */ public function processFunctionCall( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $openBracket, $closeBracket diff --git a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/LCheckPlainSniff.php b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/LCheckPlainSniff.php index 397a150b..815fc436 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/LCheckPlainSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/LCheckPlainSniff.php @@ -1,12 +1,17 @@ <?php /** - * Drupal_Sniffs_FunctionCalls_LCheckPlainSniff + * \DrupalPractice\Sniffs\FunctionCalls\Drupal_Sniffs_FunctionCalls_LCheckPlainSniff * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace DrupalPractice\Sniffs\FunctionCalls; + +use PHP_CodeSniffer\Files\File; +use Drupal\Sniffs\Semantics\FunctionCall; + /** * The first argument of the l() function should not be check_plain()'ed. * @@ -14,7 +19,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class DrupalPractice_Sniffs_FunctionCalls_LCheckPlainSniff extends Drupal_Sniffs_Semantics_FunctionCall +class LCheckPlainSniff extends FunctionCall { @@ -33,18 +38,18 @@ class DrupalPractice_Sniffs_FunctionCalls_LCheckPlainSniff extends Drupal_Sniffs /** * Processes this function call. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the function call in - * the stack. - * @param int $openBracket The position of the opening - * parenthesis in the stack. - * @param int $closeBracket The position of the closing - * parenthesis in the stack. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the function call in + * the stack. + * @param int $openBracket The position of the opening + * parenthesis in the stack. + * @param int $closeBracket The position of the closing + * parenthesis in the stack. * * @return void */ public function processFunctionCall( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $openBracket, $closeBracket diff --git a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/MessageTSniff.php b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/MessageTSniff.php index 300eded0..bf4ac9e6 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/MessageTSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/MessageTSniff.php @@ -1,12 +1,17 @@ <?php /** - * DrupalPractice_Sniffs_FunctionCalls_MessageTSniff + * \DrupalPractice\Sniffs\FunctionCalls\MessageTSniff * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace DrupalPractice\Sniffs\FunctionCalls; + +use PHP_CodeSniffer\Files\File; +use Drupal\Sniffs\Semantics\FunctionCall; + /** * Verifies that messages passed to drupal_set_message() run through t(). * @@ -14,7 +19,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class DrupalPractice_Sniffs_FunctionCalls_MessageTSniff extends Drupal_Sniffs_Semantics_FunctionCall +class MessageTSniff extends FunctionCall { @@ -33,18 +38,18 @@ class DrupalPractice_Sniffs_FunctionCalls_MessageTSniff extends Drupal_Sniffs_Se /** * Processes this function call. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the function call in - * the stack. - * @param int $openBracket The position of the opening - * parenthesis in the stack. - * @param int $closeBracket The position of the closing - * parenthesis in the stack. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the function call in + * the stack. + * @param int $openBracket The position of the opening + * parenthesis in the stack. + * @param int $closeBracket The position of the closing + * parenthesis in the stack. * * @return void */ public function processFunctionCall( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $openBracket, $closeBracket diff --git a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/TCheckPlainSniff.php b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/TCheckPlainSniff.php index 30831c4f..8e7e37bb 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/TCheckPlainSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/TCheckPlainSniff.php @@ -1,12 +1,17 @@ <?php /** - * Drupal_Sniffs_Semantics_FunctionTSniff + * \DrupalPractice\Sniffs\FunctionCalls\TCheckPlainSniff * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace DrupalPractice\Sniffs\FunctionCalls; + +use PHP_CodeSniffer\Files\File; +use Drupal\Sniffs\Semantics\FunctionCall; + /** * Check that "@" and "%" placeholders in t()/watchdog() are not escaped twice * with check_plain(). @@ -15,7 +20,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class DrupalPractice_Sniffs_FunctionCalls_TCheckPlainSniff extends Drupal_Sniffs_Semantics_FunctionCall +class TCheckPlainSniff extends FunctionCall { @@ -37,18 +42,18 @@ class DrupalPractice_Sniffs_FunctionCalls_TCheckPlainSniff extends Drupal_Sniffs /** * Processes this function call. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the function call in - * the stack. - * @param int $openBracket The position of the opening - * parenthesis in the stack. - * @param int $closeBracket The position of the closing - * parenthesis in the stack. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the function call in + * the stack. + * @param int $openBracket The position of the opening + * parenthesis in the stack. + * @param int $closeBracket The position of the closing + * parenthesis in the stack. * * @return void */ public function processFunctionCall( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $openBracket, $closeBracket diff --git a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/ThemeSniff.php b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/ThemeSniff.php index deea2e13..1339c4ab 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/ThemeSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/ThemeSniff.php @@ -1,20 +1,25 @@ <?php /** - * DrupalPractice_Sniffs_FunctionCalls_ThemeSniff + * ThemeSniff * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace DrupalPractice\Sniffs\FunctionCalls; + +use PHP_CodeSniffer\Files\File; +use Drupal\Sniffs\Semantics\FunctionCall; + /** - * Checks that theme functions are not directly called. + * \DrupalPractice\Sniffs\FunctionCalls\Checks that theme functions are not directly called. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class DrupalPractice_Sniffs_FunctionCalls_ThemeSniff extends Drupal_Sniffs_Semantics_FunctionCall +class ThemeSniff extends FunctionCall { /** @@ -35,13 +40,13 @@ class DrupalPractice_Sniffs_FunctionCalls_ThemeSniff extends Drupal_Sniffs_Seman /** * Processes this function call. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the function call in - * the stack. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the function call in + * the stack. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $functionName = $tokens[$stackPtr]['content']; diff --git a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/VariableSetSanitizeSniff.php b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/VariableSetSanitizeSniff.php index e1723146..60937a23 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/VariableSetSanitizeSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/VariableSetSanitizeSniff.php @@ -1,12 +1,17 @@ <?php /** - * DrupalPractice_Sniffs_FunctionCalls_VariableSetSanitizeSniff + * \DrupalPractice\Sniffs\FunctionCalls\VariableSetSanitizeSniff * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace DrupalPractice\Sniffs\FunctionCalls; + +use PHP_CodeSniffer\Files\File; +use Drupal\Sniffs\Semantics\FunctionCall; + /** * Check that variable_set() calls do not run check_plain() or other * sanitization functions on the value. @@ -15,7 +20,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class DrupalPractice_Sniffs_FunctionCalls_VariableSetSanitizeSniff extends Drupal_Sniffs_Semantics_FunctionCall +class VariableSetSanitizeSniff extends FunctionCall { @@ -34,18 +39,18 @@ class DrupalPractice_Sniffs_FunctionCalls_VariableSetSanitizeSniff extends Drupa /** * Processes this function call. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the function call in - * the stack. - * @param int $openBracket The position of the opening - * parenthesis in the stack. - * @param int $closeBracket The position of the closing - * parenthesis in the stack. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the function call in + * the stack. + * @param int $openBracket The position of the opening + * parenthesis in the stack. + * @param int $closeBracket The position of the closing + * parenthesis in the stack. * * @return void */ public function processFunctionCall( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $openBracket, $closeBracket diff --git a/coder_sniffer/DrupalPractice/Sniffs/FunctionDefinitions/AccessHookMenuSniff.php b/coder_sniffer/DrupalPractice/Sniffs/FunctionDefinitions/AccessHookMenuSniff.php index d75975fa..c4cedb29 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/FunctionDefinitions/AccessHookMenuSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/FunctionDefinitions/AccessHookMenuSniff.php @@ -1,12 +1,18 @@ <?php /** - * DrupalPractice_Sniffs_FunctionDefinitions_AccessHookMenuSniff. + * \DrupalPractice\Sniffs\FunctionDefinitions\AccessHookMenuSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace DrupalPractice\Sniffs\FunctionDefinitions; + +use PHP_CodeSniffer\Files\File; +use Drupal\Sniffs\Semantics\FunctionDefinition; +use PHP_CodeSniffer\Util\Tokens; + /** * Checks that there are no undocumented open access callbacks in hook_menu(). * @@ -14,22 +20,22 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class DrupalPractice_Sniffs_FunctionDefinitions_AccessHookMenuSniff extends Drupal_Sniffs_Semantics_FunctionDefinition +class AccessHookMenuSniff extends FunctionDefinition { /** * Process this function definition. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the function name - * in the stack. - * @param int $functionPtr The position of the function keyword - * in the stack. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the function name + * in the stack. + * @param int $functionPtr The position of the function keyword + * in the stack. * * @return void */ - public function processFunction(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $functionPtr) + public function processFunction(File $phpcsFile, $stackPtr, $functionPtr) { $fileExtension = strtolower(substr($phpcsFile->getFilename(), -6)); // Only check in *.module files. @@ -52,7 +58,7 @@ class DrupalPractice_Sniffs_FunctionDefinitions_AccessHookMenuSniff extends Drup while ($string !== false) { if (substr($tokens[$string]['content'], 1, -1) === 'access callback') { $array_operator = $phpcsFile->findNext( - PHP_CodeSniffer_Tokens::$emptyTokens, + Tokens::$emptyTokens, ($string + 1), null, true @@ -61,7 +67,7 @@ class DrupalPractice_Sniffs_FunctionDefinitions_AccessHookMenuSniff extends Drup && $tokens[$array_operator]['code'] === T_DOUBLE_ARROW ) { $callback = $phpcsFile->findNext( - PHP_CodeSniffer_Tokens::$emptyTokens, + Tokens::$emptyTokens, ($array_operator + 1), null, true @@ -75,7 +81,7 @@ class DrupalPractice_Sniffs_FunctionDefinitions_AccessHookMenuSniff extends Drup $tokens[$functionPtr]['scope_opener'], true ); - if ($commentBefore !== false && in_array($tokens[$commentBefore]['code'], PHP_CodeSniffer_Tokens::$commentTokens) === false) { + if ($commentBefore !== false && in_array($tokens[$commentBefore]['code'], Tokens::$commentTokens) === false) { $warning = 'Open page callback found, please add a comment before the line why there is no access restriction'; $phpcsFile->addWarning($warning, $callback, 'OpenCallback'); } diff --git a/coder_sniffer/DrupalPractice/Sniffs/FunctionDefinitions/FormAlterDocSniff.php b/coder_sniffer/DrupalPractice/Sniffs/FunctionDefinitions/FormAlterDocSniff.php index 7e518851..746c57d5 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/FunctionDefinitions/FormAlterDocSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/FunctionDefinitions/FormAlterDocSniff.php @@ -1,12 +1,18 @@ <?php /** - * DrupalPractice_Sniffs_FunctionDefinitions_FormAlterDocSniff. + * \DrupalPractice\Sniffs\FunctionDefinitions\FormAlterDocSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace DrupalPractice\Sniffs\FunctionDefinitions; + +use PHP_CodeSniffer\Files\File; +use Drupal\Sniffs\Semantics\FunctionDefinition; +use DrupalPractice\Project; + /** * Checks that the comment "Implements hook_form_alter()." actually matches the * function signature. @@ -15,22 +21,22 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class DrupalPractice_Sniffs_FunctionDefinitions_FormAlterDocSniff extends Drupal_Sniffs_Semantics_FunctionDefinition +class FormAlterDocSniff extends FunctionDefinition { /** * Process this function definition. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the function name - * in the stack. - * @param int $functionPtr The position of the function keyword - * in the stack. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the function name + * in the stack. + * @param int $functionPtr The position of the function keyword + * in the stack. * * @return void */ - public function processFunction(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $functionPtr) + public function processFunction(File $phpcsFile, $stackPtr, $functionPtr) { $tokens = $phpcsFile->getTokens(); $docCommentEnd = $phpcsFile->findPrevious(T_WHITESPACE, ($functionPtr - 1), null, true); @@ -55,7 +61,7 @@ class DrupalPractice_Sniffs_FunctionDefinitions_FormAlterDocSniff extends Drupal return; } - $projectName = DrupalPractice_Project::getName($phpcsFile); + $projectName = Project::getName($phpcsFile); if ($projectName === false) { return; } diff --git a/coder_sniffer/DrupalPractice/Sniffs/FunctionDefinitions/HookInitCssSniff.php b/coder_sniffer/DrupalPractice/Sniffs/FunctionDefinitions/HookInitCssSniff.php index f983713a..51347fb8 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/FunctionDefinitions/HookInitCssSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/FunctionDefinitions/HookInitCssSniff.php @@ -1,12 +1,19 @@ <?php /** - * DrupalPractice_Sniffs_FunctionDefinitions_HookInitCssSniff. + * \DrupalPractice\Sniffs\FunctionDefinitions\HookInitCssSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace DrupalPractice\Sniffs\FunctionDefinitions; + +use PHP_CodeSniffer\Files\File; +use Drupal\Sniffs\Semantics\FunctionDefinition; +use DrupalPractice\Project; +use PHP_CodeSniffer\Util\Tokens; + /** * Checks that drupal_add_css() is not used in hook_init(). * @@ -14,22 +21,22 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class DrupalPractice_Sniffs_FunctionDefinitions_HookInitCssSniff extends Drupal_Sniffs_Semantics_FunctionDefinition +class HookInitCssSniff extends FunctionDefinition { /** * Process this function definition. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the function name in the stack. - * name in the stack. - * @param int $functionPtr The position of the function keyword in the stack. - * keyword in the stack. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the function name + * in the stack. + * @param int $functionPtr The position of the function keyword + * in the stack. * * @return void */ - public function processFunction(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $functionPtr) + public function processFunction(File $phpcsFile, $stackPtr, $functionPtr) { $fileExtension = strtolower(substr($phpcsFile->getFilename(), -6)); // Only check in *.module files. @@ -38,7 +45,7 @@ class DrupalPractice_Sniffs_FunctionDefinitions_HookInitCssSniff extends Drupal_ } // This check only applies to Drupal 7, not Drupal 6. - if (DrupalPractice_Project::getCoreVersion($phpcsFile) !== '7.x') { + if (Project::getCoreVersion($phpcsFile) !== '7.x') { return; } @@ -57,7 +64,7 @@ class DrupalPractice_Sniffs_FunctionDefinitions_HookInitCssSniff extends Drupal_ while ($string !== false) { if ($tokens[$string]['content'] === 'drupal_add_css' || $tokens[$string]['content'] === 'drupal_add_js') { $opener = $phpcsFile->findNext( - PHP_CodeSniffer_Tokens::$emptyTokens, + Tokens::$emptyTokens, ($string + 1), null, true diff --git a/coder_sniffer/DrupalPractice/Sniffs/FunctionDefinitions/InstallTSniff.php b/coder_sniffer/DrupalPractice/Sniffs/FunctionDefinitions/InstallTSniff.php index 94bcaf61..603a9d0b 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/FunctionDefinitions/InstallTSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/FunctionDefinitions/InstallTSniff.php @@ -1,12 +1,19 @@ <?php /** - * DrupalPractice_Sniffs_FunctionCalls_InstallTSniff. + * \DrupalPractice\Sniffs\FunctionDefinitions\InstallTSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace DrupalPractice\Sniffs\FunctionDefinitions; + +use PHP_CodeSniffer\Files\File; +use Drupal\Sniffs\Semantics\FunctionDefinition; +use DrupalPractice\Project; +use PHP_CodeSniffer\Util\Tokens; + /** * Checks that t() and st() are not used in hook_install() and hook_requirements(). * @@ -14,22 +21,22 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class DrupalPractice_Sniffs_FunctionDefinitions_InstallTSniff extends Drupal_Sniffs_Semantics_FunctionDefinition +class InstallTSniff extends FunctionDefinition { /** * Process this function definition. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the function name in the stack. - * name in the stack. - * @param int $functionPtr The position of the function keyword in the stack. - * keyword in the stack. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the function name + * in the stack. + * @param int $functionPtr The position of the function keyword + * in the stack. * * @return void */ - public function processFunction(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $functionPtr) + public function processFunction(File $phpcsFile, $stackPtr, $functionPtr) { $fileExtension = strtolower(substr($phpcsFile->getFilename(), -7)); // Only check in *.install files. @@ -46,7 +53,7 @@ class DrupalPractice_Sniffs_FunctionDefinitions_InstallTSniff extends Drupal_Sni } // This check only applies to Drupal 7, not Drupal 8. - if (DrupalPractice_Project::getCoreVersion($phpcsFile) !== '7.x') { + if (Project::getCoreVersion($phpcsFile) !== '7.x') { return; } @@ -59,7 +66,7 @@ class DrupalPractice_Sniffs_FunctionDefinitions_InstallTSniff extends Drupal_Sni while ($string !== false) { if ($tokens[$string]['content'] === 't' || $tokens[$string]['content'] === 'st') { $opener = $phpcsFile->findNext( - PHP_CodeSniffer_Tokens::$emptyTokens, + Tokens::$emptyTokens, ($string + 1), null, true diff --git a/coder_sniffer/DrupalPractice/Sniffs/General/AccessAdminPagesSniff.php b/coder_sniffer/DrupalPractice/Sniffs/General/AccessAdminPagesSniff.php index d279304e..c2629d5c 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/General/AccessAdminPagesSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/General/AccessAdminPagesSniff.php @@ -1,12 +1,17 @@ <?php /** - * DrupalPractice_Sniffs_General_AccessAdminPagesSniff + * \DrupalPractice\Sniffs\General\AccessAdminPagesSniff * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace DrupalPractice\Sniffs\General; + +use PHP_CodeSniffer\Files\File; +use Drupal\Sniffs\Semantics\FunctionDefinition; + /** * Throws a warning if the "access administration pages" string is found in * hook_menu(). @@ -15,22 +20,22 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class DrupalPractice_Sniffs_General_AccessAdminPagesSniff extends Drupal_Sniffs_Semantics_FunctionDefinition +class AccessAdminPagesSniff extends FunctionDefinition { /** * Process this function definition. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the function name in the stack. - * name in the stack. - * @param int $functionPtr The position of the function keyword in the stack. - * keyword in the stack. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the function + * name in the stack. + * @param int $functionPtr The position of the function + * keyword in the stack. * * @return void */ - public function processFunction(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $functionPtr) + public function processFunction(File $phpcsFile, $stackPtr, $functionPtr) { $fileExtension = strtolower(substr($phpcsFile->getFilename(), -6)); // Only check in *.module files. diff --git a/coder_sniffer/DrupalPractice/Sniffs/General/ClassNameSniff.php b/coder_sniffer/DrupalPractice/Sniffs/General/ClassNameSniff.php index b2ea1555..51b45c80 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/General/ClassNameSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/General/ClassNameSniff.php @@ -1,12 +1,18 @@ <?php /** - * DrupalPractice_Sniffs_General_ClassNameSniff + * \DrupalPractice\Sniffs\General\ClassNameSniff * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace DrupalPractice\Sniffs\General; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; +use DrupalPractice\Project; + /** * Checks that classes without namespaces are properly prefixed with the module * name. @@ -15,7 +21,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class DrupalPractice_Sniffs_General_ClassNameSniff implements PHP_CodeSniffer_Sniff +class ClassNameSniff implements Sniff { @@ -37,13 +43,13 @@ class DrupalPractice_Sniffs_General_ClassNameSniff implements PHP_CodeSniffer_Sn /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The current file being processed. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the function + * name in the stack. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { // If there is a PHP 5.3 namespace declaration in the file we return // immediately as classes can be named arbitrary within a namespace. @@ -52,7 +58,7 @@ class DrupalPractice_Sniffs_General_ClassNameSniff implements PHP_CodeSniffer_Sn return; } - $moduleName = DrupalPractice_Project::getName($phpcsFile); + $moduleName = Project::getName($phpcsFile); if ($moduleName === false) { return; } diff --git a/coder_sniffer/DrupalPractice/Sniffs/General/DescriptionTSniff.php b/coder_sniffer/DrupalPractice/Sniffs/General/DescriptionTSniff.php index 79244a9b..3ba9d105 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/General/DescriptionTSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/General/DescriptionTSniff.php @@ -1,12 +1,17 @@ <?php /** - * DrupalPractice_Sniffs_General_DescriptionTSniff + * \DrupalPractice\Sniffs\General\DescriptionTSniff * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace DrupalPractice\Sniffs\General; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** * Checks that string values for #description in render arrays are translated. * @@ -14,7 +19,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class DrupalPractice_Sniffs_General_DescriptionTSniff implements PHP_CodeSniffer_Sniff +class DescriptionTSniff implements Sniff { @@ -33,13 +38,13 @@ class DrupalPractice_Sniffs_General_DescriptionTSniff implements PHP_CodeSniffer /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The current file being processed. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the function + * name in the stack. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { // Look for the string "#description". $tokens = $phpcsFile->getTokens(); @@ -64,7 +69,7 @@ class DrupalPractice_Sniffs_General_DescriptionTSniff implements PHP_CodeSniffer if (strlen($content) > 5) { $warning = '#description values usually have to run through t() for translation'; - $phpcsFile->addWarning($warning, $stringToken); + $phpcsFile->addWarning($warning, $stringToken, 'DescriptionT'); } }//end process() diff --git a/coder_sniffer/DrupalPractice/Sniffs/General/FormStateInputSniff.php b/coder_sniffer/DrupalPractice/Sniffs/General/FormStateInputSniff.php index 97648a66..86fdec86 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/General/FormStateInputSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/General/FormStateInputSniff.php @@ -1,12 +1,17 @@ <?php /** - * DrupalPractice_Sniffs_General_FormStateInputSniff. + * \DrupalPractice\Sniffs\General\FormStateInputSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace DrupalPractice\Sniffs\General; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** * Throws a message whenever $form_state['input'] is used. $form_state['values'] * is preferred. @@ -15,7 +20,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class DrupalPractice_Sniffs_General_FormStateInputSniff implements PHP_CodeSniffer_Sniff +class FormStateInputSniff implements Sniff { @@ -34,13 +39,13 @@ class DrupalPractice_Sniffs_General_FormStateInputSniff implements PHP_CodeSniff /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the function + * name in the stack. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { if ($phpcsFile->getTokensAsString($stackPtr, 4) === '$form_state[\'input\']' || $phpcsFile->getTokensAsString($stackPtr, 4) === '$form_state["input"]' diff --git a/coder_sniffer/DrupalPractice/Sniffs/General/LanguageNoneSniff.php b/coder_sniffer/DrupalPractice/Sniffs/General/LanguageNoneSniff.php index bb10afa5..642742a9 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/General/LanguageNoneSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/General/LanguageNoneSniff.php @@ -1,12 +1,17 @@ <?php /** - * DrupalPractice_Sniffs_General_LanguageNoneSniff + * \DrupalPractice\Sniffs\General\LanguageNoneSniff * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace DrupalPractice\Sniffs\General; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** * Checks that ['und'] is not used, should be LANGUAGE_NONE. * @@ -14,7 +19,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class DrupalPractice_Sniffs_General_LanguageNoneSniff implements PHP_CodeSniffer_Sniff +class LanguageNoneSniff implements Sniff { @@ -36,13 +41,13 @@ class DrupalPractice_Sniffs_General_LanguageNoneSniff implements PHP_CodeSniffer /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The current file being processed. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the function + * name in the stack. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $sequence = $phpcsFile->getTokensAsString($stackPtr, 3); if ($sequence === "['und']" || $sequence === '["und"]') { diff --git a/coder_sniffer/DrupalPractice/Sniffs/General/OptionsTSniff.php b/coder_sniffer/DrupalPractice/Sniffs/General/OptionsTSniff.php index fced8fc2..74b4d3c8 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/General/OptionsTSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/General/OptionsTSniff.php @@ -1,12 +1,17 @@ <?php /** - * DrupalPractice_Sniffs_General_OptionsTSniff + * \DrupalPractice\Sniffs\General\OptionsTSniff * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace DrupalPractice\Sniffs\General; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** * Checks that values in #otions form arrays are translated. * @@ -14,7 +19,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class DrupalPractice_Sniffs_General_OptionsTSniff implements PHP_CodeSniffer_Sniff +class OptionsTSniff implements Sniff { @@ -33,13 +38,13 @@ class DrupalPractice_Sniffs_General_OptionsTSniff implements PHP_CodeSniffer_Sni /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The current file being processed. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the function + * name in the stack. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { // Look for the string "#options". $tokens = $phpcsFile->getTokens(); diff --git a/coder_sniffer/DrupalPractice/Sniffs/General/VariableNameSniff.php b/coder_sniffer/DrupalPractice/Sniffs/General/VariableNameSniff.php index 16285d85..b8b38e36 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/General/VariableNameSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/General/VariableNameSniff.php @@ -1,12 +1,19 @@ <?php /** - * DrupalPractice_Sniffs_General_VariableNameSniff + * \DrupalPractice\Sniffs\General\VariableNameSniff * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace DrupalPractice\Sniffs\General; + +use PHP_CodeSniffer\Files\File; +use Drupal\Sniffs\Semantics\FunctionCall; +use DrupalPractice\Project; +use PHP_CodeSniffer\Util\Tokens; + /** * Checks the usage of variable_get() in forms and the variable name. * @@ -14,7 +21,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class DrupalPractice_Sniffs_General_VariableNameSniff extends Drupal_Sniffs_Semantics_FunctionCall +class VariableNameSniff extends FunctionCall { @@ -33,18 +40,18 @@ class DrupalPractice_Sniffs_General_VariableNameSniff extends Drupal_Sniffs_Sema /** * Processes this function call. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the function call in - * the stack. - * @param int $openBracket The position of the opening - * parenthesis in the stack. - * @param int $closeBracket The position of the closing - * parenthesis in the stack. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the function call in + * the stack. + * @param int $openBracket The position of the opening + * parenthesis in the stack. + * @param int $closeBracket The position of the closing + * parenthesis in the stack. * * @return void */ public function processFunctionCall( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $openBracket, $closeBracket @@ -53,12 +60,12 @@ class DrupalPractice_Sniffs_General_VariableNameSniff extends Drupal_Sniffs_Sema // We assume that the sequence '#default_value' => variable_get(...) // indicates a variable that the module owns. - $arrow = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true); + $arrow = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); if ($arrow === false || $tokens[$arrow]['code'] !== T_DOUBLE_ARROW) { return; } - $arrayKey = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($arrow - 1), null, true); + $arrayKey = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($arrow - 1), null, true); if ($arrayKey === false || $tokens[$arrayKey]['code'] !== T_CONSTANT_ENCAPSED_STRING || substr($tokens[$arrayKey]['content'], 1, -1) !== '#default_value' @@ -73,7 +80,7 @@ class DrupalPractice_Sniffs_General_VariableNameSniff extends Drupal_Sniffs_Sema return; } - $moduleName = DrupalPractice_Project::getName($phpcsFile); + $moduleName = Project::getName($phpcsFile); if ($moduleName === false) { return; } diff --git a/coder_sniffer/DrupalPractice/Sniffs/InfoFiles/NamespacedDependencySniff.php b/coder_sniffer/DrupalPractice/Sniffs/InfoFiles/NamespacedDependencySniff.php index 27c827ab..d571017b 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/InfoFiles/NamespacedDependencySniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/InfoFiles/NamespacedDependencySniff.php @@ -1,13 +1,18 @@ <?php /** - * DrupalPractice_Sniffs_InfoFiles_NamespacedDependencySniff. + * \DrupalPractice\Sniffs\InfoFiles\NamespacedDependencySniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace DrupalPractice\Sniffs\InfoFiles; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** * Checks that all declared dependencies are namespaced. * @@ -15,7 +20,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class DrupalPractice_Sniffs_InfoFiles_NamespacedDependencySniff implements PHP_CodeSniffer_Sniff +class NamespacedDependencySniff implements Sniff { @@ -34,13 +39,13 @@ class DrupalPractice_Sniffs_InfoFiles_NamespacedDependencySniff implements PHP_C /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The current file being processed. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The current file being processed. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return int */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); diff --git a/coder_sniffer/DrupalPractice/Sniffs/Objects/GlobalClassSniff.php b/coder_sniffer/DrupalPractice/Sniffs/Objects/GlobalClassSniff.php index 8e62fcc5..e93542a5 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/Objects/GlobalClassSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/Objects/GlobalClassSniff.php @@ -1,12 +1,18 @@ <?php /** - * DrupalPractice_Sniffs_Objects_GlobalClassSniff. + * \DrupalPractice\Sniffs\Objects\GlobalClassSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace DrupalPractice\Sniffs\Objects; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; +use DrupalPractice\Project; + /** * Checks that Node::load() calls and friends are not used in forms, controllers or * services. @@ -15,7 +21,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class DrupalPractice_Sniffs_Objects_GlobalClassSniff implements PHP_CodeSniffer_Sniff +class GlobalClassSniff implements Sniff { /** @@ -48,13 +54,13 @@ class DrupalPractice_Sniffs_Objects_GlobalClassSniff implements PHP_CodeSniffer_ /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -85,8 +91,8 @@ class DrupalPractice_Sniffs_Objects_GlobalClassSniff implements PHP_CodeSniffer_ $extendsName = $phpcsFile->findExtendedClassName($classPtr); if (($extendsName === false - || in_array($extendsName, DrupalPractice_Sniffs_Objects_GlobalDrupalSniff::$baseClasses) === false) - && DrupalPractice_Project::isServiceClass($phpcsFile, $classPtr) === false + || in_array($extendsName, GlobalDrupalSniff::$baseClasses) === false) + && Project::isServiceClass($phpcsFile, $classPtr) === false ) { return; } diff --git a/coder_sniffer/DrupalPractice/Sniffs/Objects/GlobalDrupalSniff.php b/coder_sniffer/DrupalPractice/Sniffs/Objects/GlobalDrupalSniff.php index 1bf4faf0..ee2eda4b 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/Objects/GlobalDrupalSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/Objects/GlobalDrupalSniff.php @@ -1,12 +1,18 @@ <?php /** - * DrupalPractice_Sniffs_Objects_GlobalDrupalSniff. + * \DrupalPractice\Sniffs\Objects\GlobalDrupalSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace DrupalPractice\Sniffs\Objects; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; +use DrupalPractice\Project; + /** * Checks that \Drupal::service() and friends is not used in forms, controllers, services. * @@ -14,7 +20,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class DrupalPractice_Sniffs_Objects_GlobalDrupalSniff implements PHP_CodeSniffer_Sniff +class GlobalDrupalSniff implements Sniff { /** @@ -53,13 +59,13 @@ class DrupalPractice_Sniffs_Objects_GlobalDrupalSniff implements PHP_CodeSniffer /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -89,7 +95,7 @@ class DrupalPractice_Sniffs_Objects_GlobalDrupalSniff implements PHP_CodeSniffer $extendsName = $phpcsFile->findExtendedClassName($classPtr); if (($extendsName === false || in_array($extendsName, static::$baseClasses) === false) - && DrupalPractice_Project::isServiceClass($phpcsFile, $classPtr) === false + && Project::isServiceClass($phpcsFile, $classPtr) === false ) { return; } diff --git a/coder_sniffer/DrupalPractice/Sniffs/Objects/GlobalFunctionSniff.php b/coder_sniffer/DrupalPractice/Sniffs/Objects/GlobalFunctionSniff.php index 29d7f790..969d1c80 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/Objects/GlobalFunctionSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/Objects/GlobalFunctionSniff.php @@ -1,12 +1,19 @@ <?php /** - * DrupalPractice_Sniffs_Objects_GlobalFunctionSniff. + * \DrupalPractice\Sniffs\Objects\GlobalFunctionSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace DrupalPractice\Sniffs\Objects; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; +use DrupalPractice\Sniffs\Objects\GlobalDrupalSniff; +use DrupalPractice\Project; + /** * Checks that global functions like t() are not used in forms or controllers. * @@ -14,7 +21,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class DrupalPractice_Sniffs_Objects_GlobalFunctionSniff implements PHP_CodeSniffer_Sniff +class GlobalFunctionSniff implements Sniff { /** @@ -54,13 +61,13 @@ class DrupalPractice_Sniffs_Objects_GlobalFunctionSniff implements PHP_CodeSniff /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -94,8 +101,8 @@ class DrupalPractice_Sniffs_Objects_GlobalFunctionSniff implements PHP_CodeSniff $extendsName = $phpcsFile->findExtendedClassName($classPtr); if (($extendsName === false - || in_array($extendsName, DrupalPractice_Sniffs_Objects_GlobalDrupalSniff::$baseClasses) === false) - && DrupalPractice_Project::isServiceClass($phpcsFile, $classPtr) === false + || in_array($extendsName, GlobalDrupalSniff::$baseClasses) === false) + && Project::isServiceClass($phpcsFile, $classPtr) === false ) { return; } diff --git a/coder_sniffer/DrupalPractice/Sniffs/Objects/UnusedPrivateMethodSniff.php b/coder_sniffer/DrupalPractice/Sniffs/Objects/UnusedPrivateMethodSniff.php index 7a55f7ef..63f9e40b 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/Objects/UnusedPrivateMethodSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/Objects/UnusedPrivateMethodSniff.php @@ -1,12 +1,18 @@ <?php /** - * DrupalPractice_Sniffs_Objects_UnusedPrivateMethodSniff. + * \DrupalPractice\Sniffs\Objects\UnusedPrivateMethodSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace DrupalPractice\Sniffs\Objects; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\AbstractScopeSniff; +use PHP_CodeSniffer\Util\Tokens; + /** * Checks that private methods are actually used in a class. * @@ -14,7 +20,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class DrupalPractice_Sniffs_Objects_UnusedPrivateMethodSniff extends PHP_CodeSniffer_Standards_AbstractScopeSniff +class UnusedPrivateMethodSniff extends AbstractScopeSniff { @@ -31,14 +37,14 @@ class DrupalPractice_Sniffs_Objects_UnusedPrivateMethodSniff extends PHP_CodeSni /** * Processes the tokens within the scope. * - * @param PHP_CodeSniffer_File $phpcsFile The file being processed. - * @param int $stackPtr The position where this token was - * found. - * @param int $currScope The position of the current scope. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being processed. + * @param int $stackPtr The position where this token was + * found. + * @param int $currScope The position of the current scope. * * @return void */ - protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope) + protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope) { // Only check private methods. $methodProperties = $phpcsFile->getMethodProperties($stackPtr); @@ -60,18 +66,18 @@ class DrupalPractice_Sniffs_Objects_UnusedPrivateMethodSniff extends PHP_CodeSni continue; } - $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($current + 1), null, true); + $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($current + 1), null, true); if ($next === false) { continue; } if ($tokens[$next]['code'] === T_OBJECT_OPERATOR) { - $call = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($next + 1), null, true); + $call = $phpcsFile->findNext(Tokens::$emptyTokens, ($next + 1), null, true); if ($call === false || $tokens[$call]['content'] !== $methodName) { continue; } - $parenthesis = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($call + 1), null, true); + $parenthesis = $phpcsFile->findNext(Tokens::$emptyTokens, ($call + 1), null, true); if ($parenthesis === false || $tokens[$parenthesis]['code'] !== T_OPEN_PARENTHESIS) { continue; } @@ -80,7 +86,7 @@ class DrupalPractice_Sniffs_Objects_UnusedPrivateMethodSniff extends PHP_CodeSni // can stop. return; } else if ($tokens[$next]['code'] === T_COMMA) { - $call = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($next + 1), null, true); + $call = $phpcsFile->findNext(Tokens::$emptyTokens, ($next + 1), null, true); if ($call === false || substr($tokens[$call]['content'], 1, -1) !== $methodName) { continue; } @@ -98,4 +104,19 @@ class DrupalPractice_Sniffs_Objects_UnusedPrivateMethodSniff extends PHP_CodeSni }//end processTokenWithinScope() + /** + * Process tokens outside of scope. + * + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being processed. + * @param int $stackPtr The position where this token was + * found. + * + * @return void + */ + protected function processTokenOutsideScope(File $phpcsFile, $stackPtr) + { + + }//end processTokenOutsideScope() + + }//end class diff --git a/coder_sniffer/DrupalPractice/Sniffs/Yaml/RoutingAccessSniff.php b/coder_sniffer/DrupalPractice/Sniffs/Yaml/RoutingAccessSniff.php index 78349667..7ca36195 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/Yaml/RoutingAccessSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/Yaml/RoutingAccessSniff.php @@ -1,13 +1,18 @@ <?php /** - * DrupalPractice_Sniffs_Yaml_RoutingAccessSniff. + * \DrupalPractice\Sniffs\Yaml\RoutingAccessSniff. * * @category PHP * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace DrupalPractice\Sniffs\Yaml; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; + /** * Checks that there are no undocumented open access callbacks in *.routing.yml files. * @@ -17,7 +22,7 @@ * @package PHP_CodeSniffer * @link http://pear.php.net/package/PHP_CodeSniffer */ -class DrupalPractice_Sniffs_Yaml_RoutingAccessSniff implements PHP_CodeSniffer_Sniff +class RoutingAccessSniff implements Sniff { @@ -36,13 +41,13 @@ class DrupalPractice_Sniffs_Yaml_RoutingAccessSniff implements PHP_CodeSniffer_S /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The current file being processed. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The current file being processed. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return int */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); diff --git a/coder_sniffer/DrupalPractice/Test/CodeAnalysis/VariableAnalysisUnitTest.php b/coder_sniffer/DrupalPractice/Test/CodeAnalysis/VariableAnalysisUnitTest.php index 59b67326..8026e308 100644 --- a/coder_sniffer/DrupalPractice/Test/CodeAnalysis/VariableAnalysisUnitTest.php +++ b/coder_sniffer/DrupalPractice/Test/CodeAnalysis/VariableAnalysisUnitTest.php @@ -1,12 +1,16 @@ <?php +namespace DrupalPractice\Sniffs\CodeAnalysis; + +use Drupal\Test\CoderSniffUnitTest; + /** * Unit test class for the VariableAnalysis sniff. * * A sniff unit test checks a .inc file for expected violations of a single * coding standard. Expected errors and warnings are stored in this class. */ -class DrupalPractice_Sniffs_CodeAnalysis_VariableAnalysisUnitTest extends CoderSniffUnitTest +class VariableAnalysisUnitTest extends CoderSniffUnitTest { @@ -18,7 +22,7 @@ class DrupalPractice_Sniffs_CodeAnalysis_VariableAnalysisUnitTest extends CoderS * * @return array(int => int) */ - protected function getErrorList($testFile) + protected function getErrorList($testFile = NULL) { return array(); @@ -33,7 +37,7 @@ class DrupalPractice_Sniffs_CodeAnalysis_VariableAnalysisUnitTest extends CoderS * * @return array(int => int) */ - protected function getWarningList($testFile) + protected function getWarningList($testFile = NULL) { return array( 4 => 1, diff --git a/coder_sniffer/DrupalPractice/Test/Commenting/AuthorTagUnitTest.php b/coder_sniffer/DrupalPractice/Test/Commenting/AuthorTagUnitTest.php index 7864c69d..f12e84ed 100644 --- a/coder_sniffer/DrupalPractice/Test/Commenting/AuthorTagUnitTest.php +++ b/coder_sniffer/DrupalPractice/Test/Commenting/AuthorTagUnitTest.php @@ -1,6 +1,10 @@ <?php -class DrupalPractice_Sniffs_Commenting_AuthorTagUnitTest extends CoderSniffUnitTest +namespace DrupalPractice\Sniffs\Commenting; + +use Drupal\Test\CoderSniffUnitTest; + +class AuthorTagUnitTest extends CoderSniffUnitTest { @@ -12,7 +16,7 @@ class DrupalPractice_Sniffs_Commenting_AuthorTagUnitTest extends CoderSniffUnitT * * @return array(int => int) */ - protected function getErrorList($testFile) + protected function getErrorList($testFile = NULL) { return array(); @@ -27,7 +31,7 @@ class DrupalPractice_Sniffs_Commenting_AuthorTagUnitTest extends CoderSniffUnitT * * @return array(int => int) */ - protected function getWarningList($testFile) + protected function getWarningList($testFile = NULL) { return array( 7 => 1, diff --git a/coder_sniffer/DrupalPractice/Test/Commenting/CommentEmptyLineUnitTest.php b/coder_sniffer/DrupalPractice/Test/Commenting/CommentEmptyLineUnitTest.php index eddda0df..2edc500a 100644 --- a/coder_sniffer/DrupalPractice/Test/Commenting/CommentEmptyLineUnitTest.php +++ b/coder_sniffer/DrupalPractice/Test/Commenting/CommentEmptyLineUnitTest.php @@ -3,13 +3,17 @@ * Unit test class for the CommentEmptyLine sniff. */ +namespace DrupalPractice\Sniffs\Commenting; + +use Drupal\Test\CoderSniffUnitTest; + /** * Unit test class for the EmptyStatement sniff. * * A sniff unit test checks a .inc file for expected violations of a single * coding standard. Expected errors and warnings are stored in this class. */ -class DrupalPractice_Sniffs_Commenting_CommentEmptyLineUnitTest extends CoderSniffUnitTest +class CommentEmptyLineUnitTest extends CoderSniffUnitTest { @@ -21,7 +25,7 @@ class DrupalPractice_Sniffs_Commenting_CommentEmptyLineUnitTest extends CoderSni * * @return array(int => int) */ - protected function getErrorList($testFile) + protected function getErrorList($testFile = NULL) { return array(); @@ -36,7 +40,7 @@ class DrupalPractice_Sniffs_Commenting_CommentEmptyLineUnitTest extends CoderSni * * @return array(int => int) */ - protected function getWarningList($testFile) + protected function getWarningList($testFile = NULL) { return array(3 => 1); diff --git a/coder_sniffer/DrupalPractice/Test/Commenting/ExpectedExceptionUnitTest.php b/coder_sniffer/DrupalPractice/Test/Commenting/ExpectedExceptionUnitTest.php index 1100f915..6f3e5811 100644 --- a/coder_sniffer/DrupalPractice/Test/Commenting/ExpectedExceptionUnitTest.php +++ b/coder_sniffer/DrupalPractice/Test/Commenting/ExpectedExceptionUnitTest.php @@ -1,6 +1,10 @@ <?php -class DrupalPractice_Sniffs_Commenting_ExpectedExceptionUnitTest extends CoderSniffUnitTest +namespace DrupalPractice\Sniffs\Commenting; + +use Drupal\Test\CoderSniffUnitTest; + +class ExpectedExceptionUnitTest extends CoderSniffUnitTest { @@ -12,7 +16,7 @@ class DrupalPractice_Sniffs_Commenting_ExpectedExceptionUnitTest extends CoderSn * * @return array(int => int) */ - protected function getErrorList($testFile) + protected function getErrorList($testFile = NULL) { return array(); @@ -27,7 +31,7 @@ class DrupalPractice_Sniffs_Commenting_ExpectedExceptionUnitTest extends CoderSn * * @return array(int => int) */ - protected function getWarningList($testFile) + protected function getWarningList($testFile = NULL) { return array( 8 => 1, diff --git a/coder_sniffer/DrupalPractice/Test/Constants/GlobalConstantUnitTest.php b/coder_sniffer/DrupalPractice/Test/Constants/GlobalConstantUnitTest.php index 1b9a5440..890eebd8 100644 --- a/coder_sniffer/DrupalPractice/Test/Constants/GlobalConstantUnitTest.php +++ b/coder_sniffer/DrupalPractice/Test/Constants/GlobalConstantUnitTest.php @@ -1,12 +1,16 @@ <?php +namespace DrupalPractice\Sniffs\Constants; + +use Drupal\Test\CoderSniffUnitTest; + /** * Unit test class for the OptionsT sniff. * * A sniff unit test checks a .inc file for expected violations of a single * coding standard. Expected errors and warnings are stored in this class. */ -class DrupalPractice_Sniffs_Constants_GlobalConstantUnitTest extends CoderSniffUnitTest +class GlobalConstantUnitTest extends CoderSniffUnitTest { @@ -18,7 +22,7 @@ class DrupalPractice_Sniffs_Constants_GlobalConstantUnitTest extends CoderSniffU * * @return array(int => int) */ - protected function getErrorList($testFile) + protected function getErrorList($testFile = NULL) { return array(); @@ -33,7 +37,7 @@ class DrupalPractice_Sniffs_Constants_GlobalConstantUnitTest extends CoderSniffU * * @return array(int => int) */ - protected function getWarningList($testFile) + protected function getWarningList($testFile = NULL) { return array( 3 => 1, diff --git a/coder_sniffer/DrupalPractice/Test/Constants/GlobalDefineUnitTest.php b/coder_sniffer/DrupalPractice/Test/Constants/GlobalDefineUnitTest.php index 49f551ec..f2453985 100644 --- a/coder_sniffer/DrupalPractice/Test/Constants/GlobalDefineUnitTest.php +++ b/coder_sniffer/DrupalPractice/Test/Constants/GlobalDefineUnitTest.php @@ -1,12 +1,16 @@ <?php +namespace DrupalPractice\Sniffs\Constants; + +use Drupal\Test\CoderSniffUnitTest; + /** * Unit test class for the OptionsT sniff. * * A sniff unit test checks a .inc file for expected violations of a single * coding standard. Expected errors and warnings are stored in this class. */ -class DrupalPractice_Sniffs_Constants_GlobalDefineUnitTest extends CoderSniffUnitTest +class GlobalDefineUnitTest extends CoderSniffUnitTest { @@ -18,7 +22,7 @@ class DrupalPractice_Sniffs_Constants_GlobalDefineUnitTest extends CoderSniffUni * * @return array(int => int) */ - protected function getErrorList($testFile) + protected function getErrorList($testFile = NULL) { return array(); @@ -33,7 +37,7 @@ class DrupalPractice_Sniffs_Constants_GlobalDefineUnitTest extends CoderSniffUni * * @return array(int => int) */ - protected function getWarningList($testFile) + protected function getWarningList($testFile = NULL) { return array( 3 => 1, diff --git a/coder_sniffer/DrupalPractice/Test/FunctionCalls/CheckPlainUnitTest.php b/coder_sniffer/DrupalPractice/Test/FunctionCalls/CheckPlainUnitTest.php index ee01d2b9..afe0aa70 100644 --- a/coder_sniffer/DrupalPractice/Test/FunctionCalls/CheckPlainUnitTest.php +++ b/coder_sniffer/DrupalPractice/Test/FunctionCalls/CheckPlainUnitTest.php @@ -3,13 +3,17 @@ * Unit test class for the CheckPlain sniff. */ +namespace DrupalPractice\Sniffs\FunctionCalls; + +use Drupal\Test\CoderSniffUnitTest; + /** * Unit test class for the CheckPlain sniff. * * A sniff unit test checks a .inc file for expected violations of a single * coding standard. Expected errors and warnings are stored in this class. */ -class DrupalPractice_Sniffs_FunctionCalls_CheckPlainUnitTest extends CoderSniffUnitTest +class CheckPlainUnitTest extends CoderSniffUnitTest { @@ -21,7 +25,7 @@ class DrupalPractice_Sniffs_FunctionCalls_CheckPlainUnitTest extends CoderSniffU * * @return array(int => int) */ - protected function getErrorList($testFile) + protected function getErrorList($testFile = NULL) { return array(); @@ -36,7 +40,7 @@ class DrupalPractice_Sniffs_FunctionCalls_CheckPlainUnitTest extends CoderSniffU * * @return array(int => int) */ - protected function getWarningList($testFile) + protected function getWarningList($testFile = NULL) { return array(3 => 1); diff --git a/coder_sniffer/DrupalPractice/Test/FunctionCalls/CurlSslVerifierUnitTest.php b/coder_sniffer/DrupalPractice/Test/FunctionCalls/CurlSslVerifierUnitTest.php index b3f628f5..73e4e537 100644 --- a/coder_sniffer/DrupalPractice/Test/FunctionCalls/CurlSslVerifierUnitTest.php +++ b/coder_sniffer/DrupalPractice/Test/FunctionCalls/CurlSslVerifierUnitTest.php @@ -1,12 +1,16 @@ <?php +namespace DrupalPractice\Sniffs\FunctionCalls; + +use Drupal\Test\CoderSniffUnitTest; + /** * Unit test class for the CurlSslVerifier sniff. * * A sniff unit test checks a .inc file for expected violations of a single * coding standard. Expected errors and warnings are stored in this class. */ -class DrupalPractice_Sniffs_FunctionCalls_CurlSslVerifierUnitTest extends CoderSniffUnitTest +class CurlSslVerifierUnitTest extends CoderSniffUnitTest { @@ -18,7 +22,7 @@ class DrupalPractice_Sniffs_FunctionCalls_CurlSslVerifierUnitTest extends CoderS * * @return array(int => int) */ - protected function getErrorList($testFile) + protected function getErrorList($testFile = NULL) { return array(); @@ -33,7 +37,7 @@ class DrupalPractice_Sniffs_FunctionCalls_CurlSslVerifierUnitTest extends CoderS * * @return array(int => int) */ - protected function getWarningList($testFile) + protected function getWarningList($testFile = NULL) { return array(4 => 1); diff --git a/coder_sniffer/DrupalPractice/Test/FunctionCalls/DbQueryUnitTest.php b/coder_sniffer/DrupalPractice/Test/FunctionCalls/DbQueryUnitTest.php index a6be997d..18343b2f 100644 --- a/coder_sniffer/DrupalPractice/Test/FunctionCalls/DbQueryUnitTest.php +++ b/coder_sniffer/DrupalPractice/Test/FunctionCalls/DbQueryUnitTest.php @@ -3,13 +3,17 @@ * Unit test class for the DbQuery sniff. */ +namespace DrupalPractice\Sniffs\FunctionCalls; + +use Drupal\Test\CoderSniffUnitTest; + /** * Unit test class for the DbQuery sniff. * * A sniff unit test checks a .inc file for expected violations of a single * coding standard. Expected errors and warnings are stored in this class. */ -class DrupalPractice_Sniffs_FunctionCalls_DbQueryUnitTest extends CoderSniffUnitTest +class DbQueryUnitTest extends CoderSniffUnitTest { @@ -21,7 +25,7 @@ class DrupalPractice_Sniffs_FunctionCalls_DbQueryUnitTest extends CoderSniffUnit * * @return array(int => int) */ - protected function getErrorList($testFile) + protected function getErrorList($testFile = NULL) { return array(); @@ -36,7 +40,7 @@ class DrupalPractice_Sniffs_FunctionCalls_DbQueryUnitTest extends CoderSniffUnit * * @return array(int => int) */ - protected function getWarningList($testFile) + protected function getWarningList($testFile = NULL) { return array( 3 => 1, diff --git a/coder_sniffer/DrupalPractice/Test/FunctionCalls/DbSelectBracesUnitTest.php b/coder_sniffer/DrupalPractice/Test/FunctionCalls/DbSelectBracesUnitTest.php index 2e88dd7f..673a5cda 100644 --- a/coder_sniffer/DrupalPractice/Test/FunctionCalls/DbSelectBracesUnitTest.php +++ b/coder_sniffer/DrupalPractice/Test/FunctionCalls/DbSelectBracesUnitTest.php @@ -3,13 +3,17 @@ * Unit test class for the DbSelectBraces sniff. */ +namespace DrupalPractice\Sniffs\FunctionCalls; + +use Drupal\Test\CoderSniffUnitTest; + /** * Unit test class for the DbSelectBraces sniff. * * A sniff unit test checks a .inc file for expected violations of a single * coding standard. Expected errors and warnings are stored in this class. */ -class DrupalPractice_Sniffs_FunctionCalls_DbSelectBracesUnitTest extends CoderSniffUnitTest +class DbSelectBracesUnitTest extends CoderSniffUnitTest { @@ -21,7 +25,7 @@ class DrupalPractice_Sniffs_FunctionCalls_DbSelectBracesUnitTest extends CoderSn * * @return array(int => int) */ - protected function getErrorList($testFile) + protected function getErrorList($testFile = NULL) { return array(); @@ -36,7 +40,7 @@ class DrupalPractice_Sniffs_FunctionCalls_DbSelectBracesUnitTest extends CoderSn * * @return array(int => int) */ - protected function getWarningList($testFile) + protected function getWarningList($testFile = NULL) { return array(3 => 1); diff --git a/coder_sniffer/DrupalPractice/Test/FunctionCalls/DefaultValueSanitizeUnitTest.php b/coder_sniffer/DrupalPractice/Test/FunctionCalls/DefaultValueSanitizeUnitTest.php index feaca9d5..0599a602 100644 --- a/coder_sniffer/DrupalPractice/Test/FunctionCalls/DefaultValueSanitizeUnitTest.php +++ b/coder_sniffer/DrupalPractice/Test/FunctionCalls/DefaultValueSanitizeUnitTest.php @@ -1,12 +1,16 @@ <?php +namespace DrupalPractice\Sniffs\FunctionCalls; + +use Drupal\Test\CoderSniffUnitTest; + /** * Unit test class for the DefaultValueSanitize sniff. * * A sniff unit test checks a .inc file for expected violations of a single * coding standard. Expected errors and warnings are stored in this class. */ -class DrupalPractice_Sniffs_FunctionCalls_DefaultValueSanitizeUnitTest extends CoderSniffUnitTest +class DefaultValueSanitizeUnitTest extends CoderSniffUnitTest { @@ -18,7 +22,7 @@ class DrupalPractice_Sniffs_FunctionCalls_DefaultValueSanitizeUnitTest extends C * * @return array(int => int) */ - protected function getErrorList($testFile) + protected function getErrorList($testFile = NULL) { return array(); @@ -33,7 +37,7 @@ class DrupalPractice_Sniffs_FunctionCalls_DefaultValueSanitizeUnitTest extends C * * @return array(int => int) */ - protected function getWarningList($testFile) + protected function getWarningList($testFile = NULL) { return array(6 => 1); diff --git a/coder_sniffer/DrupalPractice/Test/FunctionCalls/TCheckPlainUnitTest.php b/coder_sniffer/DrupalPractice/Test/FunctionCalls/TCheckPlainUnitTest.php index ccbd7d40..4161264d 100644 --- a/coder_sniffer/DrupalPractice/Test/FunctionCalls/TCheckPlainUnitTest.php +++ b/coder_sniffer/DrupalPractice/Test/FunctionCalls/TCheckPlainUnitTest.php @@ -1,12 +1,16 @@ <?php +namespace DrupalPractice\Sniffs\FunctionCalls; + +use Drupal\Test\CoderSniffUnitTest; + /** * Unit test class for the TCheckPlain sniff. * * A sniff unit test checks a .inc file for expected violations of a single * coding standard. Expected errors and warnings are stored in this class. */ -class DrupalPractice_Sniffs_FunctionCalls_TCheckPlainUnitTest extends CoderSniffUnitTest +class TCheckPlainUnitTest extends CoderSniffUnitTest { @@ -18,7 +22,7 @@ class DrupalPractice_Sniffs_FunctionCalls_TCheckPlainUnitTest extends CoderSniff * * @return array(int => int) */ - protected function getErrorList($testFile) + protected function getErrorList($testFile = NULL) { return array(); @@ -33,7 +37,7 @@ class DrupalPractice_Sniffs_FunctionCalls_TCheckPlainUnitTest extends CoderSniff * * @return array(int => int) */ - protected function getWarningList($testFile) + protected function getWarningList($testFile = NULL) { return array(8 => 1); }//end getWarningList() diff --git a/coder_sniffer/DrupalPractice/Test/FunctionCalls/VariableSetSanitizeUnitTest.php b/coder_sniffer/DrupalPractice/Test/FunctionCalls/VariableSetSanitizeUnitTest.php index 3d0a260d..976db058 100644 --- a/coder_sniffer/DrupalPractice/Test/FunctionCalls/VariableSetSanitizeUnitTest.php +++ b/coder_sniffer/DrupalPractice/Test/FunctionCalls/VariableSetSanitizeUnitTest.php @@ -1,12 +1,16 @@ <?php +namespace DrupalPractice\Sniffs\FunctionCalls; + +use Drupal\Test\CoderSniffUnitTest; + /** * Unit test class for the VariableSetSanitize sniff. * * A sniff unit test checks a .inc file for expected violations of a single * coding standard. Expected errors and warnings are stored in this class. */ -class DrupalPractice_Sniffs_FunctionCalls_VariableSetSanitizeUnitTest extends CoderSniffUnitTest +class VariableSetSanitizeUnitTest extends CoderSniffUnitTest { @@ -18,7 +22,7 @@ class DrupalPractice_Sniffs_FunctionCalls_VariableSetSanitizeUnitTest extends Co * * @return array(int => int) */ - protected function getErrorList($testFile) + protected function getErrorList($testFile = NULL) { return array(); @@ -33,7 +37,7 @@ class DrupalPractice_Sniffs_FunctionCalls_VariableSetSanitizeUnitTest extends Co * * @return array(int => int) */ - protected function getWarningList($testFile) + protected function getWarningList($testFile = NULL) { return array(3 => 1); diff --git a/coder_sniffer/DrupalPractice/Test/FunctionDefinitions/AccessHookMenuUnitTest.php b/coder_sniffer/DrupalPractice/Test/FunctionDefinitions/AccessHookMenuUnitTest.php index 9ea875b6..30f1447f 100644 --- a/coder_sniffer/DrupalPractice/Test/FunctionDefinitions/AccessHookMenuUnitTest.php +++ b/coder_sniffer/DrupalPractice/Test/FunctionDefinitions/AccessHookMenuUnitTest.php @@ -1,12 +1,16 @@ <?php +namespace DrupalPractice\Sniffs\FunctionDefinitions; + +use Drupal\Test\CoderSniffUnitTest; + /** * Unit test class for the HookInitCss sniff. * * A sniff unit test checks a .inc file for expected violations of a single * coding standard. Expected errors and warnings are stored in this class. */ -class DrupalPractice_Sniffs_FunctionDefinitions_AccessHookMenuUnitTest extends CoderSniffUnitTest +class AccessHookMenuUnitTest extends CoderSniffUnitTest { @@ -18,7 +22,7 @@ class DrupalPractice_Sniffs_FunctionDefinitions_AccessHookMenuUnitTest extends C * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array(); @@ -33,7 +37,7 @@ class DrupalPractice_Sniffs_FunctionDefinitions_AccessHookMenuUnitTest extends C * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array( 24 => 1, @@ -46,7 +50,7 @@ class DrupalPractice_Sniffs_FunctionDefinitions_AccessHookMenuUnitTest extends C * * @return array The list of test files. */ - protected function getTestFiles() { + protected function getTestFiles($testFileBase) { return array(__DIR__ . '/test.module'); } diff --git a/coder_sniffer/DrupalPractice/Test/FunctionDefinitions/FormAlterDocUnitTest.php b/coder_sniffer/DrupalPractice/Test/FunctionDefinitions/FormAlterDocUnitTest.php index 0147b5ad..07027cad 100644 --- a/coder_sniffer/DrupalPractice/Test/FunctionDefinitions/FormAlterDocUnitTest.php +++ b/coder_sniffer/DrupalPractice/Test/FunctionDefinitions/FormAlterDocUnitTest.php @@ -1,6 +1,10 @@ <?php -class DrupalPractice_Sniffs_FunctionDefinitions_FormAlterDocUnitTest extends CoderSniffUnitTest +namespace DrupalPractice\Sniffs\FunctionDefinitions; + +use Drupal\Test\CoderSniffUnitTest; + +class FormAlterDocUnitTest extends CoderSniffUnitTest { @@ -12,7 +16,7 @@ class DrupalPractice_Sniffs_FunctionDefinitions_FormAlterDocUnitTest extends Cod * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array(); @@ -27,7 +31,7 @@ class DrupalPractice_Sniffs_FunctionDefinitions_FormAlterDocUnitTest extends Cod * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array( 31 => 1, @@ -40,7 +44,7 @@ class DrupalPractice_Sniffs_FunctionDefinitions_FormAlterDocUnitTest extends Cod * * @return array The list of test files. */ - protected function getTestFiles() { + protected function getTestFiles($testFileBase) { return array(__DIR__ . '/test.module'); } diff --git a/coder_sniffer/DrupalPractice/Test/FunctionDefinitions/HookInitCssUnitTest.php b/coder_sniffer/DrupalPractice/Test/FunctionDefinitions/HookInitCssUnitTest.php index db9237ab..66e54b7c 100644 --- a/coder_sniffer/DrupalPractice/Test/FunctionDefinitions/HookInitCssUnitTest.php +++ b/coder_sniffer/DrupalPractice/Test/FunctionDefinitions/HookInitCssUnitTest.php @@ -1,12 +1,16 @@ <?php +namespace DrupalPractice\Sniffs\FunctionDefinitions; + +use Drupal\Test\CoderSniffUnitTest; + /** * Unit test class for the HookInitCss sniff. * * A sniff unit test checks a .inc file for expected violations of a single * coding standard. Expected errors and warnings are stored in this class. */ -class DrupalPractice_Sniffs_FunctionDefinitions_HookInitCssUnitTest extends CoderSniffUnitTest +class HookInitCssUnitTest extends CoderSniffUnitTest { @@ -18,7 +22,7 @@ class DrupalPractice_Sniffs_FunctionDefinitions_HookInitCssUnitTest extends Code * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array(); @@ -33,7 +37,7 @@ class DrupalPractice_Sniffs_FunctionDefinitions_HookInitCssUnitTest extends Code * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array( 7 => 1, @@ -47,7 +51,7 @@ class DrupalPractice_Sniffs_FunctionDefinitions_HookInitCssUnitTest extends Code * * @return array The list of test files. */ - protected function getTestFiles() { + protected function getTestFiles($testFileBase) { return array(__DIR__ . '/test.module'); } diff --git a/coder_sniffer/DrupalPractice/Test/FunctionDefinitions/InstallTSniffUnitTest.php b/coder_sniffer/DrupalPractice/Test/FunctionDefinitions/InstallTSniffUnitTest.php index 2442b894..c1467376 100644 --- a/coder_sniffer/DrupalPractice/Test/FunctionDefinitions/InstallTSniffUnitTest.php +++ b/coder_sniffer/DrupalPractice/Test/FunctionDefinitions/InstallTSniffUnitTest.php @@ -1,12 +1,16 @@ <?php +namespace DrupalPractice\Sniffs\FunctionDefinitions; + +use Drupal\Test\CoderSniffUnitTest; + /** * Unit test class for the InstallT sniff. * * A sniff unit test checks a .inc file for expected violations of a single * coding standard. Expected errors and warnings are stored in this class. */ -class DrupalPractice_Sniffs_FunctionDefinitions_InstallTUnitTest extends CoderSniffUnitTest +class InstallTUnitTest extends CoderSniffUnitTest { @@ -18,7 +22,7 @@ class DrupalPractice_Sniffs_FunctionDefinitions_InstallTUnitTest extends CoderSn * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array( 12 => 1, @@ -35,7 +39,7 @@ class DrupalPractice_Sniffs_FunctionDefinitions_InstallTUnitTest extends CoderSn * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); @@ -46,7 +50,7 @@ class DrupalPractice_Sniffs_FunctionDefinitions_InstallTUnitTest extends CoderSn * * @return array The list of test files. */ - protected function getTestFiles() { + protected function getTestFiles($testFileBase) { return array(__DIR__ . '/test.install'); } diff --git a/coder_sniffer/DrupalPractice/Test/General/OptionsTUnitTest.php b/coder_sniffer/DrupalPractice/Test/General/OptionsTUnitTest.php index 8af305e9..9dd44bf2 100644 --- a/coder_sniffer/DrupalPractice/Test/General/OptionsTUnitTest.php +++ b/coder_sniffer/DrupalPractice/Test/General/OptionsTUnitTest.php @@ -1,12 +1,16 @@ <?php +namespace DrupalPractice\Sniffs\General; + +use Drupal\Test\CoderSniffUnitTest; + /** * Unit test class for the OptionsT sniff. * * A sniff unit test checks a .inc file for expected violations of a single * coding standard. Expected errors and warnings are stored in this class. */ -class DrupalPractice_Sniffs_General_OptionsTUnitTest extends CoderSniffUnitTest +class OptionsTUnitTest extends CoderSniffUnitTest { @@ -18,7 +22,7 @@ class DrupalPractice_Sniffs_General_OptionsTUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - protected function getErrorList($testFile) + protected function getErrorList($testFile = NULL) { return array(); @@ -33,7 +37,7 @@ class DrupalPractice_Sniffs_General_OptionsTUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - protected function getWarningList($testFile) + protected function getWarningList($testFile = NULL) { return array(14 => 1); diff --git a/coder_sniffer/DrupalPractice/Test/General/VariableNameUnitTest.php b/coder_sniffer/DrupalPractice/Test/General/VariableNameUnitTest.php index 162d97d6..8ee62bd5 100644 --- a/coder_sniffer/DrupalPractice/Test/General/VariableNameUnitTest.php +++ b/coder_sniffer/DrupalPractice/Test/General/VariableNameUnitTest.php @@ -3,13 +3,17 @@ * Unit test class for the CommentEmptyLine sniff. */ +namespace DrupalPractice\Sniffs\General; + +use Drupal\Test\CoderSniffUnitTest; + /** * Unit test class for the VariableName sniff. * * A sniff unit test checks a .inc file for expected violations of a single * coding standard. Expected errors and warnings are stored in this class. */ -class DrupalPractice_Sniffs_General_VariableNameUnitTest extends CoderSniffUnitTest +class VariableNameUnitTest extends CoderSniffUnitTest { @@ -21,7 +25,7 @@ class DrupalPractice_Sniffs_General_VariableNameUnitTest extends CoderSniffUnitT * * @return array(int => int) */ - protected function getErrorList($testFile) + protected function getErrorList($testFile = NULL) { return array(); @@ -36,7 +40,7 @@ class DrupalPractice_Sniffs_General_VariableNameUnitTest extends CoderSniffUnitT * * @return array(int => int) */ - protected function getWarningList($testFile) + protected function getWarningList($testFile = NULL) { return array(11 => 1); diff --git a/coder_sniffer/DrupalPractice/Test/InfoFiles/NamespacedDependencyUnitTest.php b/coder_sniffer/DrupalPractice/Test/InfoFiles/NamespacedDependencyUnitTest.php index 52341e87..8a3ddbe8 100644 --- a/coder_sniffer/DrupalPractice/Test/InfoFiles/NamespacedDependencyUnitTest.php +++ b/coder_sniffer/DrupalPractice/Test/InfoFiles/NamespacedDependencyUnitTest.php @@ -1,6 +1,10 @@ <?php -class DrupalPractice_Sniffs_InfoFiles_NamespacedDependencyUnitTest extends CoderSniffUnitTest +namespace DrupalPractice\Sniffs\InfoFiles; + +use Drupal\Test\CoderSniffUnitTest; + +class NamespacedDependencyUnitTest extends CoderSniffUnitTest { @@ -12,7 +16,7 @@ class DrupalPractice_Sniffs_InfoFiles_NamespacedDependencyUnitTest extends Coder * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array(); @@ -27,7 +31,7 @@ class DrupalPractice_Sniffs_InfoFiles_NamespacedDependencyUnitTest extends Coder * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array( 9 => 1, @@ -42,7 +46,7 @@ class DrupalPractice_Sniffs_InfoFiles_NamespacedDependencyUnitTest extends Coder * * @return array The list of test files. */ - protected function getTestFiles() { + protected function getTestFiles($testFileBase) { return array(__DIR__ . '/dependencies_test.info.yml'); } diff --git a/coder_sniffer/DrupalPractice/Test/Objects/GlobalClassUnitTest.php b/coder_sniffer/DrupalPractice/Test/Objects/GlobalClassUnitTest.php index 2c83bcc7..3a7d97a8 100644 --- a/coder_sniffer/DrupalPractice/Test/Objects/GlobalClassUnitTest.php +++ b/coder_sniffer/DrupalPractice/Test/Objects/GlobalClassUnitTest.php @@ -1,6 +1,10 @@ <?php -class DrupalPractice_Sniffs_Objects_GlobalClassUnitTest extends CoderSniffUnitTest +namespace DrupalPractice\Sniffs\Objects; + +use Drupal\Test\CoderSniffUnitTest; + +class GlobalClassUnitTest extends CoderSniffUnitTest { @@ -12,7 +16,7 @@ class DrupalPractice_Sniffs_Objects_GlobalClassUnitTest extends CoderSniffUnitTe * * @return array(int => int) */ - protected function getErrorList($testFile) + protected function getErrorList($testFile = NULL) { return array(); @@ -27,13 +31,15 @@ class DrupalPractice_Sniffs_Objects_GlobalClassUnitTest extends CoderSniffUnitTe * * @return array(int => int) */ - protected function getWarningList($testFile) + protected function getWarningList($testFile = NULL) { switch ($testFile) { case 'GlobalClassUnitTest.inc': return array(8 => 1); case 'ExampleService.php': return array(23 => 1); + default: + return []; } }//end getWarningList() @@ -43,7 +49,7 @@ class DrupalPractice_Sniffs_Objects_GlobalClassUnitTest extends CoderSniffUnitTe * * @return array The list of test files. */ - protected function getTestFiles() { + protected function getTestFiles($testFileBase) { return [__DIR__.'/GlobalClassUnitTest.inc', __DIR__.'/src/ExampleService.php']; } diff --git a/coder_sniffer/DrupalPractice/Test/Objects/GlobalDrupalUnitTest.php b/coder_sniffer/DrupalPractice/Test/Objects/GlobalDrupalUnitTest.php index 5350f61c..8eb94ee4 100644 --- a/coder_sniffer/DrupalPractice/Test/Objects/GlobalDrupalUnitTest.php +++ b/coder_sniffer/DrupalPractice/Test/Objects/GlobalDrupalUnitTest.php @@ -1,6 +1,10 @@ <?php -class DrupalPractice_Sniffs_Objects_GlobalDrupalUnitTest extends CoderSniffUnitTest +namespace DrupalPractice\Sniffs\Objects; + +use Drupal\Test\CoderSniffUnitTest; + +class GlobalDrupalUnitTest extends CoderSniffUnitTest { @@ -12,7 +16,7 @@ class DrupalPractice_Sniffs_Objects_GlobalDrupalUnitTest extends CoderSniffUnitT * * @return array(int => int) */ - protected function getErrorList($testFile) + protected function getErrorList($testFile = NULL) { return array(); @@ -27,13 +31,15 @@ class DrupalPractice_Sniffs_Objects_GlobalDrupalUnitTest extends CoderSniffUnitT * * @return array(int => int) */ - protected function getWarningList($testFile) + protected function getWarningList($testFile = NULL) { switch ($testFile) { case 'GlobalDrupalUnitTest.inc': return array(6 => 1); case 'ExampleService.php': return array(16 => 1); + default: + return []; } }//end getWarningList() @@ -44,7 +50,7 @@ class DrupalPractice_Sniffs_Objects_GlobalDrupalUnitTest extends CoderSniffUnitT * * @return array The list of test files. */ - protected function getTestFiles() { + protected function getTestFiles($testFileBase) { return [__DIR__.'/GlobalDrupalUnitTest.inc', __DIR__.'/src/ExampleService.php']; } diff --git a/coder_sniffer/DrupalPractice/Test/Objects/GlobalFunctionUnitTest.php b/coder_sniffer/DrupalPractice/Test/Objects/GlobalFunctionUnitTest.php index a5857e41..6d3e6be7 100644 --- a/coder_sniffer/DrupalPractice/Test/Objects/GlobalFunctionUnitTest.php +++ b/coder_sniffer/DrupalPractice/Test/Objects/GlobalFunctionUnitTest.php @@ -1,6 +1,10 @@ <?php -class DrupalPractice_Sniffs_Objects_GlobalFunctionUnitTest extends CoderSniffUnitTest +namespace DrupalPractice\Sniffs\Objects; + +use Drupal\Test\CoderSniffUnitTest; + +class GlobalFunctionUnitTest extends CoderSniffUnitTest { @@ -12,7 +16,7 @@ class DrupalPractice_Sniffs_Objects_GlobalFunctionUnitTest extends CoderSniffUni * * @return array(int => int) */ - protected function getErrorList($testFile) + protected function getErrorList($testFile = NULL) { return array(); @@ -27,13 +31,15 @@ class DrupalPractice_Sniffs_Objects_GlobalFunctionUnitTest extends CoderSniffUni * * @return array(int => int) */ - protected function getWarningList($testFile) + protected function getWarningList($testFile = NULL) { switch ($testFile) { case 'GlobalFunctionUnitTest.inc': return array(6 => 1); case 'ExampleService.php': return array(30 => 1); + default: + return []; } }//end getWarningList() @@ -44,7 +50,7 @@ class DrupalPractice_Sniffs_Objects_GlobalFunctionUnitTest extends CoderSniffUni * * @return array The list of test files. */ - protected function getTestFiles() { + protected function getTestFiles($testFileBase) { return [__DIR__.'/GlobalFunctionUnitTest.inc', __DIR__.'/src/ExampleService.php']; } diff --git a/coder_sniffer/DrupalPractice/Test/Objects/UnusedPrivateMethodUnitTest.php b/coder_sniffer/DrupalPractice/Test/Objects/UnusedPrivateMethodUnitTest.php index 992a950a..212ba21c 100644 --- a/coder_sniffer/DrupalPractice/Test/Objects/UnusedPrivateMethodUnitTest.php +++ b/coder_sniffer/DrupalPractice/Test/Objects/UnusedPrivateMethodUnitTest.php @@ -1,6 +1,10 @@ <?php -class DrupalPractice_Sniffs_Objects_UnusedPrivateMethodUnitTest extends CoderSniffUnitTest +namespace DrupalPractice\Sniffs\Objects; + +use Drupal\Test\CoderSniffUnitTest; + +class UnusedPrivateMethodUnitTest extends CoderSniffUnitTest { @@ -12,7 +16,7 @@ class DrupalPractice_Sniffs_Objects_UnusedPrivateMethodUnitTest extends CoderSni * * @return array(int => int) */ - protected function getErrorList($testFile) + protected function getErrorList($testFile = NULL) { return array(); @@ -27,7 +31,7 @@ class DrupalPractice_Sniffs_Objects_UnusedPrivateMethodUnitTest extends CoderSni * * @return array(int => int) */ - protected function getWarningList($testFile) + protected function getWarningList($testFile = NULL) { return array(8 => 1); diff --git a/coder_sniffer/DrupalPractice/Test/ProjectDetection/ProjectUnitTest.php b/coder_sniffer/DrupalPractice/Test/ProjectDetection/ProjectUnitTest.php deleted file mode 100644 index 31268b86..00000000 --- a/coder_sniffer/DrupalPractice/Test/ProjectDetection/ProjectUnitTest.php +++ /dev/null @@ -1,79 +0,0 @@ -<?php - -/** - * Tests that project and version detection works. - */ -class ProjectUnitTest extends PHPUnit_Framework_TestCase -{ - - /** - * The mocked file object for testing. - * - * @var PHP_CodeSniffer_File|PHPUnit_Framework_MockObject_MockObject - */ - protected $phpcsFile; - - /** - * {@inheritdoc} - */ - public function setUp() - { - parent::setUp(); - $this->phpcsFile = $this->getMockBuilder('PHP_CodeSniffer_File') - ->disableOriginalConstructor() - ->getMock(); - } - - /** - * Tests the extending classes Sniff class. - */ - public function testInfoFileDetection() - { - $this->phpcsFile->expects($this->any()) - ->method('getFilename') - // The file does not exist, but doesn't matter for this test. - ->will($this->returnValue(dirname(__FILE__) . '/modules/drupal6/test.php')); - - $this->assertEquals(DrupalPractice_Project::getInfoFile($this->phpcsFile), dirname(__FILE__) . '/modules/drupal6/testmodule.info'); - } - - /** - * Tests the extending classes Sniff class. - */ - public function testInfoFileNestedDetection() - { - $this->phpcsFile->expects($this->any()) - ->method('getFilename') - // The file does not exist, but doesn't matter for this test. - ->will($this->returnValue(dirname(__FILE__) . '/modules/drupal6/nested/test.php')); - - $this->assertEquals(DrupalPractice_Project::getInfoFile($this->phpcsFile), dirname(__FILE__) . '/modules/drupal6/testmodule.info'); - } - - /** - * Tests the extending classes Sniff class. - * - * @dataProvider coreVersionProvider - */ - public function testCoreVersion($filename, $core_version) - { - $this->phpcsFile->expects($this->any()) - ->method('getFilename') - // The file does not exist, but doesn't matter for this test. - ->will($this->returnValue($filename)); - - $this->assertEquals(DrupalPractice_Project::getCoreVersion($this->phpcsFile), $core_version); - } - - /** - * Data provider for testCoreVersion(). - */ - public function coreVersionProvider() { - return array( - array(dirname(__FILE__) . '/modules/drupal6/nested/test.php', '6.x'), - array(dirname(__FILE__) . '/modules/drupal7/test.php', '7.x'), - array(dirname(__FILE__) . '/modules/drupal8/test.php', '8.x'), - ); - } - -}//end class diff --git a/coder_sniffer/DrupalPractice/Test/ProjectDetection/modules/drupal6/nested/test.php b/coder_sniffer/DrupalPractice/Test/ProjectDetection/modules/drupal6/nested/test.php deleted file mode 100644 index 31c91e08..00000000 --- a/coder_sniffer/DrupalPractice/Test/ProjectDetection/modules/drupal6/nested/test.php +++ /dev/null @@ -1,4 +0,0 @@ -<?php - -// Empty file for testing purposes. - diff --git a/coder_sniffer/DrupalPractice/Test/ProjectDetection/modules/drupal6/testmodule.info b/coder_sniffer/DrupalPractice/Test/ProjectDetection/modules/drupal6/testmodule.info deleted file mode 100644 index 1098c3a5..00000000 --- a/coder_sniffer/DrupalPractice/Test/ProjectDetection/modules/drupal6/testmodule.info +++ /dev/null @@ -1,4 +0,0 @@ -name = Test module -description = Test -package = Core -core = 6.x diff --git a/coder_sniffer/DrupalPractice/Test/ProjectDetection/modules/drupal7/testmodule.info b/coder_sniffer/DrupalPractice/Test/ProjectDetection/modules/drupal7/testmodule.info deleted file mode 100644 index fd742e8e..00000000 --- a/coder_sniffer/DrupalPractice/Test/ProjectDetection/modules/drupal7/testmodule.info +++ /dev/null @@ -1,6 +0,0 @@ -name = Test module -description = Test -package = Core -core = 7.x -configure = admin/structure/types -stylesheets[all][] = node.css diff --git a/coder_sniffer/DrupalPractice/Test/ProjectDetection/modules/drupal8/testmodule.info.yml b/coder_sniffer/DrupalPractice/Test/ProjectDetection/modules/drupal8/testmodule.info.yml deleted file mode 100644 index b7aecc7c..00000000 --- a/coder_sniffer/DrupalPractice/Test/ProjectDetection/modules/drupal8/testmodule.info.yml +++ /dev/null @@ -1,7 +0,0 @@ -name: Test module -type: module -description: 'Test.' -core: 8.x -configure: node.overview_types -dependencies: -- text diff --git a/coder_sniffer/DrupalPractice/Test/Yaml/RoutingAccessUnitTest.php b/coder_sniffer/DrupalPractice/Test/Yaml/RoutingAccessUnitTest.php index 4651bda1..39a59830 100644 --- a/coder_sniffer/DrupalPractice/Test/Yaml/RoutingAccessUnitTest.php +++ b/coder_sniffer/DrupalPractice/Test/Yaml/RoutingAccessUnitTest.php @@ -1,6 +1,10 @@ <?php -class DrupalPractice_Sniffs_Yaml_RoutingAccessUnitTest extends CoderSniffUnitTest +namespace DrupalPractice\Sniffs\Yaml; + +use Drupal\Test\CoderSniffUnitTest; + +class RoutingAccessUnitTest extends CoderSniffUnitTest { /** @@ -8,7 +12,7 @@ class DrupalPractice_Sniffs_Yaml_RoutingAccessUnitTest extends CoderSniffUnitTes * * @return array The list of test files. */ - protected function getTestFiles() { + protected function getTestFiles($testFileBase) { return [__DIR__.'/routing_access_test.routing.yml']; } @@ -21,7 +25,7 @@ class DrupalPractice_Sniffs_Yaml_RoutingAccessUnitTest extends CoderSniffUnitTes * * @return array(int => int) */ - protected function getErrorList($testFile) + protected function getErrorList($testFile = NULL) { return array(); @@ -36,7 +40,7 @@ class DrupalPractice_Sniffs_Yaml_RoutingAccessUnitTest extends CoderSniffUnitTes * * @return array(int => int) */ - protected function getWarningList($testFile) + protected function getWarningList($testFile = NULL) { return array( 7 => 1, diff --git a/coder_sniffer/DrupalPractice/Test/good/GoodUnitTest.php b/coder_sniffer/DrupalPractice/Test/good/GoodUnitTest.php index 9e46ae15..d03e412c 100644 --- a/coder_sniffer/DrupalPractice/Test/good/GoodUnitTest.php +++ b/coder_sniffer/DrupalPractice/Test/good/GoodUnitTest.php @@ -3,10 +3,14 @@ * Unit test class for all good files that must not throw errors/warnings. */ +namespace DrupalPractice\good; + +use Drupal\Test\CoderSniffUnitTest; + /** * Unit test class for all good files that must not throw errors/warnings. */ -class DrupalPractice_GoodUnitTest extends CoderSniffUnitTest +class GoodUnitTest extends CoderSniffUnitTest { @@ -18,7 +22,7 @@ class DrupalPractice_GoodUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getErrorList($testFile) + public function getErrorList($testFile = NULL) { return array(); @@ -33,7 +37,7 @@ class DrupalPractice_GoodUnitTest extends CoderSniffUnitTest * * @return array(int => int) */ - public function getWarningList($testFile) + public function getWarningList($testFile = NULL) { return array(); @@ -44,9 +48,9 @@ class DrupalPractice_GoodUnitTest extends CoderSniffUnitTest * * @return array The list of test files. */ - protected function getTestFiles() { + protected function getTestFiles($testFileBase) { $dir = dirname(__FILE__); - $di = new DirectoryIterator($dir); + $di = new \DirectoryIterator($dir); foreach ($di as $file) { $path = $file->getPathname(); @@ -65,9 +69,9 @@ class DrupalPractice_GoodUnitTest extends CoderSniffUnitTest * * @return array The list of sniff codes. */ - protected function getSniffCodes() { + protected function allSniffCodes() { // We want to test all sniffs defined in the standard. - return array(); + return TRUE; } diff --git a/composer.json b/composer.json index 769d890b..3e4cdbe4 100644 --- a/composer.json +++ b/composer.json @@ -12,9 +12,15 @@ "require": { "php": ">=5.4.0", "ext-mbstring": "*", - "squizlabs/php_codesniffer": ">=2.8.1 <3.0", + "squizlabs/php_codesniffer": "^3.0.0", "symfony/yaml": ">=2.0.0" }, + "autoload": { + "psr-0": { + "Drupal\\": "coder_sniffer/Drupal/", + "DrupalPractice\\": "coder_sniffer/Drupal/" + } + }, "require-dev": { "phpunit/phpunit": ">=3.7 <6" } diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 0ac2eb72..0e340b15 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -6,7 +6,58 @@ <exclude-pattern>*/Test/*</exclude-pattern> - <rule ref="PHPCS" /> + <!-- 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"> -- GitLab