diff --git a/src/Standards/PSR12/Sniffs/Functions/NullableTypeDeclarationSniff.php b/src/Standards/PSR12/Sniffs/Functions/NullableTypeDeclarationSniff.php index 3f18a82179..ac0775d13e 100644 --- a/src/Standards/PSR12/Sniffs/Functions/NullableTypeDeclarationSniff.php +++ b/src/Standards/PSR12/Sniffs/Functions/NullableTypeDeclarationSniff.php @@ -27,6 +27,9 @@ class NullableTypeDeclarationSniff implements Sniff T_SELF => true, T_PARENT => true, T_STATIC => true, + T_NULL => true, + T_FALSE => true, + T_TRUE => true, ]; diff --git a/src/Standards/PSR12/Tests/Functions/NullableTypeDeclarationUnitTest.inc b/src/Standards/PSR12/Tests/Functions/NullableTypeDeclarationUnitTest.inc index e3a5a775f2..056d74c3f2 100644 --- a/src/Standards/PSR12/Tests/Functions/NullableTypeDeclarationUnitTest.inc +++ b/src/Standards/PSR12/Tests/Functions/NullableTypeDeclarationUnitTest.inc @@ -85,3 +85,11 @@ class testInstanceOf() { // PHP 8.0: static return type. function testStatic() : ? static {} + +// PHP 8.2: nullable true/false. +function fooG(): ? true {} +function fooH(): ? + false {} + +// Fatal error: null cannot be marked as nullable, but that's not the concern of this sniff. +function fooI(): ? null {} diff --git a/src/Standards/PSR12/Tests/Functions/NullableTypeDeclarationUnitTest.inc.fixed b/src/Standards/PSR12/Tests/Functions/NullableTypeDeclarationUnitTest.inc.fixed index 6225d1b337..6cc418d074 100644 --- a/src/Standards/PSR12/Tests/Functions/NullableTypeDeclarationUnitTest.inc.fixed +++ b/src/Standards/PSR12/Tests/Functions/NullableTypeDeclarationUnitTest.inc.fixed @@ -83,3 +83,10 @@ class testInstanceOf() { // PHP 8.0: static return type. function testStatic() : ?static {} + +// PHP 8.2: nullable true/false. +function fooG(): ?true {} +function fooH(): ?false {} + +// Fatal error: null cannot be marked as nullable, but that's not the concern of this sniff. +function fooI(): ?null {} diff --git a/src/Standards/PSR12/Tests/Functions/NullableTypeDeclarationUnitTest.php b/src/Standards/PSR12/Tests/Functions/NullableTypeDeclarationUnitTest.php index b4905d3650..da11498ad1 100644 --- a/src/Standards/PSR12/Tests/Functions/NullableTypeDeclarationUnitTest.php +++ b/src/Standards/PSR12/Tests/Functions/NullableTypeDeclarationUnitTest.php @@ -41,6 +41,9 @@ protected function getErrorList() 58 => 2, 59 => 2, 87 => 1, + 90 => 1, + 91 => 1, + 95 => 1, ]; }//end getErrorList()