Properties

$parts

$parts : array<mixed,string>

Type

array<mixed,string> — Parts of the name

$attributes

$attributes : 

Type

Methods

__construct()

__construct(array  $attributes = array()) 

Creates a Node.

Parameters

array $attributes

Array of attributes

getSubNodeNames()

getSubNodeNames() 

getFirst()

getFirst() : string

Gets the first part of the name, i.e. everything before the first namespace separator.

Returns

string —

First part of the name

getLast()

getLast() : string

Gets the last part of the name, i.e. everything after the last namespace separator.

Returns

string —

Last part of the name

isUnqualified()

isUnqualified() : boolean

Checks whether the name is unqualified. (E.g. Name)

Returns

boolean —

Whether the name is unqualified

isQualified()

isQualified() : boolean

Checks whether the name is qualified. (E.g. Name\Name)

Returns

boolean —

Whether the name is qualified

isFullyQualified()

isFullyQualified() : boolean

Checks whether the name is fully qualified. (E.g. \Name)

Returns

boolean —

Whether the name is fully qualified

isRelative()

isRelative() : boolean

Checks whether the name is explicitly relative to the current namespace. (E.g. namespace\Name)

Returns

boolean —

Whether the name is relative

toString()

toString() : string

Returns a string representation of the name by imploding the namespace parts with the namespace separator.

Returns

string —

String representation

__toString()

__toString() : string

Returns a string representation of the name by imploding the namespace parts with the namespace separator.

Returns

string —

String representation

slice()

slice(integer  $offset, integer|null  $length = null) : static|null

Gets a slice of a name (similar to array_slice).

This method returns a new instance of the same type as the original and with the same attributes.

If the slice is empty, null is returned. The null value will be correctly handled in concatenations using concat().

Offset and length have the same meaning as in array_slice().

Parameters

integer $offset

Offset to start the slice at (may be negative)

integer|null $length

Length of the slice (may be negative)

Returns

static|null —

Sliced name

concat()

concat(string|array|self|null  $name1, string|array|self|null  $name2, array  $attributes = array()) : static|null

Concatenate two names, yielding a new Name instance.

The type of the generated instance depends on which class this method is called on, for example Name\FullyQualified::concat() will yield a Name\FullyQualified instance.

If one of the arguments is null, a new instance of the other name will be returned. If both arguments are null, null will be returned. As such, writing Name::concat($namespace, $shortName) where $namespace is a Name node or null will work as expected.

Parameters

string|array|self|null $name1

The first name

string|array|self|null $name2

The second name

array $attributes

Attributes to assign to concatenated name

Returns

static|null —

Concatenated name

getType()

getType() : string

Gets the type of the node.

Returns

string —

Type of the node

getLine()

getLine() : integer

Gets line the node started in.

Returns

integer —

Line

setLine()

setLine(integer  $line) 

Sets line the node started in.

Parameters

integer $line

Line

getDocComment()

getDocComment() : null|\PhpParser\Comment\Doc

Gets the doc comment of the node.

The doc comment has to be the last comment associated with the node.

Returns

null|\PhpParser\Comment\Doc

Doc comment object or null

setDocComment()

setDocComment(\PhpParser\Comment\Doc  $docComment) 

Sets the doc comment of the node.

This will either replace an existing doc comment or add it to the comments array.

Parameters

\PhpParser\Comment\Doc $docComment

Doc comment to set

setAttribute()

setAttribute(string  $key, mixed  $value) 

Sets an attribute on a node.

Parameters

string $key
mixed $value

hasAttribute()

hasAttribute(string  $key) : boolean

Returns whether an attribute exists.

Parameters

string $key

Returns

boolean

getAttribute()

getAttribute(string  $key, mixed  $default = null) : mixed

Returns the value of an attribute.

Parameters

string $key
mixed $default

Returns

mixed

getAttributes()

getAttributes() : array

Returns all attributes for the given node.

Returns

array

jsonSerialize()

jsonSerialize() 

prepareName()

prepareName(string|array|self  $name) : array

Prepares a (string, array or Name node) name for use in name changing methods by converting it to an array.

Parameters

string|array|self $name

Name to prepare

Returns

array —

Prepared name