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

Breadcrumb

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

function Tokens::getHighestWeightedToken

Returns the highest weighted token type.

Tokens are weighted by their approximate frequency of appearance in code

  • the less frequently they appear in the code, the higher the weighting.

For example T_CLASS tokens appear very infrequently in a file, and therefore have a high weighting.

If there are no weightings for any of the specified tokens, the first token seen in the passed array will be returned.

Parameters

array<int|string> $tokens The token types to get the highest weighted: type for.

Return value

int The highest weighted token. On equal "weight", returns the first token of that particular weight.

1 call to Tokens::getHighestWeightedToken()
AbstractPatternSniff::getListenerTokenPos in vendor/squizlabs/php_codesniffer/src/Sniffs/AbstractPatternSniff.php
Returns the position in the pattern that this test should register as a listener for the pattern.

File

vendor/squizlabs/php_codesniffer/src/Util/Tokens.php, line 789

Class

Tokens

Namespace

PHP_CodeSniffer\Util

Code

public static function getHighestWeightedToken(array $tokens) {
    $highest = -1;
    $highestType = false;
    $weights = self::$weightings;
    foreach ($tokens as $token) {
        if (isset($weights[$token]) === true) {
            $weight = $weights[$token];
        }
        else {
            $weight = 0;
        }
        if ($weight > $highest) {
            $highest = $weight;
            $highestType = $token;
        }
    }
    return $highestType;
}

API Navigation

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