Documentation

PassedParameters

Utility functions to retrieve information about parameters passed to function calls, array declarations, isset and unset constructs.

Table of Contents

$allowedConstructs The token types these methods can handle. array
$callParsingStopPoints Tokens which are considered stop point, either because they are the end of the parameter (comma) or because we need to skip over them. array
hasParameters() Checks if any parameters have been passed. bool
getParameters() Get information on all parameters passed. array
getParameter() Get information on a specific parameter passed. array|bool
getParameterCount() Count the number of parameters which have been passed. int

Properties

$allowedConstructs

The token types these methods can handle.

private static array $allowedConstructs = [ \T_STRING => true, \T_VARIABLE => true, \T_SELF => true, \T_STATIC => true, \T_ARRAY => true, \T_OPEN_SHORT_ARRAY => true, \T_ISSET => true, \T_UNSET => true, // BC for various short array tokenizer issues. See the Arrays class for more details. \T_OPEN_SQUARE_BRACKET => true, ]

$callParsingStopPoints

Tokens which are considered stop point, either because they are the end of the parameter (comma) or because we need to skip over them.

private static array $callParsingStopPoints = [\T_COMMA => \T_COMMA, \T_OPEN_SHORT_ARRAY => \T_OPEN_SHORT_ARRAY, \T_OPEN_SQUARE_BRACKET => \T_OPEN_SQUARE_BRACKET, \T_OPEN_PARENTHESIS => \T_OPEN_PARENTHESIS, \T_DOC_COMMENT_OPEN_TAG => \T_DOC_COMMENT_OPEN_TAG]

Methods

hasParameters()

Checks if any parameters have been passed.

public static hasParameters( $phpcsFile : File , $stackPtr : int ) : bool
  • If passed a T_STRING or T_VARIABLE stack pointer, it will treat it as a function call. If a T_STRING or T_VARIABLE which is not a function call is passed, the behaviour is unreliable.
  • If passed a T_SELF or T_STATIC stack pointer, it will accept it as a function call when used like new self().
  • If passed a T_ARRAY or T_OPEN_SHORT_ARRAY stack pointer, it will detect whether the array has values or is empty.
  • If passed a T_ISSET or T_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, or T_UNSET token.

Tags
since
throws

If the token passed is not one of the accepted types or doesn't exist.

Return values
bool

getParameters()

Get information on all parameters passed.

public static getParameters( $phpcsFile : File , $stackPtr : int ) : array

See \PHPCSUtils\Utils\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, or T_UNSET token.

Tags
since
throws

If the token passed is not one of the accepted types or doesn't exist.

Return values
array

Returns a multi-dimentional array with the "start" token pointer, "end" token pointer, "raw" parameter value and "clean" (only code, no comments) parameter value for all parameters. The array starts at index 1. If no parameters are found, will return an empty array.

getParameter()

Get information on a specific parameter passed.

public static getParameter( $phpcsFile : File , $stackPtr : int , $paramOffset : int ) : array|bool

See \PHPCSUtils\Utils\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 or T_UNSET token.

$paramOffset : int

The 1-based index position of the parameter to retrieve.

Tags
since
throws

If the token passed is not one of the accepted types or doesn't exist.

Return values
array|bool

Returns an array with the "start" token pointer, "end" token pointer, "raw" parameter value and "clean" (only code, no comments) parameter value for the parameter at the specified offset. Or FALSE if the specified parameter is not found.

getParameterCount()

Count the number of parameters which have been passed.

public static getParameterCount( $phpcsFile : File , $stackPtr : int ) : int

See \PHPCSUtils\Utils\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 or T_UNSET token.

Tags
since
throws

If the token passed is not one of the accepted types or doesn't exist.

Return values
int

Search results