function UseStatementHelper::isImportUse
7 calls to UseStatementHelper::isImportUse()
- LineLengthSniff::checkLineLength in vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ Files/ LineLengthSniff.php - MultipleUsesPerLineSniff::process in vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ Namespaces/ MultipleUsesPerLineSniff.php - * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
- UseDoesNotStartWithBackslashSniff::process in vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ Namespaces/ UseDoesNotStartWithBackslashSniff.php - * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
- UseFromSameNamespaceSniff::process in vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ Namespaces/ UseFromSameNamespaceSniff.php - * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
- UseOnlyWhitelistedNamespacesSniff::process in vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ Namespaces/ UseOnlyWhitelistedNamespacesSniff.php - * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
File
-
vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Helpers/ UseStatementHelper.php, line 33
Class
- UseStatementHelper
- @internal
Namespace
SlevomatCodingStandard\HelpersCode
public static function isImportUse(File $phpcsFile, int $usePointer) : bool {
$tokens = $phpcsFile->getTokens();
$nextPointer = TokenHelper::findNextEffective($phpcsFile, $usePointer + 1);
// Anonymous function use
if ($tokens[$nextPointer]['code'] === T_OPEN_PARENTHESIS) {
return false;
}
if ($tokens[$nextPointer]['code'] === T_STRING && in_array(strtolower($tokens[$nextPointer]['content']), [
'function',
'const',
], true)) {
return true;
}
$previousPointer = TokenHelper::findPrevious($phpcsFile, [
T_OPEN_TAG,
T_DECLARE,
T_NAMESPACE,
T_OPEN_CURLY_BRACKET,
T_CLOSE_CURLY_BRACKET,
], $usePointer);
if (in_array($tokens[$previousPointer]['code'], [
T_OPEN_TAG,
T_DECLARE,
T_NAMESPACE,
], true)) {
return true;
}
if (array_key_exists('scope_condition', $tokens[$previousPointer])) {
$scopeConditionPointer = $tokens[$previousPointer]['scope_condition'];
if ($tokens[$previousPointer]['code'] === T_OPEN_CURLY_BRACKET && in_array($tokens[$scopeConditionPointer]['code'], TokenHelper::$typeWithAnonymousClassKeywordTokenCodes, true)) {
return false;
}
// Trait use after another trait use
if ($tokens[$scopeConditionPointer]['code'] === T_USE) {
return false;
}
// Trait use after method or import use after function
if ($tokens[$scopeConditionPointer]['code'] === T_FUNCTION) {
return ClassHelper::getClassPointer($phpcsFile, $usePointer) === null;
}
}
return true;
}