Psr2 Code Generator

PhpTrait extends AbstractPhpStruct implements GenerateableInterface, TraitsInterface, PropertiesInterface Uses PropertiesPart, TraitsPart

Represents a PHP trait.

Tags
author

Thomas Gossmann

psalm-suppress

PropertyNotSetInConstructor

Interfaces, Classes and Traits

GenerateableInterface
Represents all models that can be generated with a code generator.
TraitsInterface
Represents models that can have traits.
PropertiesInterface

Table of Contents

$description  : string
$docblock  : Docblock
$longDescription  : string
$methods  : Map
$namespace  : string
$properties  : Map
$requiredFiles  : Set
$traits  : Set
$useStatements  : Map
__construct()  : mixed
Creates a new PHP trait.
addRequiredFile()  : $this
Adds a new required file.
addTrait()  : $this
Adds a trait.
addUseStatement()  : $this
Adds a use statement with an optional alias.
clearMethods()  : $this
Clears all methods.
clearProperties()  : $this
Clears all properties.
clearUseStatements()  : $this
Clears all use statements.
create()  : static
Creates a new struct.
declareUse()  : string
Declares a "use $fullClassName" with " as $alias" if $alias is available, and returns its alias (or not qualified classname) to be used in your actual php code.
declareUses()  : $this
Declares multiple use statements at once.
generateDocblock()  : $this
Generates a docblock from provided information.
getDescription()  : string
Returns this description.
getDocblock()  : Docblock
Returns the docblock.
getLongDescription()  : string
Returns the long description.
getMethod()  : PhpMethod
Returns a method.
getMethodByName()  : PhpMethod
Returns amethod.
getMethodNames()  : Set
Returns all method names.
getMethods()  : Map
Returns all methods.
getNamespace()  : string
Returns the namespace.
getProperties()  : Map
Returns a collection of properties.
getProperty()  : PhpProperty
Returns a property.
getPropertyNames()  : Set
Returns all property names.
getQualifiedName()  : string
Returns the qualified name.
getRequiredFiles()  : Set
Returns required files.
getTraits()  : Set
Returns a collection of traits.
getUseAlias()  : string
Returns the usable alias for a qualified name.
getUseStatements()  : Map
Returns all use statements.
hasMethod()  : bool
Checks whether a method exists or not.
hasMethodByName()  : bool
Checks whether a method exists or not.
hasProperty()  : bool
Checks whether a property exists.
hasPropertyByName()  : bool
Checks whether a property exists.
hasTrait()  : bool
Checks whether a trait exists.
hasTraitByName()  : bool
Checks whether a trait exists.
hasUseStatement()  : bool
Returns whether the given use statement is present.
removeMethod()  : $this
Removes a method.
removeMethodByName()  : $this
Removes a method.
removeProperty()  : $this
Removes a property.
removePropertyByName()  : $this
Removes a property.
removeTrait()  : $this
Removes a trait.
removeTraitByName()  : $this
Removes a trait.
removeUseStatement()  : $this
Removes a use statement.
setDescription()  : $this
Sets the description, which will also be used when generating a docblock.
setDocblock()  : $this
Sets the docblock.
setLongDescription()  : $this
Sets the long description.
setMethod()  : $this
Adds a method.
setMethods()  : $this
Sets a collection of methods.
setMultilineDescription()  : $this
Sets a multi-line description, which will also be used when generating a docblock.
setNamespace()  : $this
Sets the namespace.
setProperties()  : $this
Sets a collection of properties.
setProperty()  : $this
Adds a property.
setQualifiedName()  : $this
In contrast to setName(), this method accepts the fully qualified name including the namespace.
setRequiredFiles()  : $this
Sets requried files.
setTraits()  : $this
Sets a collection of traits.
setUseStatements()  : $this
Sets use statements.
initProperties()  : void
initTraits()  : void

Properties

Methods

__construct()

Creates a new PHP trait.

public final __construct([string $name = '' ]) : mixed
Parameters
$name : string = ''

