Skip to content

Commit d70c2a4

Browse files
committed
PSR12/NullableTypeDeclaration: fix sniff to work with the PHP 8 identifier tokens
Includes minor update to pre-existing tests to ensure all identifier name types are covered.
1 parent bbded9b commit d70c2a4

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,17 @@ class NullableTypeDeclarationSniff implements Sniff
2121
* @var array
2222
*/
2323
private $validTokens = [
24-
T_STRING => true,
25-
T_NS_SEPARATOR => true,
26-
T_CALLABLE => true,
27-
T_SELF => true,
28-
T_PARENT => true,
29-
T_STATIC => true,
30-
T_NULL => true,
31-
T_FALSE => true,
32-
T_TRUE => true,
24+
T_STRING => true,
25+
T_NAME_QUALIFIED => true,
26+
T_NAME_FULLY_QUALIFIED => true,
27+
T_NAME_RELATIVE => true,
28+
T_CALLABLE => true,
29+
T_SELF => true,
30+
T_PARENT => true,
31+
T_STATIC => true,
32+
T_NULL => true,
33+
T_FALSE => true,
34+
T_TRUE => true,
3335
];
3436

3537

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ class MyClass {
88
{
99
}
1010

11-
public function validWithFQN(
11+
public function validWithQualifiedNames(
1212
?\MyNameSpace\MyArray $array = null,
13-
?\MyNameSpace\MyObject $object
14-
): ?\MyNameSpace\MyObject
13+
?MyNameSpace\MyObject $object
14+
): ?namespace\MyObject
1515
{
1616
}
1717

@@ -26,10 +26,10 @@ class MyClass {
2626
{
2727
}
2828

29-
public function invalidWithFQNTooMuchWhitespace(
29+
public function invalidWithQualifiedNamesTooMuchWhitespace(
3030
? \MyNameSpace\MyArray $array = null,
31-
? \MyNameSpace\MyObject
32-
):? \MyNameSpace\MyObject
31+
? MyNameSpace\MyObject
32+
):? namespace\MyObject
3333
{
3434
}
3535
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ class MyClass {
88
{
99
}
1010

11-
public function validWithFQN(
11+
public function validWithQualifiedNames(
1212
?\MyNameSpace\MyArray $array = null,
13-
?\MyNameSpace\MyObject $object
14-
): ?\MyNameSpace\MyObject
13+
?MyNameSpace\MyObject $object
14+
): ?namespace\MyObject
1515
{
1616
}
1717

@@ -26,10 +26,10 @@ class MyClass {
2626
{
2727
}
2828

29-
public function invalidWithFQNTooMuchWhitespace(
29+
public function invalidWithQualifiedNamesTooMuchWhitespace(
3030
?\MyNameSpace\MyArray $array = null,
31-
?\MyNameSpace\MyObject
32-
):?\MyNameSpace\MyObject
31+
?MyNameSpace\MyObject
32+
):?namespace\MyObject
3333
{
3434
}
3535
}

0 commit comments

Comments
 (0)