Skip to content

Commit f70a6bc

Browse files
committed
PHP 8.2 | PSR12/NullableTypeDeclaration: allow for nullable true/false
As of PHP 8.2, `true`, `false` and `null` will be allowed as stand-alone types. The `true` and the `false` types are allowed to be nullable, the `null` type is not (but that's not the concern of the sniff). Also see: https://3v4l.org/ZpfID This adjusts the sniff to take these new types into account. Includes unit tests. Refs: * https://wiki.php.net/rfc/null-false-standalone-types * https://wiki.php.net/rfc/true-type
1 parent b8f5f63 commit f70a6bc

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

src/Standards/PSR12/Sniffs/Functions/NullableTypeDeclarationSniff.php

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class NullableTypeDeclarationSniff implements Sniff
2727
T_SELF => true,
2828
T_PARENT => true,
2929
T_STATIC => true,
30+
T_NULL => true,
31+
T_FALSE => true,
32+
T_TRUE => true,
3033
];
3134

3235

src/Standards/PSR12/Tests/Functions/NullableTypeDeclarationUnitTest.inc

+8
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,11 @@ class testInstanceOf() {
8585

8686
// PHP 8.0: static return type.
8787
function testStatic() : ? static {}
88+
89+
// PHP 8.2: nullable true/false.
90+
function fooG(): ? true {}
91+
function fooH(): ?
92+
false {}
93+
94+
// Fatal error: null cannot be marked as nullable, but that's not the concern of this sniff.
95+
function fooI(): ? null {}

src/Standards/PSR12/Tests/Functions/NullableTypeDeclarationUnitTest.inc.fixed

+7
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,10 @@ class testInstanceOf() {
8383

8484
// PHP 8.0: static return type.
8585
function testStatic() : ?static {}
86+
87+
// PHP 8.2: nullable true/false.
88+
function fooG(): ?true {}
89+
function fooH(): ?false {}
90+
91+
// Fatal error: null cannot be marked as nullable, but that's not the concern of this sniff.
92+
function fooI(): ?null {}

src/Standards/PSR12/Tests/Functions/NullableTypeDeclarationUnitTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ protected function getErrorList()
4141
58 => 2,
4242
59 => 2,
4343
87 => 1,
44+
90 => 1,
45+
91 => 1,
46+
95 => 1,
4447
];
4548

4649
}//end getErrorList()

0 commit comments

Comments
 (0)