Documentation

MethodGenerator extends AbstractClassElementGenerator
in package
uses AbstractFinalTrait, FunctionTrait, BodyTrait

Namespace generator class

Tags
category

Pop

author

Nick Sagona, III nick@popphp.org

copyright

Copyright (c) 2009-2026 Nick Sagona, III

license

https://www.popphp.org/license New BSD License

version
6.0.0

Table of Contents

Constants

VALID_VISIBILITIES  = ['public', 'protected', 'private']
Valid visibility values

Properties

$abstract  : bool
Method abstract flag
$arguments  : array<string|int, mixed>
Arguments
$attributes  : array<string|int, mixed>
Attributes. An indexed list, not keyed by name — attributes can legitimately repeat (Attribute::IS_REPEATABLE), so a name-keyed map would silently collapse repeats.
$body  : string|null
Method body
$docblock  : DocblockGenerator|null
Docblock generator object
$final  : bool
Method final flag
$indent  : int
Code indent spaces
$name  : string|null
Name
$output  : string|null
Output string
$returnTypes  : array<string|int, mixed>
Return Types
$static  : bool
Static flag
$visibility  : string
Visibility

Methods

__construct()  : mixed
Constructor
__toString()  : string
Print method
addArgument()  : static
Add an argument
addArguments()  : static
Add arguments
addAttribute()  : static
Add an attribute
addAttributes()  : static
Add attributes
addParameter()  : static
Add an argument (alias method for convenience)
addParameters()  : static
Add arguments (alias method for convenience)
addPromotedArgument()  : MethodGenerator
Add a promoted constructor argument
addReturnType()  : static
Add a return type
addReturnTypes()  : static
Add return types
appendToBody()  : static
Append to the function body
getArgument()  : array<string|int, mixed>|null
Get an argument
getArguments()  : array<string|int, mixed>
Get the arguments
getAttributes()  : array<string|int, mixed>
Get all attributes
getAttributesByName()  : array<string|int, mixed>
Get all attributes with the given name (supports repeated attributes)
getBody()  : string|null
Get the function body
getDesc()  : string|null
Get the docblock description
getDocblock()  : DocblockGenerator|null
Access the docblock generator object
getIndent()  : int
Get the indent
getName()  : string|null
Get the name
getOutput()  : string|null
Get the output
getParameter()  : array<string|int, mixed>|null
Get an argument (alias method for convenience)
getParameters()  : array<string|int, mixed>
Get the arguments (alias method for convenience)
getReturnTypes()  : array<string|int, mixed>
Get the return types
getVisibility()  : string
Get the visibility
hasArgument()  : bool
Has an argument
hasArguments()  : bool
Has arguments
hasAttribute()  : bool
Has an attribute with the given name
hasAttributes()  : bool
Has attributes
hasBody()  : bool
Has method body
hasDesc()  : bool
Has a docblock description
hasDocblock()  : bool
Has docblock generator object
hasIndent()  : bool
Has indent
hasName()  : bool
Get the name
hasOutput()  : bool
Has output
hasParameter()  : bool
Has an argument (alias method for convenience)
hasParameters()  : bool
Has arguments (alias method for convenience)
hasReturnType()  : bool
Has return type
hasReturnTypes()  : bool
Has return types
indentBody()  : static
Append to the function body
isAbstract()  : bool
Get the method abstract flag
isFinal()  : bool
Get the method final flag
isPrivate()  : bool
Set the visibility to private
isProtected()  : bool
Set the visibility to protected
isPublic()  : bool
Is visibility public
isRendered()  : bool
Is rendered (alias to hasOutput())
isStatic()  : bool
Get the static flag
printIndent()  : string
Print the indent
removeAttribute()  : static
Remove an attribute (by instance identity — there is no unique name to remove by)
render()  : string
Render method
setAsAbstract()  : static
Set the method abstract flag
setAsFinal()  : static
Set the method final flag
setAsPrivate()  : AbstractClassElementGenerator
Set the visibility to public
setAsProtected()  : AbstractClassElementGenerator
Set the visibility to protected
setAsPublic()  : AbstractClassElementGenerator
Set the visibility to public
setAsStatic()  : AbstractClassElementGenerator
Set the static flag
setBody()  : static
Set the function body
setDesc()  : static
Set the docblock description
setDocblock()  : static
Set the docblock generator object
setIndent()  : AbstractGenerator
Set the indent
setName()  : static
Set the name
setVisibility()  : AbstractClassElementGenerator
Set the visibility
formatArguments()  : string|null
Format the arguments
formatAttributes()  : string
Format the attributes

Constants

VALID_VISIBILITIES

Valid visibility values

protected array<string|int, mixed> VALID_VISIBILITIES = ['public', 'protected', 'private']

Properties

$arguments

Arguments

protected array<string|int, mixed> $arguments = []

$attributes

Attributes. An indexed list, not keyed by name — attributes can legitimately repeat (Attribute::IS_REPEATABLE), so a name-keyed map would silently collapse repeats.

protected array<string|int, mixed> $attributes = []

$name

Name

protected string|null $name = null

$returnTypes

Return Types

protected array<string|int, mixed> $returnTypes = []

Methods

__construct()

Constructor

public __construct(string $name[, string $visibility = 'public' ][, bool $static = false ]) : mixed

Instantiate the method generator object

Parameters
$name : string
$visibility : string = 'public'
$static : bool = false
Tags
throws
Exception

__toString()

Print method

public __toString() : string
Return values
string

addArgument()

Add an argument

public addArgument(string $name[, mixed $value = new NoValue() ][, string|null $type = null ][, bool $variadic = false ][, bool $byRef = false ][, array<string|int, mixed> $attributes = [] ]) : static
Parameters
$name : string
$value : mixed = new NoValue()
$type : string|null = null
$variadic : bool = false
$byRef : bool = false
$attributes : array<string|int, mixed> = []
Tags
throws
Exception
Return values
static