qualified name

Tags
psalm-suppress

PropertyNotSetInConstructor

Return values
mixed

addRequiredFile()

Adds a new required file.

public addRequiredFile(string $file) : $this
Parameters
$file : string
Return values
$this

addTrait()

Adds a trait.

public addTrait(PhpTrait $trait) : $this

If the trait is passed as PhpTrait object, the trait is also added as use statement.

Parameters
$trait : PhpTrait

trait or qualified name

Return values
$this

addUseStatement()

Adds a use statement with an optional alias.

public addUseStatement(string $qualifiedName[, string|null $alias = null ]) : $this
Parameters
$qualifiedName : string
$alias : string|null = null
Return values
$this

clearMethods()

Clears all methods.

public clearMethods() : $this
Return values
$this

clearProperties()

Clears all properties.

public clearProperties() : $this
Return values
$this

clearUseStatements()

Clears all use statements.

public clearUseStatements() : $this
Return values
$this

create()

Creates a new struct.

public static create([string $name = '' ]) : static
Parameters
$name : string = ''

the fqcn

Return values
static

declareUse()

Declares a "use $fullClassName" with " as $alias" if $alias is available, and returns its alias (or not qualified classname) to be used in your actual php code.

public declareUse(string $qualifiedName[, string|null $alias = null ]) : string

If the class has already been declared you get only the set alias.

Parameters
$qualifiedName : string
$alias : string|null = null
Return values
string

the used alias

declareUses()

Declares multiple use statements at once.

public declareUses() : $this
Return values
$this

generateDocblock()

Generates a docblock from provided information.

public generateDocblock() : $this
Return values
$this

getDescription()

Returns this description.

public getDescription() : string
Return values
string

getDocblock()

Returns the docblock.

public getDocblock() : Docblock
Return values
Docblock

getLongDescription()

Returns the long description.

public getLongDescription() : string
Return values
string

getMethodByName()

Returns amethod.

public getMethodByName(string $name) : PhpMethod
Parameters
$name : string
Tags
throws
InvalidArgumentException

If the method does not exists

Return values
PhpMethod

getMethodNames()

Returns all method names.

public getMethodNames() : Set
Return values
Set

getMethods()

Returns all methods.

public getMethods() : Map
Return values
Map

collection of methods

getNamespace()

Returns the namespace.

public getNamespace() : string
Return values
string

getProperties()

Returns a collection of properties.

public getProperties() : Map
Return values
Map

getProperty()

Returns a property.

public getProperty(string $name) : PhpProperty
Parameters
$name : string

property name

Tags
throws
InvalidArgumentException

If the property cannot be found

Return values
PhpProperty

getPropertyNames()

Returns all property names.

public getPropertyNames() : Set
Return values
Set

getQualifiedName()

Returns the qualified name.

public getQualifiedName() : string
Return values
string

getRequiredFiles()

Returns required files.

public getRequiredFiles() : Set
Return values
Set

collection of filenames

getTraits()

Returns a collection of traits.

public getTraits() : Set
Return values
Set

getUseAlias()

Returns the usable alias for a qualified name.

public getUseAlias(string $qualifiedName) : string
Parameters
$qualifiedName : string
Return values
string

the alias

getUseStatements()

Returns all use statements.

public getUseStatements() : Map
Return values
Map

collection of use statements

hasMethod()

Checks whether a method exists or not.

public hasMethod(PhpMethod $method) : bool
Parameters
$method : PhpMethod
Return values
bool

true if it exists and false if not

hasMethodByName()

Checks whether a method exists or not.

public hasMethodByName(string $name) : bool
Parameters
$name : string
Return values
bool

hasProperty()

Checks whether a property exists.

public hasProperty(PhpProperty $property) : bool
Parameters
$property : PhpProperty
Return values
bool

true if a property exists and false if not

hasPropertyByName()

Checks whether a property exists.

public hasPropertyByName(string $name) : bool
Parameters
$name : string

property name

Return values
bool

true if a property exists and false if not

