function File::findPrevious
Returns the position of the previous specified token(s).
If a value is specified, the previous token of the specified type(s) containing the specified value will be returned.
Returns false if no token can be found.
Parameters
int|string|array $types The type(s) of tokens to search for.:
int $start The position to start searching from in the: token stack.
int|null $end The end position to fail if no token is found.: if not specified or null, end will default to the start of the token stack.
bool $exclude If true, find the previous token that is NOT of: the types specified in $types.
string|null $value The value that the token(s) must be equal to.: If value is omitted, tokens with any value will be returned.
bool $local If true, tokens outside the current statement: will not be checked. IE. checking will stop at the previous semicolon found.
Return value
int|false
See also
findNext()
4 calls to File::findPrevious()
- File::findEndOfStatement in vendor/
squizlabs/ php_codesniffer/ src/ Files/ File.php - Returns the position of the last non-whitespace token in a statement.
- File::findStartOfStatement in vendor/
squizlabs/ php_codesniffer/ src/ Files/ File.php - Returns the position of the first non-whitespace token in a statement.
- File::getMemberProperties in vendor/
squizlabs/ php_codesniffer/ src/ Files/ File.php - Returns the visibility and implementation properties of a class member var.
- File::isReference in vendor/
squizlabs/ php_codesniffer/ src/ Files/ File.php - Determine if the passed token is a reference operator.
File
-
vendor/
squizlabs/ php_codesniffer/ src/ Files/ File.php, line 2280
Class
Namespace
PHP_CodeSniffer\FilesCode
public function findPrevious($types, $start, $end = null, $exclude = false, $value = null, $local = false) {
$types = (array) $types;
if ($end === null) {
$end = 0;
}
for ($i = $start; $i >= $end; $i--) {
$found = (bool) $exclude;
foreach ($types as $type) {
if ($this->tokens[$i]['code'] === $type) {
$found = !$exclude;
break;
}
}
if ($found === true) {
if ($value === null) {
return $i;
}
else {
if ($this->tokens[$i]['content'] === $value) {
return $i;
}
}
}
if ($local === true) {
if (isset($this->tokens[$i]['scope_opener']) === true && $i === $this->tokens[$i]['scope_closer']) {
$i = $this->tokens[$i]['scope_opener'];
}
else {
if (isset($this->tokens[$i]['bracket_opener']) === true && $i === $this->tokens[$i]['bracket_closer']) {
$i = $this->tokens[$i]['bracket_opener'];
}
else {
if (isset($this->tokens[$i]['parenthesis_opener']) === true && $i === $this->tokens[$i]['parenthesis_closer']) {
$i = $this->tokens[$i]['parenthesis_opener'];
}
else {
if ($this->tokens[$i]['code'] === T_SEMICOLON) {
break;
}
}
}
}
}
}
//end for
return false;
}