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

Breadcrumb

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

function TokenPolyfill::is

Check whether the token is of the given kind. The kind may be either an integer that matches the token ID, a string that matches the token text, or an array of integers/strings. In the latter case, the function returns true if any of the kinds in the array match.

Parameters

int|string|(int|string)[] $kind:

File

vendor/nikic/php-parser/lib/PhpParser/Internal/TokenPolyfill.php, line 69

Class

TokenPolyfill
This is a polyfill for the PhpToken class introduced in PHP 8.0. We do not actually polyfill PhpToken, because composer might end up picking a different polyfill implementation, which does not meet our requirements.

Namespace

PhpParser\Internal

Code

public function is($kind) : bool {
    if (\is_int($kind)) {
        return $this->id === $kind;
    }
    if (\is_string($kind)) {
        return $this->text === $kind;
    }
    if (\is_array($kind)) {
        foreach ($kind as $entry) {
            if (\is_int($entry)) {
                if ($this->id === $entry) {
                    return true;
                }
            }
            elseif (\is_string($entry)) {
                if ($this->text === $entry) {
                    return true;
                }
            }
            else {
                throw new \TypeError('Argument #1 ($kind) must only have elements of type string|int, ' . gettype($entry) . ' given');
            }
        }
        return false;
    }
    throw new \TypeError('Argument #1 ($kind) must be of type string|int|array, ' . gettype($kind) . ' given');
}
RSS feed
Powered by Drupal