Psr2 Code Generator

PhpMethod extends AbstractPhpMember implements RoutineInterface Uses AbstractPart, BodyPart, FinalPart, ParametersPart, ReferenceReturnPart, TypeDocblockGeneratorPart

Represents a PHP method.

Tags
author

Johannes M. Schmitt schmittjoh@gmail.com

author

Thomas Gossmann

psalm-suppress

PropertyNotSetInConstructor

Interfaces, Classes and Traits

RoutineInterface

Table of Contents

VISIBILITY_PRIVATE  = 'private'
Private visibility.
VISIBILITY_PROTECTED  = 'protected'
Protected visibility.
VISIBILITY_PUBLIC  = 'public'
Public visibility.
$description  : string
$abstract  : bool
$body  : string
$docblock  : Docblock
$final  : bool
$longDescription  : string
$name  : string
$parameters  : array<string|int, PhpParameter>
$parent  : AbstractPhpStruct|null
$referenceReturned  : bool
$static  : bool
$type  : string
$typeDescription  : string
$visibility  : string
__construct()  : mixed
Creates a new member.
addParameter()  : $this
Adds a parameter.
addSimpleDescParameter()  : $this
A quick way to add a parameter with description which is created from the given parameters.
addSimpleParameter()  : $this
A quick way to add a parameter which is created from the given parameters.
appendToBody()  : $this
Append a string to the body of this.
create()  : static
Creates a new PHP method.
generateDocblock()  : mixed
Generates docblock based on provided information.
getBody()  : string
Returns the body.
getDescription()  : string
Returns this description.
getDocblock()  : Docblock
Returns the docblock.
getLongDescription()  : string
Returns the long description.
getName()  : string
Returns the name.
getParameterByName()  : PhpParameter
Returns a parameter by index or name.
getParameterByPosition()  : PhpParameter
Returns a parameter by index or name.
getParameters()  : array<string|int, PhpParameter>
Returns an array of parameters.
getType()  : string
Returns the type.
getTypeDescription()  : string
Returns the type description.
getVisibility()  : string
Returns the visibility state of this member.
hasParameter()  : bool
Checks whether a parameter exists.
isAbstract()  : bool
Returns whether this is abstract.
isFinal()  : bool
Returns whether this is final.
isReferenceReturned()  : bool
Returns whether a reference is returned.
isStatic()  : bool
Returns whether this member is static.
removeParameter()  : $this
Remove the given parameter.
removeParameterByName()  : $this
Remove a parameter having the given name.
removeParameterByPosition()  : $this
Remove the parameter at the given position.
replaceParameter()  : $this
Replaces a parameter at a given position.
setAbstract()  : $this
Sets this to abstract.
setBody()  : $this
Sets the body for this.
setDescription()  : $this
Sets the description, which will also be used when generating a docblock.
setDocblock()  : $this
Sets the docblock.
setFinal()  : $this
Sets this final.
setLongDescription()  : $this
Sets the long description.
setMultilineDescription()  : $this
Sets a multi-line description, which will also be used when generating a docblock.
setName()  : $this
Sets the name.
setParameters()  : $this
Sets a collection of parameters.
setReferenceReturned()  : $this
Set true if a reference is returned of false if not.
setStatic()  : $this
Sets whether or not this member is static.
setType()  : $this
Sets the type.
setTypeDescription()  : $this
Sets the description for the type.
setVisibility()  : $this
Sets the members visibility.
generateParamDocblock()  : void
Generates docblock for params.
generateTypeTag()  : void
Generates a type tag (return or var) but checks if one exists and updates this one.
checkPosition()  : void
transformNullable()  : string
Transform a `?type` PHP notation in `type|null` docblock notation.

Constants

VISIBILITY_PRIVATE

Private visibility.

public string VISIBILITY_PRIVATE = 'private'

VISIBILITY_PROTECTED

Protected visibility.

public string VISIBILITY_PROTECTED = 'protected'

VISIBILITY_PUBLIC

Public visibility.

public string VISIBILITY_PUBLIC = 'public'

Properties

$typeDescription

private string $typeDescription = ''

Methods

__construct()

Creates a new member.

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

the name of the member

Return values
mixed

addSimpleDescParameter()

A quick way to add a parameter with description which is created from the given parameters.

public addSimpleDescParameter(string $name[, string|null $type = null ][, string|null $typeDescription = null ][, mixed $defaultValue = null ]) : $this
Parameters
$name : string
$type : string|null = null
$typeDescription : string|null = null
$defaultValue : mixed = null

omit the argument to define no default value

Return values
$this

addSimpleParameter()

A quick way to add a parameter which is created from the given parameters.

public addSimpleParameter(string $name[, string|null $type = null ][, mixed $defaultValue = null ]) : $this
Parameters
$name : string
$type : string|null = null
$defaultValue : mixed = null

omit the argument to define no default value

