PassedParameters
Utility functions to retrieve information about parameters passed to function calls, array declarations, isset and unset constructs.
Tags
Table of Contents
- getParameter() : array|false
- Get information on a specific parameter passed.
- getParameterCount() : int
- Count the number of parameters which have been passed.
- getParameters() : array
- Get information on all parameters passed.
- hasParameters() : bool
- Checks if any parameters have been passed.
Methods
getParameter()
Get information on a specific parameter passed.
public
static getParameter(File $phpcsFile, int $stackPtr, int $paramOffset) : array|false
See \PHPCSUtils\Utils\PassedParameters::hasParameters() for information on the supported constructs.
Parameters
- $phpcsFile : File
-
The file where this token was found.
- $stackPtr : int
-
The position of the
T_STRING
,T_VARIABLE
,T_ARRAY
,T_OPEN_SHORT_ARRAY
,T_ISSET
orT_UNSET
token. - $paramOffset : int
-
The 1-based index position of the parameter to retrieve.
Tags
Return values
array|false —Array with information on the parameter/array item at the specified offset.
Or FALSE
if the specified parameter/array item is not found.
The format of the return value is:
array(
'start' => int, // The stack pointer to the first token in the parameter/array item.
'end' => int, // The stack pointer to the last token in the parameter/array item.
'raw' => string, // A string with the contents of all tokens between `start` and `end`.
'clean' => string, // Same as `raw`, but all comment tokens have been stripped out.
)
getParameterCount()
Count the number of parameters which have been passed.
public
static getParameterCount(File $phpcsFile, int $stackPtr) : int
See \PHPCSUtils\Utils\PassedParameters::hasParameters() for information on the supported constructs.
Parameters
- $phpcsFile : File
-
The file where this token was found.
- $stackPtr : int
-
The position of the
T_STRING
,T_VARIABLE
,T_ARRAY
,T_OPEN_SHORT_ARRAY
,T_ISSET
orT_UNSET
token.
Tags
Return values
int —getParameters()
Get information on all parameters passed.
public
static getParameters(File $phpcsFile, int $stackPtr) : array
See \PHPCSUtils\Utils\PassedParameters::hasParameters() for information on the supported constructs.
Parameters
- $phpcsFile : File
-
The file where this token was found.
- $stackPtr : int
-
The position of the
T_STRING
,T_VARIABLE
,T_ARRAY
,T_OPEN_SHORT_ARRAY
,T_ISSET
, orT_UNSET
token.
Tags
Return values
array —A multi-dimentional array information on each parameter/array item. The information gathered about each parameter/array item is in the following format:
1 => array(
'start' => int, // The stack pointer to the first token in the parameter/array item.
'end' => int, // The stack pointer to the last token in the parameter/array item.
'raw' => string, // A string with the contents of all tokens between `start` and `end`.
'clean' => string, // Same as `raw`, but all comment tokens have been stripped out.
)
Note: The array starts at index 1. If no parameters/array items are found, an empty array will be returned.
hasParameters()
Checks if any parameters have been passed.
public
static hasParameters(File $phpcsFile, int $stackPtr) : bool
- If passed a
T_STRING
orT_VARIABLE
stack pointer, it will treat it as a function call. If aT_STRING
orT_VARIABLE
which is not a function call is passed, the behaviour is undetermined. - If passed a
T_SELF
orT_STATIC
stack pointer, it will accept it as a function call when used likenew self()
. - If passed a
T_ARRAY
orT_OPEN_SHORT_ARRAY
stack pointer, it will detect whether the array has values or is empty. - If passed a
T_ISSET
orT_UNSET
stack pointer, it will detect whether those language constructs have "parameters".
Parameters
- $phpcsFile : File
-
The file where this token was found.
- $stackPtr : int
-
The position of the
T_STRING
,T_VARIABLE
,T_ARRAY
,T_OPEN_SHORT_ARRAY
,T_ISSET
, orT_UNSET
token.