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

Breadcrumb

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

function IncludeSystemSniff::getIncludedClassFromToken

Determines the included class name from given token.

Parameters

\PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found.:

array $tokens The array of file tokens.:

int $stackPtr The position in the tokens array of the: potentially included class.

Return value

string|false

2 calls to IncludeSystemSniff::getIncludedClassFromToken()
IncludeSystemSniff::processTokenOutsideScope in vendor/squizlabs/php_codesniffer/src/Standards/MySource/Sniffs/Channels/IncludeSystemSniff.php
Processes a token within the scope that this test is listening to.
IncludeSystemSniff::processTokenWithinScope in vendor/squizlabs/php_codesniffer/src/Standards/MySource/Sniffs/Channels/IncludeSystemSniff.php
Processes the function tokens within the class.

File

vendor/squizlabs/php_codesniffer/src/Standards/MySource/Sniffs/Channels/IncludeSystemSniff.php, line 293

Class

IncludeSystemSniff

Namespace

PHP_CodeSniffer\Standards\MySource\Sniffs\Channels

Code

protected function getIncludedClassFromToken(File $phpcsFile, array $tokens, $stackPtr) {
    if (strtolower($tokens[$stackPtr]['content']) === 'includesystem') {
        $systemName = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, $stackPtr + 1);
        $systemName = trim($tokens[$systemName]['content'], " '");
        return strtolower($systemName);
    }
    else {
        if (strtolower($tokens[$stackPtr]['content']) === 'includeasset') {
            $typeName = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, $stackPtr + 1);
            $typeName = trim($tokens[$typeName]['content'], " '");
            return strtolower($typeName) . 'assettype';
        }
        else {
            if (isset(Tokens::$includeTokens[$tokens[$stackPtr]['code']]) === true) {
                $filePath = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, $stackPtr + 1);
                $filePath = $tokens[$filePath]['content'];
                $filePath = trim($filePath, " '");
                $filePath = basename($filePath, '.inc');
                return strtolower($filePath);
            }
        }
    }
    return false;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal