Skip to content

Commit 8aedfdc

Browse files
committed
Fix Null sniff
1 parent bff737e commit 8aedfdc

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

PhpCollective/Sniffs/Commenting/DocBlockParamAllowDefaultValueSniff.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ public function process(File $phpCsFile, $stackPointer): void
148148

149149
if ($methodSignatureValue['nullable']) {
150150
$type = 'null';
151-
152-
if (!in_array($type, $parts, true)) {
151+
if (!in_array($type, $parts, true) && !$this->hasShorthand($parts)) {
153152
$parts[] = $type;
154153
$error = 'Doc block error: `' . $content . '` seems to be missing type `' . $type . '`.';
155154
$fix = $phpCsFile->addFixableError($error, $classNameIndex, 'Nullable');
@@ -262,4 +261,20 @@ protected function isClassString(string $type, array $parts): bool
262261

263262
return false;
264263
}
264+
265+
/**
266+
* @param array<string> $parts
267+
*
268+
* @return bool
269+
*/
270+
protected function hasShorthand(array $parts): bool
271+
{
272+
foreach ($parts as $part) {
273+
if (str_starts_with($part, '?')) {
274+
return true;
275+
}
276+
}
277+
278+
return false;
279+
}
265280
}

0 commit comments

Comments
 (0)