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: DocCommentHelper.php
<?php declare(strict_types = 1); namespace SlevomatCodingStandard\Helpers; use PHP_CodeSniffer\Files\File; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTextNode; use PHPStan\PhpDocParser\Parser\ParserException; use PHPStan\PhpDocParser\Parser\TokenIterator; use function count; use function in_array; use function preg_match; use function sprintf; use function stripos; use function strtolower; use function trim; use const T_ABSTRACT; use const T_ATTRIBUTE; use const T_CLASS; use const T_CLOSE_CURLY_BRACKET; use const T_CONST; use const T_DOC_COMMENT_CLOSE_TAG; use const T_DOC_COMMENT_OPEN_TAG; use const T_DOC_COMMENT_STAR; use const T_DOC_COMMENT_STRING; use const T_DOC_COMMENT_TAG; use const T_DOC_COMMENT_WHITESPACE; use const T_ENUM; use const T_FINAL; use const T_FUNCTION; use const T_INTERFACE; use const T_OPEN_CURLY_BRACKET; use const T_PRIVATE; use const T_PROTECTED; use const T_PUBLIC; use const T_READONLY; use const T_SEMICOLON; use const T_STATIC; use const T_TRAIT; use const T_VAR; use const T_VARIABLE; use const T_WHITESPACE; /** * @internal */ class DocCommentHelper { public static function hasDocComment(File $phpcsFile, int $pointer): bool { return self::findDocCommentOpenPointer($phpcsFile, $pointer) !== null; } public static function getDocComment(File $phpcsFile, int $pointer): ?string { $docCommentOpenToken = self::findDocCommentOpenPointer($phpcsFile, $pointer); if ($docCommentOpenToken === null) { return null; } return trim( TokenHelper::getContent( $phpcsFile, $docCommentOpenToken, $phpcsFile->getTokens()[$docCommentOpenToken]['comment_closer'], ), ); } /** * @return list<Comment>|null */ public static function getDocCommentDescription(File $phpcsFile, int $pointer): ?array { $docCommentOpenPointer = self::findDocCommentOpenPointer($phpcsFile, $pointer); if ($docCommentOpenPointer === null) { return null; } $tokens = $phpcsFile->getTokens(); $descriptionStartPointer = TokenHelper::findNextExcluding( $phpcsFile, [T_DOC_COMMENT_WHITESPACE, T_DOC_COMMENT_STAR], $docCommentOpenPointer + 1, $tokens[$docCommentOpenPointer]['comment_closer'], ); if ($descriptionStartPointer === null) { return null; } if ($tokens[$descriptionStartPointer]['code'] !== T_DOC_COMMENT_STRING) { return null; } $tokenAfterDescriptionPointer = TokenHelper::findNext( $phpcsFile, [T_DOC_COMMENT_TAG, T_DOC_COMMENT_CLOSE_TAG], $descriptionStartPointer + 1, $tokens[$docCommentOpenPointer]['comment_closer'] + 1, ); /** @var list<Comment> $comments */ $comments = []; for ($i = $descriptionStartPointer; $i < $tokenAfterDescriptionPointer; $i++) { if ($tokens[$i]['code'] !== T_DOC_COMMENT_STRING) { continue; } $comments[] = new Comment($i, trim($tokens[$i]['content'])); } return count($comments) > 0 ? $comments : null; } public static function hasInheritdocAnnotation(File $phpcsFile, int $pointer): bool { $docCommentOpenPointer = self::findDocCommentOpenPointer($phpcsFile, $pointer); if ($docCommentOpenPointer === null) { return false; } $parsedDocComment = self::parseDocComment($phpcsFile, $docCommentOpenPointer); if ($parsedDocComment === null) { return false; } foreach ($parsedDocComment->getNode()->children as $child) { if ($child instanceof PhpDocTagNode) { if (strtolower($child->name) === '@inheritdoc') { return true; } if (stripos((string) $child->value, '{@inheritdoc}') !== false) { return true; } } if ($child instanceof PhpDocTextNode && stripos($child->text, '{@inheritdoc}') !== false) { return true; } } return false; } public static function hasDocCommentDescription(File $phpcsFile, int $pointer): bool { return self::getDocCommentDescription($phpcsFile, $pointer) !== null; } public static function findDocCommentOpenPointer(File $phpcsFile, int $pointer): ?int { return SniffLocalCache::getAndSetIfNotCached( $phpcsFile, sprintf('doc-comment-open-pointer-%d', $pointer), static function () use ($phpcsFile, $pointer): ?int { $tokens = $phpcsFile->getTokens(); if ($tokens[$pointer]['code'] === T_DOC_COMMENT_OPEN_TAG) { return $pointer; } $found = TokenHelper::findPrevious( $phpcsFile, [T_DOC_COMMENT_CLOSE_TAG, T_SEMICOLON, T_CLOSE_CURLY_BRACKET, T_OPEN_CURLY_BRACKET], $pointer - 1, ); if ($found !== null && $tokens[$found]['code'] === T_DOC_COMMENT_CLOSE_TAG) { return $tokens[$found]['comment_opener']; } return null; }, ); } public static function findDocCommentOwnerPointer(File $phpcsFile, int $docCommentOpenPointer): ?int { $tokens = $phpcsFile->getTokens(); $docCommentCloserPointer = $tokens[$docCommentOpenPointer]['comment_closer']; if (self::isInline($phpcsFile, $docCommentOpenPointer)) { return null; } $docCommentOwnerPointer = null; for ($i = $docCommentCloserPointer + 1; $i < count($tokens); $i++) { if ($tokens[$i]['code'] === T_ATTRIBUTE) { $i = $tokens[$i]['attribute_closer']; continue; } if (in_array( $tokens[$i]['code'], [T_PUBLIC, T_PROTECTED, T_PRIVATE, T_VAR, T_READONLY, T_FINAL, T_STATIC, T_ABSTRACT, T_WHITESPACE], true, )) { continue; } if (in_array( $tokens[$i]['code'], [T_FUNCTION, T_VARIABLE, T_CONST, ...TokenHelper::CLASS_TYPE_TOKEN_CODES], true, )) { $docCommentOwnerPointer = $i; } break; } return $docCommentOwnerPointer; } public static function isInline(File $phpcsFile, int $docCommentOpenPointer): bool { $tokens = $phpcsFile->getTokens(); $nextPointer = TokenHelper::findNextNonWhitespace($phpcsFile, $tokens[$docCommentOpenPointer]['comment_closer'] + 1); if ( $nextPointer !== null && in_array( $tokens[$nextPointer]['code'], [T_PUBLIC, T_PROTECTED, T_PRIVATE, T_READONLY, T_FINAL, T_STATIC, T_ABSTRACT, T_CONST, T_CLASS, T_INTERFACE, T_TRAIT, T_ENUM, T_ATTRIBUTE], true, ) ) { return false; } $parsedDocComment = self::parseDocComment($phpcsFile, $docCommentOpenPointer); if ($parsedDocComment === null) { return false; } foreach ($parsedDocComment->getNode()->getTags() as $annotation) { if (preg_match('~^@(?:(?:phpstan|psalm)-)?var~i', $annotation->name) === 1) { return true; } } return false; } public static function parseDocComment(File $phpcsFile, int $docCommentOpenPointer): ?ParsedDocComment { return SniffLocalCache::getAndSetIfNotCached( $phpcsFile, sprintf('parsed-doc-comment-%d', $docCommentOpenPointer), static function () use ($phpcsFile, $docCommentOpenPointer): ?ParsedDocComment { $docComment = self::getDocComment($phpcsFile, $docCommentOpenPointer); $docCommentTokens = new TokenIterator(PhpDocParserHelper::getLexer()->tokenize($docComment)); try { $parsedDocComment = PhpDocParserHelper::getParser()->parse($docCommentTokens); return new ParsedDocComment( $docCommentOpenPointer, $phpcsFile->getTokens()[$docCommentOpenPointer]['comment_closer'], $parsedDocComment, $docCommentTokens, ); } catch (ParserException $e) { return null; } }, ); } }
Save