addArguments()

Add arguments

public addArguments(array<string|int, mixed> $args) : static
Parameters
$args : array<string|int, mixed>

each element shaped ['name' => string, 'value' => mixed, 'type' => ?string, 'variadic' => bool, 'byRef' => bool, 'attributes' => array]

Tags
throws
Exception
Return values
static

addAttributes()

Add attributes

public addAttributes(array<string|int, mixed> $attributes) : static
Parameters
$attributes : array<string|int, mixed>
Return values
static

addParameter()

Add an argument (alias method for convenience)

public addParameter(string $name[, mixed $value = new NoValue() ][, string|null $type = null ][, bool $variadic = false ][, bool $byRef = false ][, array<string|int, mixed> $attributes = [] ]) : static
Parameters
$name : string
$value : mixed = new NoValue()
$type : string|null = null
$variadic : bool = false
$byRef : bool = false
$attributes : array<string|int, mixed> = []
Tags
throws
Exception
Return values
static

addParameters()

Add arguments (alias method for convenience)

public addParameters(array<string|int, mixed> $args) : static
Parameters
$args : array<string|int, mixed>
Return values
static

addPromotedArgument()

Add a promoted constructor argument

public addPromotedArgument(string $name, string $visibility[, mixed $value = new NoValue() ][, string|null $type = null ][, bool $readonly = false ][, array<string|int, mixed> $attributes = [] ]) : MethodGenerator
Parameters
$name : string
$visibility : string
$value : mixed = new NoValue()
$type : string|null = null
$readonly : bool = false
$attributes : array<string|int, mixed> = []
Tags
throws
Exception
Return values
MethodGenerator

addReturnType()

Add a return type

public addReturnType(string $type) : static
Parameters
$type : string
Return values
static

addReturnTypes()

Add return types

public addReturnTypes(array<string|int, mixed> $types) : static
Parameters
$types : array<string|int, mixed>
Return values
static

appendToBody()

Append to the function body

public appendToBody(string $body) : static
Parameters
$body : string
Return values
static

getArgument()

Get an argument

public getArgument(string $name) : array<string|int, mixed>|null
Parameters
$name : string
Return values
array<string|int, mixed>|null

getArguments()

Get the arguments

public getArguments() : array<string|int, mixed>
Return values
array<string|int, mixed>

getAttributes()

Get all attributes

public getAttributes() : array<string|int, mixed>
Return values
array<string|int, mixed>

getAttributesByName()

Get all attributes with the given name (supports repeated attributes)

public getAttributesByName(string $name) : array<string|int, mixed>
Parameters
$name : string
Return values
array<string|int, mixed>

getBody()

Get the function body

public getBody() : string|null
Return values
string|null

getDesc()

Get the docblock description

public getDesc() : string|null
Return values
string|null

getName()

Get the name

public getName() : string|null
Return values
string|null

getOutput()

Get the output

public getOutput() : string|null
Return values
string|null

getParameter()

Get an argument (alias method for convenience)

public getParameter(string $name) : array<string|int, mixed>|null
Parameters
$name : string
Return values
array<string|int, mixed>|null

getParameters()

Get the arguments (alias method for convenience)

public getParameters() : array<string|int, mixed>
Return values
array<string|int, mixed>

getReturnTypes()

Get the return types

public getReturnTypes() : array<string|int, mixed>
Return values
array<string|int, mixed>

hasArgument()

Has an argument

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

hasArguments()

Has arguments

public hasArguments() : bool
Return values
bool

hasAttribute()

Has an attribute with the given name

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

hasAttributes()

Has attributes

public hasAttributes() : bool
Return values
bool

hasBody()

Has method body

public hasBody() : bool
Return values
bool

hasDesc()

Has a docblock description

public hasDesc() : bool
Return values
bool

hasDocblock()

Has docblock generator object

public hasDocblock() : bool
Return values
bool

hasName()

Get the name

public hasName() : bool
Return values
bool

hasParameter()

Has an argument (alias method for convenience)

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

hasParameters()

Has arguments (alias method for convenience)

public hasParameters() : bool
Return values
bool

hasReturnType()

Has return type

public hasReturnType(string $type) : bool
Parameters
$type : string
Return values
bool

hasReturnTypes()

Has return types

public hasReturnTypes() : bool
Return values
bool

indentBody()

Append to the function body

public indentBody(int $indent) : static
Parameters
$indent : int
Return values
static

isAbstract()

Get the method abstract flag

public isAbstract() : bool
Return values
bool

isRendered()

Is rendered (alias to hasOutput())

public isRendered() : bool
Return values
bool

printIndent()

Print the indent

public printIndent() : string
Return values
string

render()

Render method

public render() : string
Return values
string

setAsAbstract()

Set the method abstract flag

public setAsAbstract([bool $abstract = true ]) : static
Parameters
$abstract : bool = true
Return values
static

setAsFinal()

Set the method final flag

public setAsFinal([bool $final = true ]) : static
Parameters
$final : bool = true
Return values
static

setBody()

Set the function body

public setBody(string $body[, int $indent = 4 ]) : static
Parameters
$body : string
$indent : int = 4
Return values
static

setDesc()

Set the docblock description

public setDesc([string|null $desc = null ]) : static
Parameters
$desc : string|null = null
Return values
static

setName()

Set the name

public setName(string $name) : static
Parameters
$name : string
Return values
static

formatArguments()

Format the arguments

protected formatArguments() : string|null
Return values
string|null

formatAttributes()

Format the attributes

protected formatAttributes([bool $indented = true ]) : string
Parameters
$indented : bool = true
Return values
string

        
On this page

Search results