trait TraitsPart

Traits part

For all models that can have traits

Methods

$this
addUseStatement(string $qualifiedName, null|string $alias = null)

Adds a use statement with an optional alias

$this
removeUseStatement(string $qualifiedName)

Removes a use statement

string
getNamespace()

Returns the namespace

$this
addTrait(PhpTrait|string $trait)

Adds a trait.

string[]
getTraits()

Returns a collection of traits

bool
hasTrait(PhpTrait|string $trait)

Checks whether a trait exists

$this
removeTrait(PhpTrait|string $trait)

Removes a trait.

$this
setTraits(array $traits)

Sets a collection of traits

Details

at line line 25
abstract $this addUseStatement(string $qualifiedName, null|string $alias = null)

Adds a use statement with an optional alias

Parameters

string $qualifiedName
null|string $alias

Return Value

$this

at line line 33
abstract $this removeUseStatement(string $qualifiedName)

Removes a use statement

Parameters

string $qualifiedName

Return Value

$this

at line line 40
abstract string getNamespace()

Returns the namespace

Return Value

string

at line line 51
$this addTrait(PhpTrait|string $trait)

Adds a trait.

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

Parameters

PhpTrait|string $trait trait or qualified name

Return Value

$this

at line line 76
string[] getTraits()

Returns a collection of traits

Return Value

string[]

at line line 86
bool hasTrait(PhpTrait|string $trait)

Checks whether a trait exists

Parameters

PhpTrait|string $trait

Return Value

bool true if it exists and false if not

at line line 103
$this removeTrait(PhpTrait|string $trait)

Removes a trait.

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

Parameters

PhpTrait|string $trait trait or qualified name

Return Value

$this

at line line 129
$this setTraits(array $traits)

Sets a collection of traits

Parameters

array $traits

Return Value

$this