diff --git a/src/Standards/PSR12/Sniffs/Functions/ReturnTypeDeclarationSniff.php b/src/Standards/PSR12/Sniffs/Functions/ReturnTypeDeclarationSniff.php index c26877baae..6326b1438e 100644 --- a/src/Standards/PSR12/Sniffs/Functions/ReturnTypeDeclarationSniff.php +++ b/src/Standards/PSR12/Sniffs/Functions/ReturnTypeDeclarationSniff.php @@ -59,6 +59,10 @@ public function process(File $phpcsFile, $stackPtr) } $returnType = $methodProperties['return_type_token']; + if ($methodProperties['nullable_return_type'] === true) { + $returnType = $phpcsFile->findPrevious(T_NULLABLE, ($returnType - 1)); + } + if ($tokens[($returnType - 1)]['code'] !== T_WHITESPACE || $tokens[($returnType - 1)]['content'] !== ' ' || $tokens[($returnType - 2)]['code'] !== T_COLON diff --git a/src/Standards/PSR12/Tests/Functions/ReturnTypeDeclarationUnitTest.inc b/src/Standards/PSR12/Tests/Functions/ReturnTypeDeclarationUnitTest.inc index d3c68e39ab..45b043f16e 100644 --- a/src/Standards/PSR12/Tests/Functions/ReturnTypeDeclarationUnitTest.inc +++ b/src/Standards/PSR12/Tests/Functions/ReturnTypeDeclarationUnitTest.inc @@ -54,3 +54,9 @@ public function functionName(int $arg1, $arg2) /* can't fix */ : string {} public function functionName(int $arg1, $arg2) /* can't fix */ : // phpcs:ignore Standard.Category.Sniff string {} + +function functionName(?string $arg1, ?int &$arg2): ?string {} +function functionName(?string $arg1, ?int &$arg2):?string {} +function functionName(?string $arg1, ?int &$arg2): ?string {} +function functionName(?string $arg1, ?int &$arg2): +?string {} diff --git a/src/Standards/PSR12/Tests/Functions/ReturnTypeDeclarationUnitTest.inc.fixed b/src/Standards/PSR12/Tests/Functions/ReturnTypeDeclarationUnitTest.inc.fixed index 4584ee1d17..531508e75b 100644 --- a/src/Standards/PSR12/Tests/Functions/ReturnTypeDeclarationUnitTest.inc.fixed +++ b/src/Standards/PSR12/Tests/Functions/ReturnTypeDeclarationUnitTest.inc.fixed @@ -51,3 +51,8 @@ public function functionName(int $arg1, $arg2) /* can't fix */ : string {} public function functionName(int $arg1, $arg2) /* can't fix */ : // phpcs:ignore Standard.Category.Sniff string {} + +function functionName(?string $arg1, ?int &$arg2): ?string {} +function functionName(?string $arg1, ?int &$arg2): ?string {} +function functionName(?string $arg1, ?int &$arg2): ?string {} +function functionName(?string $arg1, ?int &$arg2): ?string {} diff --git a/src/Standards/PSR12/Tests/Functions/ReturnTypeDeclarationUnitTest.php b/src/Standards/PSR12/Tests/Functions/ReturnTypeDeclarationUnitTest.php index 92b951881a..7849035e79 100644 --- a/src/Standards/PSR12/Tests/Functions/ReturnTypeDeclarationUnitTest.php +++ b/src/Standards/PSR12/Tests/Functions/ReturnTypeDeclarationUnitTest.php @@ -34,6 +34,9 @@ protected function getErrorList() 52 => 1, 55 => 1, 56 => 1, + 59 => 1, + 60 => 1, + 62 => 1, ]; }//end getErrorList()