class ConstantHelper
@internal
Hierarchy
- class \SlevomatCodingStandard\Helpers\ConstantHelper
Expanded class hierarchy of ConstantHelper
1 file declares its use of ConstantHelper
- ReferenceUsedNamesOnlySniff.php in vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ Namespaces/ ReferenceUsedNamesOnlySniff.php
File
-
vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Helpers/ ConstantHelper.php, line 19
Namespace
SlevomatCodingStandard\HelpersView source
class ConstantHelper {
public static function getName(File $phpcsFile, int $constantPointer) : string {
$tokens = $phpcsFile->getTokens();
return $tokens[TokenHelper::findNext($phpcsFile, T_STRING, $constantPointer + 1)]['content'];
}
public static function getFullyQualifiedName(File $phpcsFile, int $constantPointer) : string {
$name = self::getName($phpcsFile, $constantPointer);
$namespace = NamespaceHelper::findCurrentNamespaceName($phpcsFile, $constantPointer);
return $namespace !== null ? sprintf('%s%s%s%s', NamespaceHelper::NAMESPACE_SEPARATOR, $namespace, NamespaceHelper::NAMESPACE_SEPARATOR, $name) : $name;
}
/**
* @return list<string>
*/
public static function getAllNames(File $phpcsFile) : array {
$previousConstantPointer = 0;
return array_map(static function (int $constantPointer) use ($phpcsFile) : string {
return self::getName($phpcsFile, $constantPointer);
}, array_filter(iterator_to_array(self::getAllConstantPointers($phpcsFile, $previousConstantPointer)), static function (int $constantPointer) use ($phpcsFile) : bool {
foreach (array_reverse($phpcsFile->getTokens()[$constantPointer]['conditions']) as $conditionTokenCode) {
return $conditionTokenCode === T_NAMESPACE;
}
return true;
}));
}
/**
* @return Generator<int>
*/
private static function getAllConstantPointers(File $phpcsFile, int &$previousConstantPointer) : Generator {
do {
$nextConstantPointer = TokenHelper::findNext($phpcsFile, T_CONST, $previousConstantPointer + 1);
if ($nextConstantPointer === null) {
break;
}
$previousConstantPointer = $nextConstantPointer;
(yield $nextConstantPointer);
} while (true);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
ConstantHelper::getAllConstantPointers | private static | function | * |
ConstantHelper::getAllNames | public static | function | * |
ConstantHelper::getFullyQualifiedName | public static | function | |
ConstantHelper::getName | public static | function |