Skip to content

Commit 3099054

Browse files
jrfnlgsherwood
authored andcommitted
PSR12/NullableTypeDeclaration: allow for static return type
PHP 8.0 introduces `static` as a valid return type. This adds support for handling this to the `PSR12.Functions.NullableTypeDeclaration` sniff. Includes unit test.
1 parent e9d1081 commit 3099054

File tree

4 files changed

+8
-0
lines changed

4 files changed

+8
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class NullableTypeDeclarationSniff implements Sniff
2626
T_CALLABLE => true,
2727
T_SELF => true,
2828
T_PARENT => true,
29+
T_STATIC => true,
2930
];
3031

3132

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,6 @@ class testInstanceOf() {
8282
$bal = $value instanceof static ? CONSTANT_NAME : $value;
8383
}
8484
}
85+
86+
// PHP 8.0: static return type.
87+
function testStatic() : ? static {}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,6 @@ class testInstanceOf() {
8080
$bal = $value instanceof static ? CONSTANT_NAME : $value;
8181
}
8282
}
83+
84+
// PHP 8.0: static return type.
85+
function testStatic() : ?static {}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ protected function getErrorList()
4040
57 => 2,
4141
58 => 2,
4242
59 => 2,
43+
87 => 1,
4344
];
4445

4546
}//end getErrorList()

0 commit comments

Comments
 (0)