Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion SlevomatCodingStandard/Helpers/AnnotationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public static function isAnnotationUseless(
['true', 'false', 'null'],
true,
)) {
return $enableStandaloneNullTrueFalseTypeHints;
return $typeHint->getTypeHint() === strtolower($annotationType->name) ? $enableStandaloneNullTrueFalseTypeHints : false;
}

if (TypeHintHelper::isSimpleUnofficialTypeHints(
Expand Down
25 changes: 25 additions & 0 deletions SlevomatCodingStandard/Sniffs/TypeHints/ReturnTypeHintSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,31 @@ private function checkFunctionTypeHint(
}
}

if (
$this->enableStandaloneNullTrueFalseTypeHints
&& $returnTypeHint->getTypeHint() === 'bool'
&& $returnTypeNode instanceof IdentifierTypeNode
&& in_array(strtolower($returnTypeNode->name), ['true', 'false'], true)
) {
$fix = $phpcsFile->addFixableError(
sprintf(
'%s %s() has return type hint "bool" but it should be possible to use "%s" based on @return annotation "%s".',
FunctionHelper::getTypeLabel($phpcsFile, $functionPointer),
FunctionHelper::getFullyQualifiedName($phpcsFile, $functionPointer),
strtolower($returnTypeNode->name),
AnnotationTypeHelper::print($returnTypeNode),
),
$functionPointer,
self::CODE_LESS_SPECIFIC_NATIVE_TYPE_HINT,
);

if ($fix) {
$phpcsFile->fixer->beginChangeset();
FixerHelper::replace($phpcsFile, $returnTypeHint->getStartPointer(), strtolower($returnTypeNode->name));
$phpcsFile->fixer->endChangeset();
}
}

return;
}

Expand Down
Loading