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 */ 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 */ 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); } }