hasTrait()

Checks whether a trait exists.

public hasTrait(PhpTrait $trait) : bool
Parameters
$trait : PhpTrait
Return values
bool

true if it exists and false if not

hasTraitByName()

Checks whether a trait exists.

public hasTraitByName(string $name) : bool
Parameters
$name : string
Tags
psalm-suppress

TooManyArguments

Return values
bool

true if it exists and false if not

hasUseStatement()

Returns whether the given use statement is present.

public hasUseStatement(string $qualifiedName) : bool
Parameters
$qualifiedName : string
Return values
bool

removeMethodByName()

Removes a method.

public removeMethodByName(string $name) : $this
Parameters
$name : string

method name or Method instance

Tags
throws
InvalidArgumentException

If the method does not exist

Return values
$this

removeProperty()

Removes a property.

public removeProperty(PhpProperty $property) : $this
Parameters
$property : PhpProperty
Tags
throws
InvalidArgumentException

If the property cannot be found

Return values
$this

removePropertyByName()

Removes a property.

public removePropertyByName(string $name) : $this
Parameters
$name : string

property name

Tags
throws
InvalidArgumentException

If the property cannot be found

Return values
$this

removeTrait()

Removes a trait.

public removeTrait(PhpTrait $trait) : $this

If the trait is passed as PhpTrait object, the trait is also removed from use statements.

Parameters
$trait : PhpTrait

trait or qualified name

Return values
$this

removeTraitByName()

Removes a trait.

public removeTraitByName(string $traitName) : $this

If the trait is passed as PhpTrait object, the trait is also removed from use statements.

Parameters
$traitName : string

trait qualified name

Tags
psalm-suppress

TooManyArguments

Return values
$this

removeUseStatement()

Removes a use statement.

public removeUseStatement(string $qualifiedName) : $this
Parameters
$qualifiedName : string
Return values
$this

setDescription()

Sets the description, which will also be used when generating a docblock.

public setDescription(string $description) : $this
Parameters
$description : string
Return values
$this

setDocblock()

Sets the docblock.

public setDocblock(Docblock|string $doc) : $this
Parameters
$doc : Docblock|string
Return values
$this

setLongDescription()

Sets the long description.

public setLongDescription(string $longDescription) : $this
Parameters
$longDescription : string
Return values
$this

setMethods()

Sets a collection of methods.

public setMethods(array<string|int, PhpMethod$methods) : $this
Parameters
$methods : array<string|int, PhpMethod>
Return values
$this

setMultilineDescription()

Sets a multi-line description, which will also be used when generating a docblock.

public setMultilineDescription(array<string|int, mixed> $description) : $this

Each line is a value of the $description array.

Parameters
$description : array<string|int, mixed>
Return values
$this

setNamespace()

Sets the namespace.

public setNamespace(string $namespace) : $this
Parameters
$namespace : string
Return values
$this

setProperties()

Sets a collection of properties.

public setProperties(array<string|int, PhpProperty$properties) : $this
Parameters
$properties : array<string|int, PhpProperty>
Return values
$this

setQualifiedName()

In contrast to setName(), this method accepts the fully qualified name including the namespace.

public setQualifiedName(string $name) : $this
Parameters
$name : string
Return values
$this

setRequiredFiles()

Sets requried files.

public setRequiredFiles(array<string|int, mixed> $files) : $this
Parameters
$files : array<string|int, mixed>
Return values
$this

setTraits()

Sets a collection of traits.

public setTraits(array<string|int, mixed> $traits) : $this
Parameters
$traits : array<string|int, mixed>
Tags
throws
InvalidArgumentException

if wrong type given

Return values
$this

setUseStatements()

Sets use statements.

public setUseStatements(array<string|int, mixed> $useStatements) : $this
Parameters
$useStatements : array<string|int, mixed>
Tags
see

#addUseStatement

see

#declareUses()

Return values
$this

initProperties()

private initProperties() : void
Return values
void

initTraits()

private initTraits() : void
Return values
void

Search results