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
Namespace
PHP_CodeSniffer\UtilCode
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;
}