Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. File.php

function File::findFirstOnLine

Returns the position of the first token on a line, matching given type.

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.

bool $exclude If true, find the token that is NOT of: the types specified in $types.

string $value The value that the token must be equal to.: If value is omitted, tokens with any value will be returned.

Return value

int|false The first token which matches on the line containing the start token, between the start of the line and the start token. Note: The first token matching might be the start token. FALSE when no matching token could be found between the start of the line and the start token.

File

vendor/squizlabs/php_codesniffer/src/Files/File.php, line 2727

Class

File

Namespace

PHP_CodeSniffer\Files

Code

public function findFirstOnLine($types, $start, $exclude = false, $value = null) {
    if (is_array($types) === false) {
        $types = [
            $types,
        ];
    }
    $foundToken = false;
    for ($i = $start; $i >= 0; $i--) {
        if ($this->tokens[$i]['line'] < $this->tokens[$start]['line']) {
            break;
        }
        $found = $exclude;
        foreach ($types as $type) {
            if ($exclude === false) {
                if ($this->tokens[$i]['code'] === $type) {
                    $found = true;
                    break;
                }
            }
            else {
                if ($this->tokens[$i]['code'] === $type) {
                    $found = false;
                    break;
                }
            }
        }
        if ($found === true) {
            if ($value === null) {
                $foundToken = $i;
            }
            else {
                if ($this->tokens[$i]['content'] === $value) {
                    $foundToken = $i;
                }
            }
        }
    }
    
    //end for
    return $foundToken;
}
RSS feed
Powered by Drupal