Skip to content

Commit 549243a

Browse files
committed
Fix DefaultValue sniff
1 parent feae4cb commit 549243a

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

PhpCollective/Sniffs/Commenting/DocBlockParamAllowDefaultValueSniff.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public function process(File $phpCsFile, $stackPointer): void
129129
!in_array($type, $parts, true)
130130
&& !$this->isPrimitiveGenerics($type, $parts)
131131
&& !$this->isClassString($type, $parts)
132+
&& !$this->isBoolish($type, $parts)
132133
) {
133134
$parts[] = $type;
134135
$error = 'Possible doc block error: `' . $content . '` seems to be missing type `' . $type . '`.';
@@ -263,6 +264,29 @@ protected function isClassString(string $type, array $parts): bool
263264
return false;
264265
}
265266

267+
/**
268+
* @param string $type
269+
* @param array<string> $parts
270+
*
271+
* @return bool
272+
*/
273+
protected function isBoolish(string $type, array $parts): bool
274+
{
275+
if ($type !== 'bool') {
276+
return false;
277+
}
278+
279+
if (in_array('false', $parts, true)) {
280+
return true;
281+
}
282+
283+
if (in_array('true', $parts, true)) {
284+
return true;
285+
}
286+
287+
return false;
288+
}
289+
266290
/**
267291
* @param array<string> $parts
268292
*

PhpCollective/Traits/SignatureTrait.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@ protected function getMethodSignature(File $phpCsFile, int $stackPtr): array
4040
$default = 'string';
4141
} elseif ($tokens[$defaultIndex]['code'] === T_OPEN_SHORT_ARRAY) {
4242
$default = 'array';
43-
} elseif ($tokens[$defaultIndex]['code'] === T_FALSE) {
44-
$default = 'false';
45-
} elseif ($tokens[$defaultIndex]['code'] === T_TRUE) {
46-
$default = 'true';
43+
} elseif ($tokens[$defaultIndex]['code'] === T_FALSE || $tokens[$defaultIndex]['code'] === T_TRUE) {
44+
$default = 'bool';
4745
} elseif ($tokens[$defaultIndex]['code'] === T_LNUMBER) {
4846
$default = 'int';
4947
} elseif ($tokens[$defaultIndex]['code'] === T_DNUMBER) {

0 commit comments

Comments
 (0)