PHP Class BetterReflection\Reflection\ReflectionFunctionAbstract

Inheritance: implements Reflector
Exibir arquivo Open project: roave/better-reflection Class Usage Examples

Public Methods

Method Description
__clone ( )
addParameter ( string $parameterName ) Add a new parameter to the method/function.
export ( )
getAst ( ) : ClassMethod | Function_ Fetch the AST for this method or function.
getBodyAst ( ) : PhpParser\Node[] Retrieves the body of this function as AST nodes
getBodyCode ( PrettyPrinterAbstract $printer = null ) : string Retrieves the body of this function as code.
getDocBlockReturnTypes ( ) : phpDocumentor\Reflection\Type[] Get the return types defined in the DocBlocks. This returns an array because the parameter may have multiple (compound) types specified (for example when you type hint pipe-separated "string|null", in which case this would return an array of Type objects, one for string, one for null.
getDocComment ( ) : string
getEndLine ( ) : integer Get the line number that this function ends on.
getFileName ( ) : string
getLocatedSource ( ) : BetterReflection\SourceLocator\Located\LocatedSource
getName ( ) : string Get the "full" name of the function (e.g. for A\B\foo, this will return "A\B\foo").
getNamespaceName ( ) : string Get the "namespace" name of the function (e.g. for A\B\foo, this will return "A\B").
getNumberOfParameters ( ) : integer Get the number of parameters for this class.
getNumberOfRequiredParameters ( ) : integer Get the number of required parameters for this method.
getParameter ( string $parameterName ) : ReflectionParameter | null Get a single parameter by name. Returns null if parameter not found for the function.
getParameters ( ) : ReflectionParameter[] Get an array list of the parameters for this method signature, as an array of ReflectionParameter instances.
getReturnStatementsAst ( ) : PhpParser\Node\Stmt\Return_[] Fetch an array of all return statements found within this function.
getReturnType ( ) : ReflectionType | null Get the return type declaration (only for PHP 7+ code)
getShortName ( ) : string Get the "short" name of the function (e.g. for A\B\foo, this will return "foo").
getStartLine ( ) : integer Get the line number that this function starts on.
hasReturnType ( ) : boolean Do we have a return type declaration (only for PHP 7+ code)
inNamespace ( ) : boolean Decide if this function is part of a namespace. Returns false if the class is in the global namespace or does not have a specified namespace.
isClosure ( ) : boolean Is this function a closure?
isDeprecated ( ) : boolean Is this function deprecated?
isGenerator ( ) : boolean Check if this function can be used as a generator (i.e. contains the "yield" keyword).
isInternal ( ) : boolean Is this an internal function?
isUserDefined ( ) : boolean Is this a user-defined function (will always return the opposite of whatever isInternal returns).
isVariadic ( ) : boolean Check if the function has a variadic parameter.
removeParameter ( string $parameterName ) : void Remove a parameter from the method/function.
removeReturnType ( ) Remove the return type declaration completely.
returnsReference ( ) : boolean Is this function declared as a reference.
setBodyFromAst ( array $nodes ) Override the method or function's body of statements with an entirely new body of statements within the reflection.
setBodyFromClosure ( Closure $newBody ) Override the method or function's body of statements with an entirely new body of statements within the reflection.
setBodyFromString ( string $newBody ) Override the method or function's body of statements with an entirely new body of statements within the reflection.
setReturnType ( phpDocumentor\Reflection\Type $newReturnType ) Set the return type declaration.

Protected Methods

Method Description
__construct ( )
getNode ( ) : ClassMethod | Function_ Get the AST node from which this function was created
populateFunctionAbstract ( BetterReflection\Reflector\Reflector $reflector, PhpParser\Node $node, BetterReflection\SourceLocator\Located\LocatedSource $locatedSource, Namespace_ $declaringNamespace = null ) Populate the common elements of the function abstract.

Private Methods

Method Description
nodeIsOrContainsYield ( PhpParser\Node $node ) : boolean Recursively search an array of statements (PhpParser nodes) to find if a yield expression exists anywhere (thus indicating this is a generator).
setNodeOptionalFlag ( ) We must determine if params are optional or not ahead of time, but we must do it in reverse.

Method Details

__clone() public method

public __clone ( )

__construct() protected method

protected __construct ( )

addParameter() public method

Add a new parameter to the method/function.
public addParameter ( string $parameterName )
$parameterName string

export() public static method

public static export ( )

getAst() public method

Fetch the AST for this method or function.
public getAst ( ) : ClassMethod | Function_
return PhpParser\Node\Stmt\ClassMethod | PhpParser\Node\Stmt\Function_

getBodyAst() public method

Retrieves the body of this function as AST nodes
public getBodyAst ( ) : PhpParser\Node[]
return PhpParser\Node[]

getBodyCode() public method

If a PrettyPrinter is provided as a paramter, it will be used, otherwise a default will be used. Note that the formatting of the code may not be the same as the original function. If specific formatting is required, you should provide your own implementation of a PrettyPrinter to unparse the AST.
public getBodyCode ( PrettyPrinterAbstract $printer = null ) : string
$printer PhpParser\PrettyPrinterAbstract
return string

getDocBlockReturnTypes() public method

Get the return types defined in the DocBlocks. This returns an array because the parameter may have multiple (compound) types specified (for example when you type hint pipe-separated "string|null", in which case this would return an array of Type objects, one for string, one for null.
public getDocBlockReturnTypes ( ) : phpDocumentor\Reflection\Type[]
return phpDocumentor\Reflection\Type[]

getDocComment() public method

public getDocComment ( ) : string
return string

getEndLine() public method

Get the line number that this function ends on.
public getEndLine ( ) : integer
return integer

getFileName() public method

public getFileName ( ) : string
return string

getLocatedSource() public method

public getLocatedSource ( ) : BetterReflection\SourceLocator\Located\LocatedSource
return BetterReflection\SourceLocator\Located\LocatedSource

getName() public method

Get the "full" name of the function (e.g. for A\B\foo, this will return "A\B\foo").
public getName ( ) : string
return string

getNamespaceName() public method

Get the "namespace" name of the function (e.g. for A\B\foo, this will return "A\B").
public getNamespaceName ( ) : string
return string

getNode() protected method

Get the AST node from which this function was created
protected getNode ( ) : ClassMethod | Function_
return PhpParser\Node\Stmt\ClassMethod | PhpParser\Node\Stmt\Function_

getNumberOfParameters() public method

Get the number of parameters for this class.
public getNumberOfParameters ( ) : integer
return integer

getNumberOfRequiredParameters() public method

Get the number of required parameters for this method.

getParameter() public method

Get a single parameter by name. Returns null if parameter not found for the function.
public getParameter ( string $parameterName ) : ReflectionParameter | null
$parameterName string
return ReflectionParameter | null

getParameters() public method

Get an array list of the parameters for this method signature, as an array of ReflectionParameter instances.
public getParameters ( ) : ReflectionParameter[]
return ReflectionParameter[]

getReturnStatementsAst() public method

Note that return statements within smaller scopes contained (e.g. anonymous classes, closures) are not returned here as they are not within the immediate scope.
public getReturnStatementsAst ( ) : PhpParser\Node\Stmt\Return_[]
return PhpParser\Node\Stmt\Return_[]

getReturnType() public method

Get the return type declaration (only for PHP 7+ code)
public getReturnType ( ) : ReflectionType | null
return ReflectionType | null

getShortName() public method

Get the "short" name of the function (e.g. for A\B\foo, this will return "foo").
public getShortName ( ) : string
return string

getStartLine() public method

Get the line number that this function starts on.
public getStartLine ( ) : integer
return integer

hasReturnType() public method

Do we have a return type declaration (only for PHP 7+ code)
public hasReturnType ( ) : boolean
return boolean

inNamespace() public method

Decide if this function is part of a namespace. Returns false if the class is in the global namespace or does not have a specified namespace.
public inNamespace ( ) : boolean
return boolean

isClosure() public method

Is this function a closure?
public isClosure ( ) : boolean
return boolean

isDeprecated() public method

Note - we cannot reflect on internal functions (as there is no PHP source code we can access. This means, at present, we can only EVER return false from this function.
See also: https://github.com/Roave/BetterReflection/issues/38
public isDeprecated ( ) : boolean
return boolean

isGenerator() public method

Check if this function can be used as a generator (i.e. contains the "yield" keyword).
public isGenerator ( ) : boolean
return boolean

isInternal() public method

Note - we cannot reflect on internal functions (as there is no PHP source code we can access. This means, at present, we can only EVER return false from this function.
See also: https://github.com/Roave/BetterReflection/issues/38
public isInternal ( ) : boolean
return boolean

isUserDefined() public method

Is this a user-defined function (will always return the opposite of whatever isInternal returns).
public isUserDefined ( ) : boolean
return boolean

isVariadic() public method

Check if the function has a variadic parameter.
public isVariadic ( ) : boolean
return boolean

populateFunctionAbstract() protected method

Populate the common elements of the function abstract.
protected populateFunctionAbstract ( BetterReflection\Reflector\Reflector $reflector, PhpParser\Node $node, BetterReflection\SourceLocator\Located\LocatedSource $locatedSource, Namespace_ $declaringNamespace = null )
$reflector BetterReflection\Reflector\Reflector
$node PhpParser\Node
$locatedSource BetterReflection\SourceLocator\Located\LocatedSource
$declaringNamespace PhpParser\Node\Stmt\Namespace_

removeParameter() public method

Remove a parameter from the method/function.
public removeParameter ( string $parameterName ) : void
$parameterName string
return void

removeReturnType() public method

Remove the return type declaration completely.
public removeReturnType ( )

returnsReference() public method

Is this function declared as a reference.
public returnsReference ( ) : boolean
return boolean

setBodyFromAst() public method

Override the method or function's body of statements with an entirely new body of statements within the reflection.
public setBodyFromAst ( array $nodes )
$nodes array

setBodyFromClosure() public method

Override the method or function's body of statements with an entirely new body of statements within the reflection.
public setBodyFromClosure ( Closure $newBody )
$newBody Closure

setBodyFromString() public method

Override the method or function's body of statements with an entirely new body of statements within the reflection.
public setBodyFromString ( string $newBody )
$newBody string

setReturnType() public method

You must use the phpDocumentor reflection type classes as the parameter.
public setReturnType ( phpDocumentor\Reflection\Type $newReturnType )
$newReturnType phpDocumentor\Reflection\Type