Documentation
¶
Overview ¶
Package phpdoc parses PHPDoc comments: tags and type expressions.
Index ¶
- Constants
- func SplitType(text string) (typ, rest string)
- func VarName(text string) string
- type Doc
- func (d *Doc) All(name string) []Tag
- func (d *Doc) EffectiveParams() []Param
- func (d *Doc) EffectiveReturnType() string
- func (d *Doc) EffectiveVarType(name string) string
- func (d *Doc) EffectiveVars() []Param
- func (d *Doc) Has(name string) bool
- func (d *Doc) ImportedTypes() []ImportedType
- func (d *Doc) Params() []Param
- func (d *Doc) ParamsOf(tag string) []Param
- func (d *Doc) ReturnType() string
- func (d *Doc) Tag(name string) (Tag, bool)
- func (d *Doc) TemplateParams() []TemplateParam
- func (d *Doc) Templates() []string
- func (d *Doc) TypeAliases() map[string]string
- func (d *Doc) VarType(name string) string
- type ImportedType
- type MethodParam
- type MethodSignature
- type Param
- type Tag
- type TemplateParam
- type Variance
Constants ¶
const MaxAliasLen = 4096
MaxAliasLen is the longest type alias definition kept (the same cap as types.MaxDocTypeLen): a longer one is recorded as "" (mixed), so that resolvers do not copy a huge definition at every use of the alias.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Doc ¶
Doc is a parsed doc comment.
func (*Doc) EffectiveParams ¶
EffectiveParams selects parameter types, preferring phpstan-param over psalm-param over param independently for each named parameter. Empty types are ignored. Within one dialect the last declaration wins, as with Params. Results follow the first occurrence of each selected parameter in the doc.
func (*Doc) EffectiveReturnType ¶
EffectiveReturnType selects the first nonempty return type in the highest available dialect: phpstan-return, psalm-return, then return. Description-only annotations are ignored using the same heuristic as ReturnType.
func (*Doc) EffectiveVarType ¶
EffectiveVarType selects the first applicable nonempty variable annotation in the highest available dialect. An unnamed annotation applies to any name; an empty name selects the first variable annotation in that dialect.
func (*Doc) EffectiveVars ¶
EffectiveVars selects variable types, preferring phpstan-var over psalm-var over var independently for each variable (including unnamed annotations). Empty types are ignored; the first declaration within a dialect wins. Results follow the first occurrence of each selected variable in the doc.
func (*Doc) ImportedTypes ¶
func (d *Doc) ImportedTypes() []ImportedType
ImportedTypes returns the type aliases the doc imports (`@phpstan-import-type Name from From as Local`), as written.
func (*Doc) ParamsOf ¶
ParamsOf returns the tags named tag ("param", "phpstan-param", "psalm-param") parsed as @param tags.
func (*Doc) ReturnType ¶
ReturnType returns the @return type text ("" when absent).
func (*Doc) TemplateParams ¶
func (d *Doc) TemplateParams() []TemplateParam
TemplateParams returns the templates declared by @template (and the variants Templates accepts) with their bounds, in declaration order.
func (*Doc) Templates ¶
Templates returns the names declared by @template (and the psalm-/phpstan- prefixed and covariant/contravariant variants).
func (*Doc) TypeAliases ¶
TypeAliases returns local type aliases declared with @phpstan-type / @psalm-type (name -> definition text; "" beyond MaxAliasLen) and imported ones with @phpstan-import-type / @psalm-import-type (name -> "").
type ImportedType ¶
type ImportedType struct{ Name, From, Local string }
ImportedType is a type alias imported with @phpstan-import-type or @psalm-import-type: alias Name of class From, known here as Local.
type MethodParam ¶
MethodParam describes one parameter in a documented magic method.
type MethodSignature ¶
type MethodSignature struct {
Name, Return string
Static bool
Params []MethodParam
}
MethodSignature is a class @method declaration. Its types are still PHPDoc text: callers resolve them in the declaring class's namespace.
func ParseMethod ¶
func ParseMethod(text string) (MethodSignature, bool)
ParseMethod parses an @method signature, ignoring a trailing description. Malformed or oversized signatures are discarded rather than partially kept.
type Tag ¶
type Tag struct {
Name string // without '@', e.g. "return"
Text string // rest of the tag (continuation lines joined with '\n')
}
Tag is one `@name rest` entry.