golden hour
/opt/cpanel/ea-wappspector/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers
⬆️ Go Up
Upload
File/Folder
Size
Actions
Annotation.php
1.11 KB
Del
OK
AnnotationHelper.php
8.67 KB
Del
OK
AnnotationTypeHelper.php
10.15 KB
Del
OK
ArrayHelper.php
6.25 KB
Del
OK
ArrayKeyValue.php
3.6 KB
Del
OK
Attribute.php
1.14 KB
Del
OK
AttributeHelper.php
5 KB
Del
OK
CatchHelper.php
2.18 KB
Del
OK
ClassHelper.php
3.03 KB
Del
OK
Comment.php
430 B
Del
OK
CommentHelper.php
2.52 KB
Del
OK
ConditionHelper.php
10.2 KB
Del
OK
ConstantHelper.php
2.03 KB
Del
OK
DocCommentHelper.php
7.12 KB
Del
OK
EmptyFileException.php
502 B
Del
OK
FixerHelper.php
1.97 KB
Del
OK
FunctionHelper.php
16.55 KB
Del
OK
IdentificatorHelper.php
7.34 KB
Del
OK
IndentationHelper.php
2.84 KB
Del
OK
NamespaceHelper.php
5.8 KB
Del
OK
ParameterHelper.php
893 B
Del
OK
ParsedDocComment.php
2.27 KB
Del
OK
PhpDocParserHelper.php
1.56 KB
Del
OK
PropertyHelper.php
6.39 KB
Del
OK
ReferencedName.php
1.32 KB
Del
OK
ReferencedNameHelper.php
15.13 KB
Del
OK
ScopeHelper.php
1.48 KB
Del
OK
SniffLocalCache.php
1.2 KB
Del
OK
SniffSettingsHelper.php
2.01 KB
Del
OK
StringHelper.php
485 B
Del
OK
SuppressHelper.php
2.27 KB
Del
OK
TernaryOperatorHelper.php
4.97 KB
Del
OK
TokenHelper.php
12.87 KB
Del
OK
TokenPointerOutOfBoundsException.php
774 B
Del
OK
TypeHelper.php
740 B
Del
OK
TypeHint.php
966 B
Del
OK
TypeHintHelper.php
10.67 KB
Del
OK
UseStatement.php
2.53 KB
Del
OK
UseStatementHelper.php
7.82 KB
Del
OK
VariableHelper.php
5.03 KB
Del
OK
YodaHelper.php
9.28 KB
Del
OK
Edit: AttributeHelper.php
<?php declare(strict_types = 1); namespace SlevomatCodingStandard\Helpers; use PHP_CodeSniffer\Files\File; use function array_map; use function in_array; use const T_ANON_CLASS; use const T_ATTRIBUTE; use const T_ATTRIBUTE_END; use const T_CLASS; use const T_CLOSE_CURLY_BRACKET; use const T_CLOSURE; use const T_COMMA; use const T_CONST; use const T_ENUM; use const T_ENUM_CASE; use const T_FN; use const T_FUNCTION; use const T_INTERFACE; use const T_OPEN_CURLY_BRACKET; use const T_OPEN_PARENTHESIS; use const T_SEMICOLON; use const T_TRAIT; use const T_VARIABLE; /** * @internal */ class AttributeHelper { private const ATTRIBUTE_TARGETS = [ T_ANON_CLASS, T_CLASS, T_CLOSURE, T_CONST, T_ENUM, T_ENUM_CASE, T_FN, T_FUNCTION, T_INTERFACE, T_TRAIT, T_VARIABLE, ]; public static function hasAttribute(File $phpcsFile, int $pointer, string $attributeName): bool { $attributeNames = array_map( static fn (Attribute $name): string => $name->getFullyQualifiedName(), self::getAttributes($phpcsFile, $pointer), ); return in_array($attributeName, $attributeNames, true); } /** * @return list<Attribute> */ public static function getAttributes(File $phpcsFile, int $pointer): array { $tokens = $phpcsFile->getTokens(); if ($tokens[$pointer]['code'] !== T_ATTRIBUTE) { $attributeOpenerPointer = null; do { $attributeEndPointerCandidate = TokenHelper::findPrevious( $phpcsFile, [T_ATTRIBUTE_END, T_SEMICOLON, T_CLOSE_CURLY_BRACKET, T_OPEN_CURLY_BRACKET], $attributeOpenerPointer ?? $pointer - 1, ); if ( $attributeEndPointerCandidate === null || $tokens[$attributeEndPointerCandidate]['code'] !== T_ATTRIBUTE_END ) { break; } $attributeOpenerPointer = $tokens[$attributeEndPointerCandidate]['attribute_opener']; } while (true); if ($attributeOpenerPointer === null) { return []; } } else { $attributeOpenerPointer = $pointer; } $attributeCloserPointer = $tokens[$attributeOpenerPointer]['attribute_closer']; $actualPointer = $attributeOpenerPointer; $attributes = []; do { $attributeNameStartPointer = TokenHelper::findNextEffective($phpcsFile, $actualPointer + 1, $attributeCloserPointer); if ($attributeNameStartPointer === null) { break; } $attributeNameEndPointer = TokenHelper::findNextExcluding( $phpcsFile, TokenHelper::NAME_TOKEN_CODES, $attributeNameStartPointer + 1, ) - 1; $attributeName = TokenHelper::getContent($phpcsFile, $attributeNameStartPointer, $attributeNameEndPointer); $pointerAfterAttributeName = TokenHelper::findNextEffective($phpcsFile, $attributeNameEndPointer + 1, $attributeCloserPointer); if ($pointerAfterAttributeName === null) { $attributes[] = new Attribute( $attributeOpenerPointer, $attributeName, NamespaceHelper::resolveClassName($phpcsFile, $attributeName, $attributeOpenerPointer), $attributeNameStartPointer, $attributeNameEndPointer, ); break; } if ($tokens[$pointerAfterAttributeName]['code'] === T_COMMA) { $attributes[] = new Attribute( $attributeOpenerPointer, $attributeName, NamespaceHelper::resolveClassName($phpcsFile, $attributeName, $attributeOpenerPointer), $attributeNameStartPointer, $attributeNameEndPointer, ); $actualPointer = $pointerAfterAttributeName; } if ($tokens[$pointerAfterAttributeName]['code'] === T_OPEN_PARENTHESIS) { $attributes[] = new Attribute( $attributeOpenerPointer, $attributeName, NamespaceHelper::resolveClassName($phpcsFile, $attributeName, $attributeOpenerPointer), $attributeNameStartPointer, $tokens[$pointerAfterAttributeName]['parenthesis_closer'], TokenHelper::getContent( $phpcsFile, $pointerAfterAttributeName, $tokens[$pointerAfterAttributeName]['parenthesis_closer'], ), ); $actualPointer = TokenHelper::findNextEffective( $phpcsFile, $tokens[$pointerAfterAttributeName]['parenthesis_closer'] + 1, $attributeCloserPointer, ); continue; } } while ($actualPointer !== null); return $attributes; } /** * Attributes have syntax that when defined incorrectly or in older PHP version, they are treated as comments. * An example of incorrect declaration is variables that are not properties. */ public static function isValidAttribute(File $phpcsFile, int $attributeOpenerPointer): bool { return self::getAttributeTarget($phpcsFile, $attributeOpenerPointer) !== null; } public static function getAttributeTarget(File $phpcsFile, int $attributeOpenerPointer): ?int { $attributeTargetPointer = TokenHelper::findNext($phpcsFile, self::ATTRIBUTE_TARGETS, $attributeOpenerPointer); if ($attributeTargetPointer === null) { return null; } if ( $phpcsFile->getTokens()[$attributeTargetPointer]['code'] === T_VARIABLE && !PropertyHelper::isProperty($phpcsFile, $attributeTargetPointer) && !ParameterHelper::isParameter($phpcsFile, $attributeTargetPointer) ) { return null; } return $attributeTargetPointer; } }
Save