Skip to content

Commit e7286b9

Browse files
committed
NullableTypeForNullDefaultValueSniff: Fixed false positive
1 parent 0858034 commit e7286b9

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

SlevomatCodingStandard/Sniffs/TypeHints/NullableTypeForNullDefaultValueSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function process(File $phpcsFile, $functionPointer): void
9797
continue;
9898
}
9999

100-
if (preg_match('~(?:^|\|)null(?:\||$)~i', $typeHint) === 1) {
100+
if (preg_match('~(?:^|(?:\|\s*))null(?:(?:\s*\|)|$)~i', $typeHint) === 1) {
101101
continue;
102102
}
103103

tests/Sniffs/TypeHints/data/nullableTypeForNullDefaultValueNoErrors.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ public function unionTypeHint(string|null $union = null)
8080
{
8181
}
8282

83+
public function unionTypeHintWithSpace(string | null $union = null)
84+
{
85+
}
86+
87+
public function unionTypeHintWithSpaceInTheMiddle(string|null |int $union = null)
88+
{
89+
}
90+
8391
}
8492

8593
array_map(

0 commit comments

Comments
 (0)