Return values
$this

appendToBody()

Append a string to the body of this.

public appendToBody(string $toAppend) : $this
Parameters
$toAppend : string
Return values
$this

create()

Creates a new PHP method.

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

the method name

Return values
static

generateDocblock()

Generates docblock based on provided information.

public generateDocblock() : mixed
Return values
mixed

getBody()

Returns the body.

public getBody() : string
Return values
string

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

getName()

Returns the name.

public getName() : string
Return values
string

getParameterByName()

Returns a parameter by index or name.

public getParameterByName(string $name) : PhpParameter
Parameters
$name : string
Tags
throws
InvalidArgumentException
Return values
PhpParameter

getParameterByPosition()

Returns a parameter by index or name.

public getParameterByPosition(int $position) : PhpParameter
Parameters
$position : int
Tags
throws
InvalidArgumentException
Return values
PhpParameter

getType()

Returns the type.

public getType() : string
Return values
string

getTypeDescription()

Returns the type description.

public getTypeDescription() : string
Return values
string

getVisibility()

Returns the visibility state of this member.

public getVisibility() : string
Return values
string

the visibility

hasParameter()

Checks whether a parameter exists.

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

parameter name

Return values
bool

true if a parameter exists and false if not

isAbstract()

Returns whether this is abstract.

public isAbstract() : bool
Return values
bool

true for abstract and false if not

isFinal()

Returns whether this is final.

public isFinal() : bool
Return values
bool

true for final and false if not

isReferenceReturned()

Returns whether a reference is returned.

public isReferenceReturned() : bool
Return values
bool

isStatic()

Returns whether this member is static.

public isStatic() : bool
Return values
bool

true if static and false if not

removeParameter()

Remove the given parameter.

public removeParameter(PhpParameter $param) : $this
Parameters
$param : PhpParameter
Tags
throws
InvalidArgumentException

If the parameter doesn't exist

Return values
$this

removeParameterByName()

Remove a parameter having the given name.

public removeParameterByName(string $name) : $this
Parameters
$name : string
Tags
throws
InvalidArgumentException

If the parameter doesn't exist

Return values
$this

removeParameterByPosition()

Remove the parameter at the given position.

public removeParameterByPosition(int $position) : $this
Parameters
$position : int
Tags
throws
InvalidArgumentException

If the parameter doesn't exist

Return values
$this

replaceParameter()

Replaces a parameter at a given position.

public replaceParameter(int $position, PhpParameter $parameter) : $this
Parameters
$position : int
$parameter : PhpParameter
Tags
throws
InvalidArgumentException
Return values
$this

setAbstract()

Sets this to abstract.

public setAbstract(bool $bool) : $this
Parameters
$bool : bool

true for abstract and false if not

Return values
$this

setBody()

Sets the body for this.

public setBody(string $body) : $this
Parameters
$body : 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

setFinal()

Sets this final.

public setFinal(bool $bool) : $this
Parameters
$bool : bool

true for final and false if not

Return values
$this

setLongDescription()

Sets the long description.

public setLongDescription(string $longDescription) : $this
Parameters
$longDescription : string
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

setName()

Sets the name.

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

setParameters()

Sets a collection of parameters.

public setParameters(array<string|int, PhpParameter$parameters) : $this

Note: clears all parameters before setting the new ones

Parameters
$parameters : array<string|int, PhpParameter>
Return values
$this

setReferenceReturned()

Set true if a reference is returned of false if not.

public setReferenceReturned(bool $bool) : $this
Parameters
$bool : bool
Return values
$this

setStatic()

Sets whether or not this member is static.

public setStatic(bool $bool) : $this
Parameters
$bool : bool
Return values
$this

setType()

Sets the type.

public setType(string $type[, string $description = '' ]) : $this
Parameters
$type : string
$description : string = ''
Return values
$this

setTypeDescription()

Sets the description for the type.

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

setVisibility()

Sets the members visibility.

public setVisibility(string $visibility) : $this
Parameters
$visibility : string

the new visibility

Tags
see
self::VISIBILITY_PUBLIC
see
self::VISIBILITY_PROTECTED
see
self::VISIBILITY_PRIVATE
Return values
$this

generateParamDocblock()

Generates docblock for params.

protected generateParamDocblock() : void
Tags
psalm-suppress

TooManyArguments

Return values
void

generateTypeTag()

Generates a type tag (return or var) but checks if one exists and updates this one.

protected generateTypeTag(AbstractTypeTag $tag) : void
Parameters
$tag : AbstractTypeTag
Return values
void

checkPosition()

private checkPosition(int $position) : void
Parameters
$position : int
Tags
throws
InvalidArgumentException

if the position is not correct

Return values
void

transformNullable()

Transform a `?type` PHP notation in `type|null` docblock notation.

private transformNullable(string $type) : string
Parameters
$type : string
Return values
string

Search results