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

Breadcrumb

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

function File::findExtendedClassName

Returns the name of the class that the specified class extends. (works for classes, anonymous classes and interfaces)

Returns FALSE on error or if there is no extended class name.

Parameters

int $stackPtr The stack position of the class.:

Return value

string|false

File

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

Class

File

Namespace

PHP_CodeSniffer\Files

Code

public function findExtendedClassName($stackPtr) {
    // Check for the existence of the token.
    if (isset($this->tokens[$stackPtr]) === false) {
        return false;
    }
    if ($this->tokens[$stackPtr]['code'] !== T_CLASS && $this->tokens[$stackPtr]['code'] !== T_ANON_CLASS && $this->tokens[$stackPtr]['code'] !== T_INTERFACE) {
        return false;
    }
    if (isset($this->tokens[$stackPtr]['scope_opener']) === false) {
        return false;
    }
    $classOpenerIndex = $this->tokens[$stackPtr]['scope_opener'];
    $extendsIndex = $this->findNext(T_EXTENDS, $stackPtr, $classOpenerIndex);
    if ($extendsIndex === false) {
        return false;
    }
    $find = [
        T_NS_SEPARATOR,
        T_STRING,
        T_WHITESPACE,
    ];
    $end = $this->findNext($find, $extendsIndex + 1, $classOpenerIndex + 1, true);
    $name = $this->getTokensAsString($extendsIndex + 1, $end - $extendsIndex - 1);
    $name = trim($name);
    if ($name === '') {
        return false;
    }
    return $name;
}
RSS feed
Powered by Drupal