PhpDoc
Dokumentační komentáře /** */ čtou PHPStan i editor, takže na jejich obsahu záleží. Sekce
phpdoc rozhoduje, co z nich zmizí (třeba @author nebo @param, který jen opakuje
nativní typ), jak se v nich píšou typy a co je v nich nejspíš chyba.
Klíče forbiddenAnnotations a forbiddenLines odstraní, co projekt v komentářích mít nechce,
annotation.nativeTypeOnly anotaci, která jen opakuje nativní typ signatury, a klíče pod types
sjednotí zápis typů. Komentář, ve kterém po odstranění nic nezbude, zmizí celý. Další klíče pod
annotation, třeba extraParam, duplicateReturn, duplicateVar a
empty, hlásí, co odporuje signatuře nebo samo sobě: @param neexistujícího parametru, druhé
@return nebo anotaci bez obsahu.
phpdoc:
forbiddenAnnotations: ['@author']
empty: forbidden
annotation:
nativeTypeOnly: forbidden
property:
lineSpan: collapsed
types:
builtin: canonical
class Cart
{
/**
* @author John
* @var integer[]
*/
private array $items = []; // Annotation `@author` is forbidden. // The doc comment with a single annotation must be written on one line. // The type `integer` in a doc comment must be written `int`.
/**
* @param string $name
* @return void
*/
public function add(string $name): void // Useless `@param` annotation for the parameter `$name`, because the native type says the same. // Useless `@return` annotation, because the native return type says the same.
{
}
}
class Cart
{
/** @var int[] */
private array $items = [];
public function add(string $name): void
{
}
}
O typech, které deklaruje sám kód, rozhoduje sekce types. Jméno třídy zmíněné v komentáři se vždy počítá jako použití svého importu, takže úklid importů takový import neodstraní.
phpdoc.empty
An empty doc comment, which is removed.
forbidden: never therekeep: nic se nevynucuje, kód zůstane, jak je
Výchozí keep · standardy: perCs keep, psr12 keep, nette
forbidden, symfony forbidden, laravel forbidden ·
pokrývá no_empty_phpdoc
phpdoc.inheritdocOnly
A doc comment of @inheritDoc alone.
forbidden: never therekeep: nic se nevynucuje, kód zůstane, jak je
Výchozí keep · standardy: perCs keep, psr12 keep, nette
forbidden, symfony keep, laravel keep · pokrývá
phpdoc_no_useless_inheritdoc, SlevomatCodingStandard.Commenting.UselessInheritDocComment
phpdoc.aboveAttributes
The doc comment stands above the attributes.
required: always therekeep: nic se nevynucuje, kód zůstane, jak je
Výchozí keep · standardy: perCs required, psr12 keep, nette
required, symfony keep, laravel keep ·
pokrývá SlevomatCodingStandard.Attributes.RequireAttributeAfterDocComment
phpdoc.stars
The * opening each line of a doc comment.
aligned: each*below the first*of the opening/**keep: nic se nevynucuje, kód zůstane, jak je
Výchozí keep · standardy: perCs keep, psr12 keep, nette
aligned, symfony keep, laravel aligned · pokrývá align_multiline_comment,
phpdoc_indent, Squiz.Commenting.DocCommentAlignment
phpdoc.blankLines
The blank lines inside a doc comment.
trimmed: none at the start or the end, at most one in a row insidekeep: nic se nevynucuje, kód zůstane, jak je
Výchozí keep · standardy: perCs keep, psr12 keep, nette
trimmed, symfony trimmed, laravel trimmed · pokrývá
phpdoc_trim, phpdoc_trim_consecutive_blank_line_separation
phpdoc.forbiddenLines
The patterns of the lines of a description removed from doc comments, such as ~^Created by \S+\.\z~i, what a
pattern matches going and the line with it where nothing else is left.
- seznam regulárních výrazů
keep: nic se nevynucuje, kód zůstane, jak je
Výchozí keep · standardy: perCs keep, psr12 keep, nette
['~^(?:(?!private|protected|static)\S+ )?(?:con|de)structor\.\z~i', '~^\S+ [gs]etter\.\z~i'], symfony
keep, laravel keep · pokrývá SlevomatCodingStandard.Commenting.ForbiddenComments
phpdoc.annotation.casing
The letter case of a known annotation.
canonical: as it is known,@inheritDoc,@phpstan-varkeep: nic se nevynucuje, kód zůstane, jak je
Výchozí keep · standardy: perCs keep, psr12 keep, nette
canonical, symfony keep, laravel keep · pokrývá
phpdoc_tag_casing, SlevomatCodingStandard.Commenting.AnnotationName
phpdoc.annotation.empty
A @param, @return, @var or @see without content.
forbidden: never therekeep: nic se nevynucuje, kód zůstane, jak je
Výchozí keep · standardy: perCs keep, psr12 keep, nette
forbidden, symfony keep, laravel keep ·
pokrývá Squiz.Commenting.VariableComment
phpdoc.annotation.extraParam
A @param naming a parameter the function does not have.
forbidden: never therekeep: nic se nevynucuje, kód zůstane, jak je
Výchozí keep · standardy: perCs keep, psr12 keep, nette
forbidden, symfony keep, laravel keep ·
pokrývá Squiz.Commenting.FunctionComment.ExtraParamComment
phpdoc.annotation.duplicateParam
A second @param of one parameter.
forbidden: never therekeep: nic se nevynucuje, kód zůstane, jak je
Výchozí keep · standardy: perCs keep, psr12 keep, nette
forbidden, symfony keep, laravel keep
phpdoc.annotation.duplicateReturn
A second @return of a function.
forbidden: never therekeep: nic se nevynucuje, kód zůstane, jak je
Výchozí keep · standardy: perCs keep, psr12 keep, nette
forbidden, symfony keep, laravel keep ·
pokrývá Squiz.Commenting.FunctionComment.DuplicateReturn
phpdoc.annotation.duplicateVar
A second @var of a property.
forbidden: never therekeep: nic se nevynucuje, kód zůstane, jak je
Výchozí keep · standardy: perCs keep, psr12 keep, nette
forbidden, symfony keep, laravel keep ·
pokrývá Squiz.Commenting.VariableComment
phpdoc.annotation.nativeTypeOnly
A @param, @return or @var without a description that says only the native type.
forbidden: never therekeep: nic se nevynucuje, kód zůstane, jak je
Výchozí keep · standardy: perCs keep, psr12 keep, nette
forbidden, symfony keep, laravel forbidden · pokrývá
no_superfluous_phpdoc_tags, SlevomatCodingStandard.Commenting.UselessFunctionDocComment,
SlevomatCodingStandard.TypeHints.ParameterTypeHint,
SlevomatCodingStandard.TypeHints.PropertyTypeHint, SlevomatCodingStandard.TypeHints.ReturnTypeHint
phpdoc.annotation.itemTypes
An array, iterable or traversable declaration has an annotation saying what its items are, reported.
required: always therekeep: nic se nevynucuje, kód zůstane, jak je
Výchozí keep · standardy: perCs keep, psr12 keep, nette
keep, symfony keep, laravel keep · pokrývá
SlevomatCodingStandard.TypeHints.ParameterTypeHint,
SlevomatCodingStandard.TypeHints.PropertyTypeHint, SlevomatCodingStandard.TypeHints.ReturnTypeHint
phpdoc.annotation.constantVar
A @var on a class constant that says nothing.
forbidden: never therekeep: nic se nevynucuje, kód zůstane, jak je
Výchozí keep · standardy: perCs keep, psr12 keep, nette
forbidden, symfony keep, laravel keep ·
pokrývá SlevomatCodingStandard.TypeHints.UselessConstantTypeHint
phpdoc.annotation.inlineVar
An inline @var says what assert($x instanceof Foo) checks.
forbidden: never therekeep: nic se nevynucuje, kód zůstane, jak je
Výchozí keep · standardy: perCs keep, psr12 keep, nette
forbidden, symfony keep, laravel keep ·
pokrývá SlevomatCodingStandard.PHP.RequireExplicitAssertion
phpdoc.annotation.plainComment
An annotation in a plain comment, /* @var */ or /**@var without the blank, where a doc comment means
it: any annotation above a declaration, an inline @var above another statement.
forbidden: never therekeep: nic se nevynucuje, kód zůstane, jak je
Výchozí keep · standardy: perCs keep, psr12 keep, nette
forbidden, symfony keep, laravel keep ·
pokrývá SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.InvalidCommentType
phpdoc.forbiddenAnnotations
The annotations removed from doc comments, written with the @, such as @author and
@package.
- seznam jmen
keep: nic se nevynucuje, kód zůstane, jak je
Výchozí keep · standardy: perCs keep, psr12 keep, nette
[@access, @author, @copyright, @created, @license, @package, @since, @subpackage, @todo, @version], symfony
keep, laravel [@access, @package, @subpackage] · pokrývá
general_phpdoc_annotation_remove, phpdoc_no_access,
phpdoc_no_package, SlevomatCodingStandard.Commenting.ForbiddenAnnotations
phpdoc.types.builtin
How a built-in type in a doc comment is written, int and never integer or Int.
canonical: the short lowercase name of a built-in type,neverforno-returnkeep: nic se nevynucuje, kód zůstane, jak je
Výchozí keep · standardy: perCs keep, psr12 keep, nette
canonical, symfony canonical, laravel canonical · pokrývá
PhpCsFixerCustomFixers/phpdoc_type_list, phpdoc_list_type, phpdoc_scalar,
phpdoc_types, SlevomatCodingStandard.TypeHints.LongTypeHints
phpdoc.types.duplicate
A type a union of a doc comment names twice, int|integer.
forbidden: never therekeep: nic se nevynucuje, kód zůstane, jak je
Výchozí keep · standardy: perCs keep, psr12 keep, nette
forbidden, symfony forbidden, laravel keep · pokrývá
phpdoc_no_duplicate_types, phpdoc_types_no_duplicates
phpdoc.types.nullable
How a type of a doc comment of one type and null is written.
'?T': a single type withnullwritten with?'T|null': a union withnull, whichphpdoc.types.nullPositionplaceskeep: nic se nevynucuje, kód zůstane, jak je
Výchozí keep · standardy: perCs keep, psr12 keep, nette
keep, symfony keep, laravel keep
phpdoc.types.nullPosition
Where null stands in a union type of a doc comment.
last:int|string|nullfirst:null|int|stringkeep: nic se nevynucuje, kód zůstane, jak je
Výchozí keep · standardy: perCs keep, psr12 keep, nette
last, symfony last, laravel keep · pokrývá
phpdoc_types_order, SlevomatCodingStandard.TypeHints.NullTypeHintOnLastPosition
phpdoc.types.unionOrder
The order of the types of a union type of a doc comment.
alphabetical: the types besidenullsorted by name, case-insensitivelykeep: nic se nevynucuje, kód zůstane, jak je
Výchozí keep · standardy: perCs keep, psr12 keep, nette
keep, symfony keep, laravel keep · pokrývá phpdoc_types_order
phpdoc.types.array
How an array type of a doc comment is written; list<T> is a different type and stays.
'array<T>': the generic notation'T[]': the bracketskeep: nic se nevynucuje, kód zůstane, jak je
Výchozí keep · standardy: perCs keep, psr12 keep, nette
keep, symfony keep, laravel keep · pokrývá
PhpCsFixerCustomFixers/phpdoc_array_style, PhpCsFixerCustomFixers/phpdoc_type_list,
phpdoc_array_type,
phpdoc_list_type, SlevomatCodingStandard.TypeHints.DisallowArrayTypeHintSyntax
phpdoc.property.promoted
The annotation of a promoted property.
'@var': a@varat the property, not a@paramof the constructorkeep: nic se nevynucuje, kód zůstane, jak je
Výchozí keep · standardy: perCs keep, psr12 keep, nette
@var, symfony keep, laravel keep
phpdoc.property.plainComment
A plain comment describing a property, // or /* */ where /** */ belongs, reported.
forbidden: never therekeep: nic se nevynucuje, kód zůstane, jak je
Výchozí keep · standardy: perCs keep, psr12 keep, nette
forbidden, symfony keep, laravel keep ·
pokrývá Squiz.Commenting.VariableComment
phpdoc.property.lineSpan
A property doc comment with a single annotation and no description.
collapsed: on one line,/** @var int */expanded: over three lines, the annotation on the one in the middlekeep: nic se nevynucuje, kód zůstane, jak je
Výchozí keep · standardy: perCs keep, psr12 keep, nette
collapsed, symfony keep, laravel keep · pokrývá phpdoc_line_span,
SlevomatCodingStandard.Commenting.DisallowOneLinePropertyDocComment, SlevomatCodingStandard.Commenting.RequireOneLinePropertyDocComment