PATH:
opt
/
cpanel
/
ea-wappspector
/
vendor
/
slevomat
/
coding-standard
/
SlevomatCodingStandard
/
Helpers
<?php declare(strict_types = 1); namespace SlevomatCodingStandard\Helpers; use Generator; use PHP_CodeSniffer\Files\File; use function array_filter; use function array_map; use function array_reverse; use function array_values; use function iterator_to_array; use function sprintf; use const T_CONST; use const T_NAMESPACE; use const T_STRING; /** * @internal */ 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 fn (int $constantPointer): string => self::getName($phpcsFile, $constantPointer), array_values(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); } }
[-] Attribute.php
[edit]
[-] ArrayHelper.php
[edit]
[-] TernaryOperatorHelper.php
[edit]
[-] ConstantHelper.php
[edit]
[-] CatchHelper.php
[edit]
[+]
..
[-] TypeHint.php
[edit]
[-] ConditionHelper.php
[edit]
[-] IndentationHelper.php
[edit]
[-] SuppressHelper.php
[edit]
[-] TokenPointerOutOfBoundsException.php
[edit]
[-] VariableHelper.php
[edit]
[-] StringHelper.php
[edit]
[-] TypeHintHelper.php
[edit]
[-] AnnotationHelper.php
[edit]
[-] SniffLocalCache.php
[edit]
[-] ReferencedNameHelper.php
[edit]
[-] NamespaceHelper.php
[edit]
[-] ScopeHelper.php
[edit]
[-] ParameterHelper.php
[edit]
[-] AnnotationTypeHelper.php
[edit]
[-] TokenHelper.php
[edit]
[-] DocCommentHelper.php
[edit]
[-] AttributeHelper.php
[edit]
[-] Comment.php
[edit]
[-] SniffSettingsHelper.php
[edit]
[-] UseStatement.php
[edit]
[-] FunctionHelper.php
[edit]
[-] YodaHelper.php
[edit]
[-] IdentificatorHelper.php
[edit]
[-] PropertyHelper.php
[edit]
[-] UseStatementHelper.php
[edit]
[-] FixerHelper.php
[edit]
[-] PhpDocParserHelper.php
[edit]
[-] CommentHelper.php
[edit]
[-] Annotation.php
[edit]
[-] ArrayKeyValue.php
[edit]
[-] TypeHelper.php
[edit]
[-] ClassHelper.php
[edit]
[-] ParsedDocComment.php
[edit]
[-] EmptyFileException.php
[edit]
[-] ReferencedName.php
[edit]