function AnnotationHelper::isAnnotationUseless
*
Parameters
array<int, string> $traversableTypeHints:
4 calls to AnnotationHelper::isAnnotationUseless()
- ParameterTypeHintSniff::checkUselessAnnotations in vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ TypeHints/ ParameterTypeHintSniff.php - *
- PropertyTypeHintSniff::checkUselessAnnotation in vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ TypeHints/ PropertyTypeHintSniff.php - ReturnTypeHintSniff::checkFunctionUselessAnnotation in vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ TypeHints/ ReturnTypeHintSniff.php - UselessFunctionDocCommentSniff::process in vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ Commenting/ UselessFunctionDocCommentSniff.php - * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
File
-
vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Helpers/ AnnotationHelper.php, line 189
Class
- AnnotationHelper
- @internal
Namespace
SlevomatCodingStandard\HelpersCode
public static function isAnnotationUseless(File $phpcsFile, int $functionPointer, ?TypeHint $typeHint, Annotation $annotation, array $traversableTypeHints, bool $enableUnionTypeHint = false, bool $enableIntersectionTypeHint = false, bool $enableStandaloneNullTrueFalseTypeHints = false) : bool {
if ($annotation->isInvalid()) {
return false;
}
if ($typeHint === null) {
return false;
}
/** @var ParamTagValueNode|TypelessParamTagValueNode|ReturnTagValueNode|VarTagValueNode $annotationValue */
$annotationValue = $annotation->getValue();
if ($annotationValue->description !== '') {
return false;
}
if ($annotationValue instanceof TypelessParamTagValueNode) {
return true;
}
$annotationType = $annotationValue->type;
if (TypeHintHelper::isTraversableType(TypeHintHelper::getFullyQualifiedTypeHint($phpcsFile, $functionPointer, $typeHint->getTypeHintWithoutNullabilitySymbol()), $traversableTypeHints) && !($annotationType instanceof IdentifierTypeNode && TypeHintHelper::isSimpleIterableTypeHint(strtolower($annotationType->name)))) {
return false;
}
if (AnnotationTypeHelper::containsStaticOrThisType($annotationType)) {
return false;
}
if (AnnotationTypeHelper::containsJustTwoTypes($annotationType) || $enableUnionTypeHint && ($annotationType instanceof UnionTypeNode || $annotationType instanceof IdentifierTypeNode && TypeHintHelper::isUnofficialUnionTypeHint($annotationType->name)) || $enableIntersectionTypeHint && $annotationType instanceof IntersectionTypeNode) {
$annotationTypeHint = AnnotationTypeHelper::print($annotationType);
return TypeHintHelper::typeHintEqualsAnnotation($phpcsFile, $functionPointer, $typeHint->getTypeHint(), $annotationTypeHint);
}
if ($annotationType instanceof ObjectShapeNode) {
return false;
}
if ($annotationType instanceof ConstTypeNode) {
return false;
}
if ($annotationType instanceof GenericTypeNode) {
return false;
}
if ($annotationType instanceof CallableTypeNode) {
return false;
}
if ($annotationType instanceof ConditionalTypeNode) {
return false;
}
if ($annotationType instanceof ConditionalTypeForParameterNode) {
return false;
}
if ($annotationType instanceof IdentifierTypeNode) {
if (in_array(strtolower($annotationType->name), [
'true',
'false',
'null',
], true)) {
return $enableStandaloneNullTrueFalseTypeHints;
}
if (in_array(strtolower($annotationType->name), [
'class-string',
'trait-string',
'callable-string',
'numeric-string',
'non-empty-string',
'non-falsy-string',
'literal-string',
'positive-int',
'negative-int',
], true)) {
return false;
}
}
$annotationTypeHint = AnnotationTypeHelper::getTypeHintFromOneType($annotationType);
return TypeHintHelper::typeHintEqualsAnnotation($phpcsFile, $functionPointer, $typeHint->getTypeHintWithoutNullabilitySymbol(), $annotationTypeHint);
}