class ScopeHelper
@internal
Hierarchy
- class \SlevomatCodingStandard\Helpers\ScopeHelper
Expanded class hierarchy of ScopeHelper
8 files declare their use of ScopeHelper
- ClassMemberSpacingSniff.php in vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ Classes/ ClassMemberSpacingSniff.php - DisallowImplicitArrayCreationSniff.php in vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ Arrays/ DisallowImplicitArrayCreationSniff.php - EarlyExitSniff.php in vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ ControlStructures/ EarlyExitSniff.php - RequireArrowFunctionSniff.php in vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ Functions/ RequireArrowFunctionSniff.php - RequireExplicitAssertionSniff.php in vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ PHP/ RequireExplicitAssertionSniff.php
File
-
vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Helpers/ ScopeHelper.php, line 13
Namespace
SlevomatCodingStandard\HelpersView source
class ScopeHelper {
public static function isInSameScope(File $phpcsFile, int $firstPointer, int $secondPointer) : bool {
$tokens = $phpcsFile->getTokens();
$getScope = static function (int $pointer) use ($tokens) : int {
$scope = 0;
foreach (array_reverse($tokens[$pointer]['conditions'], true) as $conditionPointer => $conditionTokenCode) {
if (!in_array($conditionTokenCode, TokenHelper::$functionTokenCodes, true)) {
continue;
}
$scope = $tokens[$conditionPointer]['level'] + 1;
break;
}
return $scope;
};
return $getScope($firstPointer) === $getScope($secondPointer);
}
public static function getRootPointer(File $phpcsFile, int $pointer) : int {
$rootPointer = TokenHelper::findNext($phpcsFile, T_OPEN_TAG, 0);
$rootPointers = array_reverse(self::getAllRootPointers($phpcsFile));
foreach ($rootPointers as $currentRootPointer) {
if ($currentRootPointer < $pointer) {
$rootPointer = $currentRootPointer;
break;
}
}
return $rootPointer;
}
/**
* @return list<int>
*/
public static function getAllRootPointers(File $phpcsFile) : array {
$lazyValue = static function () use ($phpcsFile) : array {
return TokenHelper::findNextAll($phpcsFile, T_OPEN_TAG, 0);
};
return SniffLocalCache::getAndSetIfNotCached($phpcsFile, 'openTagPointers', $lazyValue);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
ScopeHelper::getAllRootPointers | public static | function | * |
ScopeHelper::getRootPointer | public static | function | |
ScopeHelper::isInSameScope | public static | function |