From ea9a89639b69bf5b77d14f272e0a61565165b9eb Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Wed, 1 Apr 2020 11:42:07 +0200 Subject: [PATCH] :sparkles: Require @return void --- SymfonyCustom/Helpers/AbstractHelper.php | 3 + SymfonyCustom/Helpers/FixerHelper.php | 8 ++ .../Sniffs/Arrays/ArrayDeclarationSniff.php | 8 +- .../Sniffs/Classes/ClassDeclarationSniff.php | 2 + .../Classes/PropertyDeclarationSniff.php | 2 + .../DocCommentForbiddenTagsSniff.php | 2 + .../DocCommentGroupSameTypeSniff.php | 2 + .../Sniffs/Commenting/DocCommentSniff.php | 2 + .../Commenting/FunctionCommentSniff.php | 107 +++++++----------- .../Commenting/VariableCommentSniff.php | 6 + .../Sniffs/Errors/ExceptionMessageSniff.php | 2 + .../Sniffs/Errors/UserDeprecatedSniff.php | 2 + .../Formatting/BlankLineBeforeReturnSniff.php | 2 + .../ConditionalReturnOrThrowSniff.php | 2 + .../Formatting/StrictComparisonSniff.php | 2 + .../Sniffs/Formatting/YodaConditionSniff.php | 2 + .../Sniffs/Functions/ScopeOrderSniff.php | 2 + .../Sniffs/Namespaces/UnusedUseSniff.php | 4 + .../NamingConventions/ValidClassNameSniff.php | 6 + .../NamingConventions/ValidFileNameSniff.php | 2 + .../NamingConventions/ValidTypeHintSniff.php | 2 + .../WhiteSpace/CloseBracketSpacingSniff.php | 2 + .../WhiteSpace/DocCommentTagSpacingSniff.php | 2 + .../Sniffs/WhiteSpace/EmptyLinesSniff.php | 2 + .../WhiteSpace/OpenBracketSpacingSniff.php | 2 + .../WhiteSpace/UnaryOperatorSpacingSniff.php | 2 + .../Commenting/FunctionCommentUnitTest.inc | 31 +++-- .../Commenting/FunctionCommentUnitTest.php | 13 ++- TwigCS/src/Command/TwigCSCommand.php | 3 + TwigCS/src/Config/Config.php | 2 + TwigCS/src/Environment/StubbedEnvironment.php | 3 + TwigCS/src/Report/Report.php | 2 + TwigCS/src/Report/SniffViolation.php | 2 + TwigCS/src/Report/TextFormatter.php | 4 + TwigCS/src/Ruleset/Generic/BlankEOFSniff.php | 2 + .../src/Ruleset/Generic/EmptyLinesSniff.php | 2 + TwigCS/src/Runner/Fixer.php | 8 ++ TwigCS/src/Runner/Linter.php | 6 + TwigCS/src/Sniff/AbstractSniff.php | 17 +++ TwigCS/src/Sniff/AbstractSpacingSniff.php | 6 + TwigCS/src/Sniff/SniffInterface.php | 8 ++ TwigCS/src/Token/Token.php | 2 + TwigCS/src/Token/TokenParser.php | 2 + TwigCS/src/Token/Tokenizer.php | 62 ++++++++++ TwigCS/src/Token/TokenizerHelper.php | 2 + TwigCS/tests/Ruleset/AbstractSniffTest.php | 4 + .../Ruleset/Generic/BlankEOF/BlankEOFTest.php | 3 + .../DelimiterSpacing/DelimiterSpacingTest.php | 3 + .../Generic/EmptyLines/EmptyLinesTest.php | 3 + .../OperatorSpacing/OperatorSpacingTest.php | 3 + TwigCS/tests/TestHelper.php | 3 + .../tests/Token/Tokenizer/TokenizerTest.php | 2 + 52 files changed, 287 insertions(+), 91 deletions(-) diff --git a/SymfonyCustom/Helpers/AbstractHelper.php b/SymfonyCustom/Helpers/AbstractHelper.php index 6b97de8..2ce11da 100644 --- a/SymfonyCustom/Helpers/AbstractHelper.php +++ b/SymfonyCustom/Helpers/AbstractHelper.php @@ -9,6 +9,9 @@ */ abstract class AbstractHelper { + /** + * @return void + */ private function __construct() { } diff --git a/SymfonyCustom/Helpers/FixerHelper.php b/SymfonyCustom/Helpers/FixerHelper.php index 346c30c..408c45b 100644 --- a/SymfonyCustom/Helpers/FixerHelper.php +++ b/SymfonyCustom/Helpers/FixerHelper.php @@ -15,6 +15,8 @@ class FixerHelper extends AbstractHelper * @param File $phpcsFile * @param int $fromPtr * @param int $toPtr + * + * @return void */ public static function removeAll(File $phpcsFile, int $fromPtr, int $toPtr): void { @@ -37,6 +39,8 @@ public static function removeAll(File $phpcsFile, int $fromPtr, int $toPtr): voi * @param int $fromPtr * @param int $fromLine * @param int $toLine + * + * @return void */ public static function removeLines(File $phpcsFile, int $fromPtr, int $fromLine, int $toLine): void { @@ -61,6 +65,8 @@ public static function removeLines(File $phpcsFile, int $fromPtr, int $fromLine, * @param int $stackPtr * @param int $expected * @param int|string $found + * + * @return void */ public static function fixWhitespaceAfter( File $phpcsFile, @@ -92,6 +98,8 @@ public static function fixWhitespaceAfter( * @param int $stackPtr * @param int $expected * @param int|string $found + * + * @return void */ public static function fixWhitespaceBefore( File $phpcsFile, diff --git a/SymfonyCustom/Sniffs/Arrays/ArrayDeclarationSniff.php b/SymfonyCustom/Sniffs/Arrays/ArrayDeclarationSniff.php index 5667c3e..54309f9 100644 --- a/SymfonyCustom/Sniffs/Arrays/ArrayDeclarationSniff.php +++ b/SymfonyCustom/Sniffs/Arrays/ArrayDeclarationSniff.php @@ -28,8 +28,10 @@ public function register(): array } /** - * @param File $phpcsFile The current file being checked. + * @param File $phpcsFile * @param int $stackPtr + * + * @return void */ public function process(File $phpcsFile, $stackPtr): void { @@ -92,6 +94,8 @@ public function process(File $phpcsFile, $stackPtr): void * @param int $stackPtr * @param int $start * @param int $end + * + * @return void */ public function processSingleLineArray(File $phpcsFile, int $stackPtr, int $start, int $end): void { @@ -216,6 +220,8 @@ public function processSingleLineArray(File $phpcsFile, int $stackPtr, int $star * @param int $stackPtr * @param int $start * @param int $end + * + * @return void */ public function processMultiLineArray(File $phpcsFile, int $stackPtr, int $start, int $end): void { diff --git a/SymfonyCustom/Sniffs/Classes/ClassDeclarationSniff.php b/SymfonyCustom/Sniffs/Classes/ClassDeclarationSniff.php index 6c30077..ab4c532 100644 --- a/SymfonyCustom/Sniffs/Classes/ClassDeclarationSniff.php +++ b/SymfonyCustom/Sniffs/Classes/ClassDeclarationSniff.php @@ -22,6 +22,8 @@ public function register(): array /** * @param File $phpcsFile * @param int $stackPtr + * + * @return void */ public function process(File $phpcsFile, $stackPtr): void { diff --git a/SymfonyCustom/Sniffs/Classes/PropertyDeclarationSniff.php b/SymfonyCustom/Sniffs/Classes/PropertyDeclarationSniff.php index edf2f5c..0e13a14 100644 --- a/SymfonyCustom/Sniffs/Classes/PropertyDeclarationSniff.php +++ b/SymfonyCustom/Sniffs/Classes/PropertyDeclarationSniff.php @@ -23,6 +23,8 @@ public function register(): array /** * @param File $phpcsFile * @param int $stackPtr + * + * @return void */ public function process(File $phpcsFile, $stackPtr): void { diff --git a/SymfonyCustom/Sniffs/Commenting/DocCommentForbiddenTagsSniff.php b/SymfonyCustom/Sniffs/Commenting/DocCommentForbiddenTagsSniff.php index 79e34dd..86ca211 100644 --- a/SymfonyCustom/Sniffs/Commenting/DocCommentForbiddenTagsSniff.php +++ b/SymfonyCustom/Sniffs/Commenting/DocCommentForbiddenTagsSniff.php @@ -28,6 +28,8 @@ public function register(): array /** * @param File $phpcsFile * @param int $stackPtr + * + * @return void */ public function process(File $phpcsFile, $stackPtr): void { diff --git a/SymfonyCustom/Sniffs/Commenting/DocCommentGroupSameTypeSniff.php b/SymfonyCustom/Sniffs/Commenting/DocCommentGroupSameTypeSniff.php index d8a84b2..523cb3a 100644 --- a/SymfonyCustom/Sniffs/Commenting/DocCommentGroupSameTypeSniff.php +++ b/SymfonyCustom/Sniffs/Commenting/DocCommentGroupSameTypeSniff.php @@ -25,6 +25,8 @@ public function register(): array /** * @param File $phpcsFile * @param int $stackPtr + * + * @return void */ public function process(File $phpcsFile, $stackPtr): void { diff --git a/SymfonyCustom/Sniffs/Commenting/DocCommentSniff.php b/SymfonyCustom/Sniffs/Commenting/DocCommentSniff.php index 9052067..fb7afb3 100644 --- a/SymfonyCustom/Sniffs/Commenting/DocCommentSniff.php +++ b/SymfonyCustom/Sniffs/Commenting/DocCommentSniff.php @@ -24,6 +24,8 @@ public function register(): array /** * @param File $phpcsFile * @param int $stackPtr + * + * @return void */ public function process(File $phpcsFile, $stackPtr): void { diff --git a/SymfonyCustom/Sniffs/Commenting/FunctionCommentSniff.php b/SymfonyCustom/Sniffs/Commenting/FunctionCommentSniff.php index 6181649..03f58c6 100644 --- a/SymfonyCustom/Sniffs/Commenting/FunctionCommentSniff.php +++ b/SymfonyCustom/Sniffs/Commenting/FunctionCommentSniff.php @@ -16,6 +16,8 @@ class FunctionCommentSniff extends PEARFunctionCommentSniff /** * @param File $phpcsFile * @param int $stackPtr + * + * @return void */ public function process(File $phpcsFile, $stackPtr): void { @@ -68,10 +70,7 @@ public function process(File $phpcsFile, $stackPtr): void } } else { // No comment but maybe a method prefix - $methodPrefixes = $phpcsFile->findFirstOnLine( - Tokens::$methodPrefixes, - $stackPtr - ); + $methodPrefixes = $phpcsFile->findFirstOnLine(Tokens::$methodPrefixes, $stackPtr); if (false !== $methodPrefixes) { $commentStart = $methodPrefixes; @@ -107,51 +106,47 @@ public function process(File $phpcsFile, $stackPtr): void * @param int $stackPtr * @param int|null $commentStart * @param bool $hasComment + * + * @return void */ protected function processReturn(File $phpcsFile, $stackPtr, $commentStart, $hasComment = true): void { - // Check for inheritDoc if there is comment - if ($hasComment && $this->isInheritDoc($phpcsFile, $stackPtr)) { + if (!$hasComment) { + $phpcsFile->addError('Missing @return tag in function comment', $stackPtr, 'MissingReturn'); + + return; + } + + // Check for inheritDoc + if ($this->isInheritDoc($phpcsFile, $stackPtr)) { return; } $tokens = $phpcsFile->getTokens(); - // Only check for a return comment if a non-void return statement exists - if (isset($tokens[$stackPtr]['scope_opener'])) { - // Start inside the function - $start = $phpcsFile->findNext( - T_OPEN_CURLY_BRACKET, - $stackPtr, - $tokens[$stackPtr]['scope_closer'] - ); - - for ($i = $start; $i < $tokens[$stackPtr]['scope_closer']; ++$i) { - // Skip closures - if (T_CLOSURE === $tokens[$i]['code']) { - $i = $tokens[$i]['scope_closer']; - continue; + $return = null; + foreach ($tokens[$commentStart]['comment_tags'] as $tag) { + if ('@return' === $tokens[$tag]['content']) { + if (null !== $return) { + $error = 'Only 1 @return tag is allowed in a function comment'; + $phpcsFile->addError($error, $tag, 'DuplicateReturn'); + + return; } - // Found a return not in a closure statement - // Run the check on the first which is not only 'return;' - if (T_RETURN === $tokens[$i]['code'] - && $this->isMatchingReturn($tokens, $i) - ) { - if ($hasComment) { - parent::processReturn($phpcsFile, $stackPtr, $commentStart); - } else { - // There is no doc and we need one with @return - $phpcsFile->addError( - 'Missing @return tag in function comment', - $stackPtr, - 'MissingReturn' - ); - } + $return = $tag; + } + } - break; - } + if (null !== $return) { + $content = $tokens[($return + 2)]['content']; + if (!$content || T_DOC_COMMENT_STRING !== $tokens[($return + 2)]['code']) { + $error = 'Return type missing for @return tag in function comment'; + $phpcsFile->addError($error, $return, 'MissingReturnType'); } + } else { + $error = 'Missing @return tag in function comment'; + $phpcsFile->addError($error, $tokens[$commentStart]['comment_closer'], 'MissingReturn'); } } @@ -159,6 +154,8 @@ protected function processReturn(File $phpcsFile, $stackPtr, $commentStart, $has * @param File $phpcsFile * @param int $stackPtr * @param int $commentStart + * + * @return void */ protected function processThrows(File $phpcsFile, $stackPtr, $commentStart): void { @@ -181,28 +178,15 @@ protected function processThrows(File $phpcsFile, $stackPtr, $commentStart): voi } } - if (null !== $throw) { - $exception = null; - if (T_DOC_COMMENT_STRING === $tokens[$throw + 2]['code']) { - $matches = []; - preg_match('/([^\s]+)(?:\s+(.*))?/', $tokens[$throw + 2]['content'], $matches); - $exception = $matches[1]; - } - - if (null === $exception) { - $phpcsFile->addError( - 'Exception type missing for @throws tag in function comment', - $throw, - 'InvalidThrows' - ); - } - } + parent::processThrows($phpcsFile, $stackPtr, $commentStart); } /** * @param File $phpcsFile * @param int $stackPtr * @param int $commentStart + * + * @return void */ protected function processParams(File $phpcsFile, $stackPtr, $commentStart): void { @@ -226,21 +210,6 @@ private function isInheritDoc(File $phpcsFile, int $stackPtr): bool $content = $phpcsFile->getTokensAsString($start, ($end - $start)); - return preg_match('#{@inheritdoc}#i', $content) === 1; - } - - /** - * @param array $tokens - * @param int $returnPos - * - * @return bool - */ - private function isMatchingReturn(array $tokens, int $returnPos): bool - { - do { - $returnPos++; - } while (T_WHITESPACE === $tokens[$returnPos]['code']); - - return T_SEMICOLON !== $tokens[$returnPos]['code']; + return preg_match('#@inheritdoc|{@inheritdoc}#i', $content) === 1; } } diff --git a/SymfonyCustom/Sniffs/Commenting/VariableCommentSniff.php b/SymfonyCustom/Sniffs/Commenting/VariableCommentSniff.php index d96ac83..036b2d6 100644 --- a/SymfonyCustom/Sniffs/Commenting/VariableCommentSniff.php +++ b/SymfonyCustom/Sniffs/Commenting/VariableCommentSniff.php @@ -15,6 +15,8 @@ class VariableCommentSniff extends AbstractVariableSniff /** * @param File $phpcsFile * @param int $stackPtr + * + * @return void */ public function processMemberVar(File $phpcsFile, $stackPtr): void { @@ -115,6 +117,8 @@ public function processMemberVar(File $phpcsFile, $stackPtr): void /** * @param File $phpcsFile * @param int $stackPtr + * + * @return void */ protected function processVariable(File $phpcsFile, $stackPtr): void { @@ -123,6 +127,8 @@ protected function processVariable(File $phpcsFile, $stackPtr): void /** * @param File $phpcsFile * @param int $stackPtr + * + * @return void */ protected function processVariableInString(File $phpcsFile, $stackPtr): void { diff --git a/SymfonyCustom/Sniffs/Errors/ExceptionMessageSniff.php b/SymfonyCustom/Sniffs/Errors/ExceptionMessageSniff.php index 63d83c8..3d92619 100644 --- a/SymfonyCustom/Sniffs/Errors/ExceptionMessageSniff.php +++ b/SymfonyCustom/Sniffs/Errors/ExceptionMessageSniff.php @@ -23,6 +23,8 @@ public function register(): array /** * @param File $phpcsFile * @param int $stackPtr + * + * @return void */ public function process(File $phpcsFile, $stackPtr): void { diff --git a/SymfonyCustom/Sniffs/Errors/UserDeprecatedSniff.php b/SymfonyCustom/Sniffs/Errors/UserDeprecatedSniff.php index 4b5b0ac..675320b 100644 --- a/SymfonyCustom/Sniffs/Errors/UserDeprecatedSniff.php +++ b/SymfonyCustom/Sniffs/Errors/UserDeprecatedSniff.php @@ -23,6 +23,8 @@ public function register(): array /** * @param File $phpcsFile * @param int $stackPtr + * + * @return void */ public function process(File $phpcsFile, $stackPtr): void { diff --git a/SymfonyCustom/Sniffs/Formatting/BlankLineBeforeReturnSniff.php b/SymfonyCustom/Sniffs/Formatting/BlankLineBeforeReturnSniff.php index 78c81ed..4f845eb 100644 --- a/SymfonyCustom/Sniffs/Formatting/BlankLineBeforeReturnSniff.php +++ b/SymfonyCustom/Sniffs/Formatting/BlankLineBeforeReturnSniff.php @@ -24,6 +24,8 @@ public function register(): array /** * @param File $phpcsFile * @param int $stackPtr + * + * @return void */ public function process(File $phpcsFile, $stackPtr): void { diff --git a/SymfonyCustom/Sniffs/Formatting/ConditionalReturnOrThrowSniff.php b/SymfonyCustom/Sniffs/Formatting/ConditionalReturnOrThrowSniff.php index 7dd2618..de28d22 100644 --- a/SymfonyCustom/Sniffs/Formatting/ConditionalReturnOrThrowSniff.php +++ b/SymfonyCustom/Sniffs/Formatting/ConditionalReturnOrThrowSniff.php @@ -23,6 +23,8 @@ public function register(): array /** * @param File $phpcsFile * @param int $stackPtr + * + * @return void */ public function process(File $phpcsFile, $stackPtr): void { diff --git a/SymfonyCustom/Sniffs/Formatting/StrictComparisonSniff.php b/SymfonyCustom/Sniffs/Formatting/StrictComparisonSniff.php index 939ff85..87837c7 100644 --- a/SymfonyCustom/Sniffs/Formatting/StrictComparisonSniff.php +++ b/SymfonyCustom/Sniffs/Formatting/StrictComparisonSniff.php @@ -33,6 +33,8 @@ public function register(): array /** * @param File $phpcsFile * @param int $stackPtr + * + * @return void */ public function process(File $phpcsFile, $stackPtr): void { diff --git a/SymfonyCustom/Sniffs/Formatting/YodaConditionSniff.php b/SymfonyCustom/Sniffs/Formatting/YodaConditionSniff.php index 5300c37..3ed8308 100644 --- a/SymfonyCustom/Sniffs/Formatting/YodaConditionSniff.php +++ b/SymfonyCustom/Sniffs/Formatting/YodaConditionSniff.php @@ -24,6 +24,8 @@ public function register(): array /** * @param File $phpcsFile * @param int $stackPtr + * + * @return void */ public function process(File $phpcsFile, $stackPtr): void { diff --git a/SymfonyCustom/Sniffs/Functions/ScopeOrderSniff.php b/SymfonyCustom/Sniffs/Functions/ScopeOrderSniff.php index cc1c630..e18c61f 100644 --- a/SymfonyCustom/Sniffs/Functions/ScopeOrderSniff.php +++ b/SymfonyCustom/Sniffs/Functions/ScopeOrderSniff.php @@ -28,6 +28,8 @@ public function register(): array /** * @param File $phpcsFile * @param int $stackPtr + * + * @return void */ public function process(File $phpcsFile, $stackPtr): void { diff --git a/SymfonyCustom/Sniffs/Namespaces/UnusedUseSniff.php b/SymfonyCustom/Sniffs/Namespaces/UnusedUseSniff.php index dc5c920..c6d9850 100644 --- a/SymfonyCustom/Sniffs/Namespaces/UnusedUseSniff.php +++ b/SymfonyCustom/Sniffs/Namespaces/UnusedUseSniff.php @@ -25,6 +25,8 @@ public function register(): array /** * @param File $phpcsFile * @param int $stackPtr + * + * @return void */ public function process(File $phpcsFile, $stackPtr): void { @@ -180,6 +182,8 @@ public function process(File $phpcsFile, $stackPtr): void * @param File $phpcsFile * @param int $from * @param int $to + * + * @return void */ private function removeUse(File $phpcsFile, int $from, int $to): void { diff --git a/SymfonyCustom/Sniffs/NamingConventions/ValidClassNameSniff.php b/SymfonyCustom/Sniffs/NamingConventions/ValidClassNameSniff.php index 2603444..86716a4 100644 --- a/SymfonyCustom/Sniffs/NamingConventions/ValidClassNameSniff.php +++ b/SymfonyCustom/Sniffs/NamingConventions/ValidClassNameSniff.php @@ -28,6 +28,8 @@ public function register() /** * @param File $phpcsFile * @param int $stackPtr + * + * @return void */ public function process(File $phpcsFile, $stackPtr): void { @@ -84,6 +86,8 @@ public function process(File $phpcsFile, $stackPtr): void * @param int $stackPtr * @param int|bool $name * @param string $prefix + * + * @return void */ private function checkPrefix(File $phpcsFile, int $stackPtr, $name, string $prefix): void { @@ -103,6 +107,8 @@ private function checkPrefix(File $phpcsFile, int $stackPtr, $name, string $pref * @param int $stackPtr * @param int|bool $name * @param string $suffix + * + * @return void */ private function checkSuffix(File $phpcsFile, int $stackPtr, $name, string $suffix): void { diff --git a/SymfonyCustom/Sniffs/NamingConventions/ValidFileNameSniff.php b/SymfonyCustom/Sniffs/NamingConventions/ValidFileNameSniff.php index df360de..f676997 100644 --- a/SymfonyCustom/Sniffs/NamingConventions/ValidFileNameSniff.php +++ b/SymfonyCustom/Sniffs/NamingConventions/ValidFileNameSniff.php @@ -23,6 +23,8 @@ public function register() /** * @param File $phpcsFile * @param int $stackPtr + * + * @return void */ public function process(File $phpcsFile, $stackPtr): void { diff --git a/SymfonyCustom/Sniffs/NamingConventions/ValidTypeHintSniff.php b/SymfonyCustom/Sniffs/NamingConventions/ValidTypeHintSniff.php index 7983f42..0a4c11d 100644 --- a/SymfonyCustom/Sniffs/NamingConventions/ValidTypeHintSniff.php +++ b/SymfonyCustom/Sniffs/NamingConventions/ValidTypeHintSniff.php @@ -121,6 +121,8 @@ public function register(): array /** * @param File $phpcsFile * @param int $stackPtr + * + * @return void */ public function process(File $phpcsFile, $stackPtr): void { diff --git a/SymfonyCustom/Sniffs/WhiteSpace/CloseBracketSpacingSniff.php b/SymfonyCustom/Sniffs/WhiteSpace/CloseBracketSpacingSniff.php index a59582f..553b1a9 100644 --- a/SymfonyCustom/Sniffs/WhiteSpace/CloseBracketSpacingSniff.php +++ b/SymfonyCustom/Sniffs/WhiteSpace/CloseBracketSpacingSniff.php @@ -25,6 +25,8 @@ public function register(): array /** * @param File $phpcsFile * @param int $stackPtr + * + * @return void */ public function process(File $phpcsFile, $stackPtr): void { diff --git a/SymfonyCustom/Sniffs/WhiteSpace/DocCommentTagSpacingSniff.php b/SymfonyCustom/Sniffs/WhiteSpace/DocCommentTagSpacingSniff.php index 4486f09..81f8345 100644 --- a/SymfonyCustom/Sniffs/WhiteSpace/DocCommentTagSpacingSniff.php +++ b/SymfonyCustom/Sniffs/WhiteSpace/DocCommentTagSpacingSniff.php @@ -24,6 +24,8 @@ public function register(): array /** * @param File $phpcsFile * @param int $stackPtr + * + * @return void */ public function process(File $phpcsFile, $stackPtr): void { diff --git a/SymfonyCustom/Sniffs/WhiteSpace/EmptyLinesSniff.php b/SymfonyCustom/Sniffs/WhiteSpace/EmptyLinesSniff.php index 0654cc4..3fe5412 100644 --- a/SymfonyCustom/Sniffs/WhiteSpace/EmptyLinesSniff.php +++ b/SymfonyCustom/Sniffs/WhiteSpace/EmptyLinesSniff.php @@ -23,6 +23,8 @@ public function register(): array /** * @param File $phpcsFile * @param int $stackPtr + * + * @return void */ public function process(File $phpcsFile, $stackPtr): void { diff --git a/SymfonyCustom/Sniffs/WhiteSpace/OpenBracketSpacingSniff.php b/SymfonyCustom/Sniffs/WhiteSpace/OpenBracketSpacingSniff.php index 638458b..9a5b27c 100644 --- a/SymfonyCustom/Sniffs/WhiteSpace/OpenBracketSpacingSniff.php +++ b/SymfonyCustom/Sniffs/WhiteSpace/OpenBracketSpacingSniff.php @@ -24,6 +24,8 @@ public function register(): array /** * @param File $phpcsFile * @param int $stackPtr + * + * @return void */ public function process(File $phpcsFile, $stackPtr): void { diff --git a/SymfonyCustom/Sniffs/WhiteSpace/UnaryOperatorSpacingSniff.php b/SymfonyCustom/Sniffs/WhiteSpace/UnaryOperatorSpacingSniff.php index febc82c..452c13e 100644 --- a/SymfonyCustom/Sniffs/WhiteSpace/UnaryOperatorSpacingSniff.php +++ b/SymfonyCustom/Sniffs/WhiteSpace/UnaryOperatorSpacingSniff.php @@ -23,6 +23,8 @@ public function register(): array /** * @param File $phpcsFile * @param int $stackPtr + * + * @return void */ public function process(File $phpcsFile, $stackPtr): void { diff --git a/SymfonyCustom/Tests/Commenting/FunctionCommentUnitTest.inc b/SymfonyCustom/Tests/Commenting/FunctionCommentUnitTest.inc index f75ee39..40f5eb8 100644 --- a/SymfonyCustom/Tests/Commenting/FunctionCommentUnitTest.inc +++ b/SymfonyCustom/Tests/Commenting/FunctionCommentUnitTest.inc @@ -38,6 +38,10 @@ function functionTestWithCallBack($tab) class classToTestIndentation { + function __construct() // do not ignore + { + } + /** * @param string $test Test Argument */ @@ -56,6 +60,8 @@ class classToTestIndentation /** * @param array $tab Test Argument + * + * @return void */ function functionTestWithCallBack($tab) { @@ -66,7 +72,7 @@ class classToTestIndentation } /** - * #{@inheritdoc} + * {@inheritdoc} */ function functionTestInherit($test) { @@ -79,32 +85,21 @@ function testToNotIgnore1($test) } /** - * @param string $test should not be ignore + * @param int $test Test argument */ function testToNotIgnore2($test) { return 42; } -function testToIgnore1() -{ - $test = 42; -} -function testToIgnore2() -{ - $test = 42; -} - -function toIgnore1() -{ - $test = 42; -} -function toIgnore2() +function toNotIgnore() { $test = 42; } /** + * @return void + * * @throws Exception */ function throwTest() @@ -113,6 +108,8 @@ function throwTest() } /** + * @return void + * * @throws Exception|RuntimeException */ function throwTest2() @@ -121,6 +118,8 @@ function throwTest2() } /** + * @return void + * * @throws Exception * @throws RuntimeException */ diff --git a/SymfonyCustom/Tests/Commenting/FunctionCommentUnitTest.php b/SymfonyCustom/Tests/Commenting/FunctionCommentUnitTest.php index 39aa263..a26b334 100644 --- a/SymfonyCustom/Tests/Commenting/FunctionCommentUnitTest.php +++ b/SymfonyCustom/Tests/Commenting/FunctionCommentUnitTest.php @@ -19,11 +19,14 @@ protected function getErrorList(): array return [ 5 => 1, 10 => 1, - 43 => 1, - 48 => 1, - 76 => 2, - 83 => 1, - 125 => 1, + 31 => 1, + 41 => 1, + 47 => 1, + 52 => 1, + 82 => 2, + 89 => 1, + 95 => 1, + 124 => 1, ]; } diff --git a/TwigCS/src/Command/TwigCSCommand.php b/TwigCS/src/Command/TwigCSCommand.php index 7fb7793..a484aa6 100644 --- a/TwigCS/src/Command/TwigCSCommand.php +++ b/TwigCS/src/Command/TwigCSCommand.php @@ -25,6 +25,9 @@ */ class TwigCSCommand extends Command { + /** + * @return void + */ protected function configure(): void { $this diff --git a/TwigCS/src/Config/Config.php b/TwigCS/src/Config/Config.php index 06ef16e..164b312 100644 --- a/TwigCS/src/Config/Config.php +++ b/TwigCS/src/Config/Config.php @@ -18,6 +18,8 @@ class Config /** * @param array $paths + * + * @return void */ public function __construct(array $paths = []) { diff --git a/TwigCS/src/Environment/StubbedEnvironment.php b/TwigCS/src/Environment/StubbedEnvironment.php index a28ece0..e81e996 100644 --- a/TwigCS/src/Environment/StubbedEnvironment.php +++ b/TwigCS/src/Environment/StubbedEnvironment.php @@ -39,6 +39,9 @@ class StubbedEnvironment extends Environment 'same' => null, // Allow 'same as' ]; + /** + * @return void + */ public function __construct() { parent::__construct(new ArrayLoader()); diff --git a/TwigCS/src/Report/Report.php b/TwigCS/src/Report/Report.php index 20684e6..2544917 100644 --- a/TwigCS/src/Report/Report.php +++ b/TwigCS/src/Report/Report.php @@ -95,6 +95,8 @@ public function getMessages(array $filters = []): array /** * @param string $file + * + * @return void */ public function addFile(string $file): void { diff --git a/TwigCS/src/Report/SniffViolation.php b/TwigCS/src/Report/SniffViolation.php index 0f9040b..01b3d69 100644 --- a/TwigCS/src/Report/SniffViolation.php +++ b/TwigCS/src/Report/SniffViolation.php @@ -52,6 +52,8 @@ class SniffViolation * @param string $message * @param string $filename * @param int|null $line + * + * @return void */ public function __construct(int $level, string $message, string $filename, int $line = null) { diff --git a/TwigCS/src/Report/TextFormatter.php b/TwigCS/src/Report/TextFormatter.php index 3b0a70d..e066ea8 100644 --- a/TwigCS/src/Report/TextFormatter.php +++ b/TwigCS/src/Report/TextFormatter.php @@ -28,6 +28,8 @@ class TextFormatter /** * @param InputInterface $input * @param OutputInterface $output + * + * @return void */ public function __construct(InputInterface $input, OutputInterface $output) { @@ -37,6 +39,8 @@ public function __construct(InputInterface $input, OutputInterface $output) /** * @param Report $report * @param string|null $level + * + * @return void */ public function display(Report $report, string $level = null): void { diff --git a/TwigCS/src/Ruleset/Generic/BlankEOFSniff.php b/TwigCS/src/Ruleset/Generic/BlankEOFSniff.php index 0ecb29b..ec0589d 100644 --- a/TwigCS/src/Ruleset/Generic/BlankEOFSniff.php +++ b/TwigCS/src/Ruleset/Generic/BlankEOFSniff.php @@ -17,6 +17,8 @@ class BlankEOFSniff extends AbstractSniff * @param int $tokenPosition * @param Token[] $tokens * + * @return void + * * @throws Exception */ public function process(int $tokenPosition, array $tokens): void diff --git a/TwigCS/src/Ruleset/Generic/EmptyLinesSniff.php b/TwigCS/src/Ruleset/Generic/EmptyLinesSniff.php index 0ebaffa..9e791bd 100644 --- a/TwigCS/src/Ruleset/Generic/EmptyLinesSniff.php +++ b/TwigCS/src/Ruleset/Generic/EmptyLinesSniff.php @@ -17,6 +17,8 @@ class EmptyLinesSniff extends AbstractSniff * @param int $tokenPosition * @param Token[] $tokens * + * @return void + * * @throws Exception */ public function process(int $tokenPosition, array $tokens): void diff --git a/TwigCS/src/Runner/Fixer.php b/TwigCS/src/Runner/Fixer.php index 043a177..c39cfc3 100644 --- a/TwigCS/src/Runner/Fixer.php +++ b/TwigCS/src/Runner/Fixer.php @@ -109,6 +109,8 @@ public function __construct(Ruleset $ruleset, Tokenizer $tokenizer) /** * @param array $tokens + * + * @return void */ public function startFile(array $tokens): void { @@ -182,6 +184,8 @@ public function getContents(): string /** * Start recording actions for a changeset. + * + * @return void */ public function beginChangeset(): void { @@ -195,6 +199,8 @@ public function beginChangeset(): void /** * Stop recording actions for a changeset, and apply logged changes. + * + * @return void */ public function endChangeset(): void { @@ -227,6 +233,8 @@ public function endChangeset(): void /** * Stop recording actions for a changeset, and discard logged changes. + * + * @return void */ public function rollbackChangeset(): void { diff --git a/TwigCS/src/Runner/Linter.php b/TwigCS/src/Runner/Linter.php index 31e8b25..a563e4d 100644 --- a/TwigCS/src/Runner/Linter.php +++ b/TwigCS/src/Runner/Linter.php @@ -32,6 +32,8 @@ class Linter /** * @param Environment $env * @param Tokenizer $tokenizer + * + * @return void */ public function __construct(Environment $env, Tokenizer $tokenizer) { @@ -84,6 +86,8 @@ public function run(array $files, Ruleset $ruleset, bool $fix = false): Report * @param iterable $files * @param Ruleset $ruleset * + * @return void + * * @throws Exception */ protected function fix(iterable $files, Ruleset $ruleset): void @@ -160,6 +164,8 @@ protected function processTemplate(string $file, Ruleset $ruleset, Report $repor /** * @param Report $report * @param string|null $file + * + * @return void */ protected function setErrorHandler(Report $report, string $file = null): void { diff --git a/TwigCS/src/Sniff/AbstractSniff.php b/TwigCS/src/Sniff/AbstractSniff.php index 569221e..fe43578 100644 --- a/TwigCS/src/Sniff/AbstractSniff.php +++ b/TwigCS/src/Sniff/AbstractSniff.php @@ -27,6 +27,8 @@ abstract class AbstractSniff implements SniffInterface /** * @param Report $report + * + * @return void */ public function enableReport(Report $report): void { @@ -35,12 +37,17 @@ public function enableReport(Report $report): void /** * @param Fixer $fixer + * + * @return void */ public function enableFixer(Fixer $fixer): void { $this->fixer = $fixer; } + /** + * @return void + */ public function disable(): void { $this->report = null; @@ -49,6 +56,8 @@ public function disable(): void /** * @param array $stream + * + * @return void */ public function processFile(array $stream): void { @@ -60,6 +69,8 @@ public function processFile(array $stream): void /** * @param int $tokenPosition * @param Token[] $stream + * + * @return void */ abstract protected function process(int $tokenPosition, array $stream): void; @@ -132,6 +143,8 @@ protected function findPrevious($type, array $tokens, int $start, bool $exclude * @param string $message * @param Token $token * + * @return void + * * @throws Exception */ protected function addWarning(string $message, Token $token): void @@ -143,6 +156,8 @@ protected function addWarning(string $message, Token $token): void * @param string $message * @param Token $token * + * @return void + * * @throws Exception */ protected function addError(string $message, Token $token): void @@ -181,6 +196,8 @@ protected function addFixableError(string $message, Token $token): bool * @param string $message * @param Token $token * + * @return void + * * @throws Exception */ private function addMessage(int $messageType, string $message, Token $token): void diff --git a/TwigCS/src/Sniff/AbstractSpacingSniff.php b/TwigCS/src/Sniff/AbstractSpacingSniff.php index 4e1e153..3620cb4 100644 --- a/TwigCS/src/Sniff/AbstractSpacingSniff.php +++ b/TwigCS/src/Sniff/AbstractSpacingSniff.php @@ -16,6 +16,8 @@ abstract class AbstractSpacingSniff extends AbstractSniff * @param int $tokenPosition * @param Token[] $tokens * + * @return void + * * @throws Exception */ public function process(int $tokenPosition, array $tokens): void @@ -53,6 +55,8 @@ abstract protected function shouldHaveSpaceBefore(int $tokenPosition, array $tok * @param Token[] $tokens * @param int $expected * + * @return void + * * @throws Exception */ private function checkSpaceAfter(int $tokenPosition, array $tokens, int $expected): void @@ -92,6 +96,8 @@ private function checkSpaceAfter(int $tokenPosition, array $tokens, int $expecte * @param Token[] $tokens * @param int $expected * + * @return void + * * @throws Exception */ private function checkSpaceBefore(int $tokenPosition, array $tokens, int $expected): void diff --git a/TwigCS/src/Sniff/SniffInterface.php b/TwigCS/src/Sniff/SniffInterface.php index 4d4b5a9..844f15c 100644 --- a/TwigCS/src/Sniff/SniffInterface.php +++ b/TwigCS/src/Sniff/SniffInterface.php @@ -18,21 +18,29 @@ interface SniffInterface * Messages will be added to the given `$report` object. * * @param Report $report + * + * @return void */ public function enableReport(Report $report): void; /** * @param Fixer $fixer + * + * @return void */ public function enableFixer(Fixer $fixer): void; /** * It usually is disabled when the processing is over, it will reset the sniff internal values for next check. + * + * @return void */ public function disable(): void; /** * @param Token[] $stream + * + * @return void */ public function processFile(array $stream): void; } diff --git a/TwigCS/src/Token/Token.php b/TwigCS/src/Token/Token.php index 8cdf50e..bcb2363 100644 --- a/TwigCS/src/Token/Token.php +++ b/TwigCS/src/Token/Token.php @@ -86,6 +86,8 @@ class Token * @param int $position * @param string $filename * @param string|null $value + * + * @return void */ public function __construct( int $type, diff --git a/TwigCS/src/Token/TokenParser.php b/TwigCS/src/Token/TokenParser.php index 90b50af..9b9cb21 100644 --- a/TwigCS/src/Token/TokenParser.php +++ b/TwigCS/src/Token/TokenParser.php @@ -22,6 +22,8 @@ class TokenParser extends AbstractTokenParser /** * @param string $name + * + * @return void */ public function __construct(string $name) { diff --git a/TwigCS/src/Token/Tokenizer.php b/TwigCS/src/Token/Tokenizer.php index 3447529..c9239dc 100644 --- a/TwigCS/src/Token/Tokenizer.php +++ b/TwigCS/src/Token/Tokenizer.php @@ -93,6 +93,8 @@ class Tokenizer /** * @param Environment $env * @param array $options + * + * @return void */ public function __construct(Environment $env, array $options = []) { @@ -178,6 +180,8 @@ public function tokenize(Source $source): array /** * @param Source $source + * + * @return void */ protected function resetState(Source $source): void { @@ -204,6 +208,8 @@ protected function getState(): int /** * @param int $state * @param array $data + * + * @return void */ protected function pushState(int $state, array $data = []): void { @@ -214,6 +220,8 @@ protected function pushState(int $state, array $data = []): void * @param string $name * @param mixed $value * + * @return void + * * @throws Exception */ protected function setStateParam($name, $value): void @@ -234,6 +242,8 @@ protected function getStateParams(): array } /** + * @return void + * * @throws Exception */ protected function popState(): void @@ -246,6 +256,8 @@ protected function popState(): void /** * @param string $code + * + * @return void */ protected function preflightSource(string $code): void { @@ -282,6 +294,8 @@ protected function getTokenPosition(int $offset = 0): ?array /** * @param int $value + * + * @return void */ protected function moveCurrentPosition(int $value = 1): void { @@ -290,6 +304,8 @@ protected function moveCurrentPosition(int $value = 1): void /** * @param string $value + * + * @return void */ protected function moveCursor(string $value): void { @@ -300,6 +316,8 @@ protected function moveCursor(string $value): void /** * @param int $type * @param string|null $value + * + * @return void */ protected function pushToken(int $type, string $value = null): void { @@ -308,6 +326,8 @@ protected function pushToken(int $type, string $value = null): void } /** + * @return void + * * @throws Exception */ protected function lexExpression(): void @@ -341,6 +361,8 @@ protected function lexExpression(): void } /** + * @return void + * * @throws Exception */ protected function lexBlock(): void @@ -359,6 +381,8 @@ protected function lexBlock(): void } /** + * @return void + * * @throws Exception */ protected function lexVariable(): void @@ -377,6 +401,8 @@ protected function lexVariable(): void } /** + * @return void + * * @throws Exception */ protected function lexComment(): void @@ -399,6 +425,8 @@ protected function lexComment(): void } /** + * @return void + * * @throws Exception */ protected function lexDqString(): void @@ -426,6 +454,8 @@ protected function lexDqString(): void } /** + * @return void + * * @throws Exception */ protected function lexInterpolation(): void @@ -446,6 +476,8 @@ protected function lexInterpolation(): void /** * @param int $limit + * + * @return void */ protected function lexData(int $limit = 0): void { @@ -486,6 +518,8 @@ protected function lexData(int $limit = 0): void } /** + * @return void + * * @throws Exception */ protected function lexStart(): void @@ -509,6 +543,9 @@ protected function lexStart(): void $this->moveCursor($tokenStart['fullMatch']); } + /** + * @return void + */ protected function lexStartDqString(): void { $this->bracketsAndTernary[] = ['"', $this->line]; @@ -517,6 +554,9 @@ protected function lexStartDqString(): void $this->moveCursor('"'); } + /** + * @return void + */ protected function lexStartInterpolation(): void { $this->bracketsAndTernary[] = [$this->options['interpolation'][0], $this->line]; @@ -525,6 +565,9 @@ protected function lexStartInterpolation(): void $this->moveCursor($this->options['interpolation'][0]); } + /** + * @return void + */ protected function lexTab(): void { $currentToken = $this->code[$this->cursor]; @@ -543,6 +586,9 @@ protected function lexTab(): void } } + /** + * @return void + */ protected function lexWhitespace(): void { $currentToken = $this->code[$this->cursor]; @@ -561,6 +607,9 @@ protected function lexWhitespace(): void } } + /** + * @return void + */ protected function lexEOL(): void { if (self::STATE_COMMENT === $this->getState()) { @@ -572,6 +621,9 @@ protected function lexEOL(): void $this->moveCursor($this->code[$this->cursor]); } + /** + * @return void + */ protected function lexArrowFunction(): void { $this->pushToken(Token::ARROW_TYPE, '=>'); @@ -580,6 +632,8 @@ protected function lexArrowFunction(): void /** * @param string $operator + * + * @return void */ protected function lexOperator(string $operator): void { @@ -596,6 +650,8 @@ protected function lexOperator(string $operator): void /** * @param string $name * + * @return void + * * @throws Exception */ protected function lexName(string $name): void @@ -612,6 +668,8 @@ protected function lexName(string $name): void /** * @param string $numberAsString + * + * @return void */ protected function lexNumber(string $numberAsString): void { @@ -625,6 +683,8 @@ protected function lexNumber(string $numberAsString): void } /** + * @return void + * * @throws Exception */ protected function lexPunctuation(): void @@ -667,6 +727,8 @@ protected function lexPunctuation(): void /** * @param string $string + * + * @return void */ protected function lexString(string $string): void { diff --git a/TwigCS/src/Token/TokenizerHelper.php b/TwigCS/src/Token/TokenizerHelper.php index 52b9aaa..15160d4 100644 --- a/TwigCS/src/Token/TokenizerHelper.php +++ b/TwigCS/src/Token/TokenizerHelper.php @@ -24,6 +24,8 @@ class TokenizerHelper /** * @param Environment $env * @param array $options + * + * @return void */ public function __construct(Environment $env, array $options = []) { diff --git a/TwigCS/tests/Ruleset/AbstractSniffTest.php b/TwigCS/tests/Ruleset/AbstractSniffTest.php index 132b240..cdb58e1 100644 --- a/TwigCS/tests/Ruleset/AbstractSniffTest.php +++ b/TwigCS/tests/Ruleset/AbstractSniffTest.php @@ -23,12 +23,16 @@ abstract class AbstractSniffTest extends TestCase { /** * Should call $this->checkSniff(new Sniff(), [...]); + * + * @return void */ abstract public function testSniff(): void; /** * @param SniffInterface $sniff * @param array $expects + * + * @return void */ protected function checkSniff(SniffInterface $sniff, array $expects): void { diff --git a/TwigCS/tests/Ruleset/Generic/BlankEOF/BlankEOFTest.php b/TwigCS/tests/Ruleset/Generic/BlankEOF/BlankEOFTest.php index 1be86f7..d124f0f 100644 --- a/TwigCS/tests/Ruleset/Generic/BlankEOF/BlankEOFTest.php +++ b/TwigCS/tests/Ruleset/Generic/BlankEOF/BlankEOFTest.php @@ -12,6 +12,9 @@ */ class BlankEOFTest extends AbstractSniffTest { + /** + * @return void + */ public function testSniff(): void { $this->checkSniff(new BlankEOFSniff(), [ diff --git a/TwigCS/tests/Ruleset/Generic/DelimiterSpacing/DelimiterSpacingTest.php b/TwigCS/tests/Ruleset/Generic/DelimiterSpacing/DelimiterSpacingTest.php index e11bd7d..820ff14 100644 --- a/TwigCS/tests/Ruleset/Generic/DelimiterSpacing/DelimiterSpacingTest.php +++ b/TwigCS/tests/Ruleset/Generic/DelimiterSpacing/DelimiterSpacingTest.php @@ -12,6 +12,9 @@ */ class DelimiterSpacingTest extends AbstractSniffTest { + /** + * @return void + */ public function testSniff(): void { $this->checkSniff(new DelimiterSpacingSniff(), [ diff --git a/TwigCS/tests/Ruleset/Generic/EmptyLines/EmptyLinesTest.php b/TwigCS/tests/Ruleset/Generic/EmptyLines/EmptyLinesTest.php index 95203bd..50aedb2 100644 --- a/TwigCS/tests/Ruleset/Generic/EmptyLines/EmptyLinesTest.php +++ b/TwigCS/tests/Ruleset/Generic/EmptyLines/EmptyLinesTest.php @@ -12,6 +12,9 @@ */ class EmptyLinesTest extends AbstractSniffTest { + /** + * @return void + */ public function testSniff(): void { $this->checkSniff(new EmptyLinesSniff(), [ diff --git a/TwigCS/tests/Ruleset/Generic/OperatorSpacing/OperatorSpacingTest.php b/TwigCS/tests/Ruleset/Generic/OperatorSpacing/OperatorSpacingTest.php index 28c2889..916610f 100644 --- a/TwigCS/tests/Ruleset/Generic/OperatorSpacing/OperatorSpacingTest.php +++ b/TwigCS/tests/Ruleset/Generic/OperatorSpacing/OperatorSpacingTest.php @@ -12,6 +12,9 @@ */ class OperatorSpacingTest extends AbstractSniffTest { + /** + * @return void + */ public function testSniff(): void { $this->checkSniff(new OperatorSpacingSniff(), [ diff --git a/TwigCS/tests/TestHelper.php b/TwigCS/tests/TestHelper.php index 75017cb..c20167f 100644 --- a/TwigCS/tests/TestHelper.php +++ b/TwigCS/tests/TestHelper.php @@ -9,6 +9,9 @@ */ class TestHelper { + /** + * @return void + */ private function __construct() { } diff --git a/TwigCS/tests/Token/Tokenizer/TokenizerTest.php b/TwigCS/tests/Token/Tokenizer/TokenizerTest.php index f312a42..ccd58c8 100644 --- a/TwigCS/tests/Token/Tokenizer/TokenizerTest.php +++ b/TwigCS/tests/Token/Tokenizer/TokenizerTest.php @@ -20,6 +20,8 @@ class TokenizerTest extends TestCase * @param string $filePath * @param array $expectedTokenTypes * + * @return void + * * @throws \Exception * * @dataProvider tokenizeDataProvider