diff --git a/src/InterNations/Sniffs/ControlStructures/SwitchDeclarationSniff.php b/src/InterNations/Sniffs/ControlStructures/SwitchDeclarationSniff.php index b7672f6..51c4d4b 100644 --- a/src/InterNations/Sniffs/ControlStructures/SwitchDeclarationSniff.php +++ b/src/InterNations/Sniffs/ControlStructures/SwitchDeclarationSniff.php @@ -84,8 +84,8 @@ public function process(File $file, $stackPtr) $caseCount = 0; $foundDefault = false; - while (($nextCase = $file->findNext([T_CASE, T_DEFAULT, T_SWITCH], ($nextCase + 1), $switch['scope_closer']) - ) !== false + while (($nextCase = $file->findNext([T_CASE, T_DEFAULT, T_SWITCH], ($nextCase + 1), $switch['scope_closer'])) + !== false ) { // Skip nested SWITCH statements; they are handled on their own. if ($tokens[$nextCase]['code'] === T_SWITCH) { diff --git a/src/InterNations/Sniffs/Formatting/ExpressionFormattingSniff.php b/src/InterNations/Sniffs/Formatting/ExpressionFormattingSniff.php index b4e85e0..4cd8827 100644 --- a/src/InterNations/Sniffs/Formatting/ExpressionFormattingSniff.php +++ b/src/InterNations/Sniffs/Formatting/ExpressionFormattingSniff.php @@ -60,6 +60,7 @@ public function process(File $file, $stackPtr) null, true ); + if (in_array($tokens[$returnTypePos]['code'], [T_STRING, T_CALLABLE, T_SELF])) { $closingPtr = $returnTypePos; } @@ -163,6 +164,7 @@ public function process(File $file, $stackPtr) if ($tokens[$nextPtr]['code'] === T_COLON) { $endPtr = $nextPtr; + while (!in_array($tokens[$endPtr]['code'], [T_STRING, T_CALLABLE, T_SELF])) { ++$endPtr; } diff --git a/src/InterNations/Sniffs/Naming/ConstantNameSniff.php b/src/InterNations/Sniffs/Naming/ConstantNameSniff.php index 7be283d..40ed89e 100644 --- a/src/InterNations/Sniffs/Naming/ConstantNameSniff.php +++ b/src/InterNations/Sniffs/Naming/ConstantNameSniff.php @@ -198,6 +198,13 @@ public function process(File $file, $stackPtr) return; } + // Is this a return type + $prevPtrColon = $file->findPrevious([T_WHITESPACE, T_NULLABLE], ($stackPtr - 1), null, true); + + if ($tokens[$prevPtrColon]['code'] === T_COLON) { + return; + } + // Is this a goto label target? if ($tokens[$nextPtr]['code'] === T_COLON) { if (in_array($tokens[$prevPtr]['code'], [T_SEMICOLON, T_OPEN_CURLY_BRACKET, T_COLON], true)) { diff --git a/src/InterNations/Sniffs/Syntax/MethodTypeHintsSniff.php b/src/InterNations/Sniffs/Syntax/MethodTypeHintsSniff.php index be4df92..e7a62db 100644 --- a/src/InterNations/Sniffs/Syntax/MethodTypeHintsSniff.php +++ b/src/InterNations/Sniffs/Syntax/MethodTypeHintsSniff.php @@ -420,8 +420,8 @@ public function process(File $file, $stackPtr) if (!in_array( $tokens[$file->findNext(T_COLON, $endBracket)+2]['code'], - [T_NULLABLE, T_STRING, T_CALLABLE, T_SELF]) - ) { + [T_NULLABLE, T_STRING, T_CALLABLE, T_SELF] + )) { $error = 'Expected exactly one space after colon, multiple spaces or no space found for the return type'; $file->addError($error, $namePtr, 'WrongStyleTypeHint');