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: TernaryOperatorHelper.php
<?php declare(strict_types = 1); namespace SlevomatCodingStandard\Helpers; use PHP_CodeSniffer\Files\File; use function count; use function in_array; use const T_CASE; use const T_CLOSE_PARENTHESIS; use const T_CLOSE_SHORT_ARRAY; use const T_CLOSE_SQUARE_BRACKET; use const T_COALESCE; use const T_COLON; use const T_COMMA; use const T_DOUBLE_ARROW; use const T_EQUAL; use const T_INLINE_ELSE; use const T_INLINE_THEN; use const T_OPEN_PARENTHESIS; use const T_OPEN_SHORT_ARRAY; use const T_OPEN_SQUARE_BRACKET; use const T_OPEN_TAG; use const T_OPEN_TAG_WITH_ECHO; use const T_RETURN; use const T_SEMICOLON; use const T_THROW; /** * @internal */ class TernaryOperatorHelper { public static function isConditionOfTernaryOperator(File $phpcsFile, int $pointer): bool { $inlineThenPointer = TokenHelper::findNext($phpcsFile, T_INLINE_THEN, $pointer + 1); if ($inlineThenPointer === null) { return false; } $startPointer = self::getStartPointer($phpcsFile, $inlineThenPointer); return $startPointer <= $pointer; } public static function getElsePointer(File $phpcsFile, int $inlineThenPointer): int { $tokens = $phpcsFile->getTokens(); $pointer = $inlineThenPointer; do { $pointer = TokenHelper::findNext( $phpcsFile, [T_INLINE_ELSE, T_OPEN_PARENTHESIS, T_OPEN_SHORT_ARRAY, T_OPEN_SQUARE_BRACKET], $pointer + 1, ); if ($tokens[$pointer]['code'] === T_OPEN_PARENTHESIS) { $pointer = $tokens[$pointer]['parenthesis_closer']; continue; } if (in_array($tokens[$pointer]['code'], [T_OPEN_SHORT_ARRAY, T_OPEN_SQUARE_BRACKET], true)) { $pointer = $tokens[$pointer]['bracket_closer']; continue; } if (ScopeHelper::isInSameScope($phpcsFile, $inlineThenPointer, $pointer)) { break; } } while ($pointer !== null); return $pointer; } public static function getStartPointer(File $phpcsFile, int $inlineThenPointer): int { $tokens = $phpcsFile->getTokens(); $pointerBeforeCondition = $inlineThenPointer; do { $pointerBeforeCondition = TokenHelper::findPrevious( $phpcsFile, [T_EQUAL, T_DOUBLE_ARROW, T_COMMA, T_RETURN, T_THROW, T_CASE, T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO, T_OPEN_SQUARE_BRACKET, T_OPEN_SHORT_ARRAY, T_OPEN_PARENTHESIS], $pointerBeforeCondition - 1, ); if ( in_array($tokens[$pointerBeforeCondition]['code'], [T_OPEN_SQUARE_BRACKET, T_OPEN_SHORT_ARRAY], true) && $tokens[$pointerBeforeCondition]['bracket_closer'] < $inlineThenPointer ) { continue; } if ( $tokens[$pointerBeforeCondition]['code'] === T_OPEN_PARENTHESIS && $tokens[$pointerBeforeCondition]['parenthesis_closer'] < $inlineThenPointer ) { continue; } break; } while (true); return TokenHelper::findNextEffective($phpcsFile, $pointerBeforeCondition + 1); } public static function getEndPointer(File $phpcsFile, int $inlineThenPointer, int $inlineElsePointer): int { $tokens = $phpcsFile->getTokens(); $pointerAfterInlineElseEnd = $inlineElsePointer; do { $pointerAfterInlineElseEnd = TokenHelper::findNext( $phpcsFile, [T_SEMICOLON, T_COLON, T_COMMA, T_DOUBLE_ARROW, T_CLOSE_PARENTHESIS, T_CLOSE_SHORT_ARRAY, T_CLOSE_SQUARE_BRACKET, T_COALESCE], $pointerAfterInlineElseEnd + 1, ); if ($pointerAfterInlineElseEnd === null) { continue; } if ($tokens[$pointerAfterInlineElseEnd]['code'] === T_CLOSE_PARENTHESIS) { if ($tokens[$pointerAfterInlineElseEnd]['parenthesis_opener'] < $inlineThenPointer) { break; } } elseif (in_array($tokens[$pointerAfterInlineElseEnd]['code'], [T_CLOSE_SHORT_ARRAY, T_CLOSE_SQUARE_BRACKET], true)) { if ($tokens[$pointerAfterInlineElseEnd]['bracket_opener'] < $inlineThenPointer) { break; } } elseif ($tokens[$pointerAfterInlineElseEnd]['code'] === T_COMMA) { $previousPointer = TokenHelper::findPrevious( $phpcsFile, [T_OPEN_PARENTHESIS, T_OPEN_SHORT_ARRAY], $pointerAfterInlineElseEnd - 1, $inlineThenPointer, ); if ($previousPointer === null) { break; } if ( $tokens[$previousPointer]['code'] === T_OPEN_PARENTHESIS && $tokens[$previousPointer]['parenthesis_closer'] < $pointerAfterInlineElseEnd ) { break; } if ( $tokens[$previousPointer]['code'] === T_OPEN_SHORT_ARRAY && $tokens[$previousPointer]['bracket_closer'] < $pointerAfterInlineElseEnd ) { break; } } elseif ($tokens[$pointerAfterInlineElseEnd]['code'] === T_DOUBLE_ARROW) { $previousPointer = TokenHelper::findPrevious( $phpcsFile, T_OPEN_SHORT_ARRAY, $pointerAfterInlineElseEnd - 1, $inlineThenPointer, ); if ($previousPointer === null) { break; } } elseif (ScopeHelper::isInSameScope($phpcsFile, $inlineElsePointer, $pointerAfterInlineElseEnd)) { break; } } while ($pointerAfterInlineElseEnd !== null); if ($pointerAfterInlineElseEnd !== null) { return TokenHelper::findPreviousEffective($phpcsFile, $pointerAfterInlineElseEnd - 1); } return TokenHelper::findPreviousEffective($phpcsFile, count($tokens) - 1); } }
Save