Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify single uses of Token::isGivenKind #3919

Merged
merged 1 commit into from Jul 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Fixer/Alias/NoAliasFunctionsFixer.php
Expand Up @@ -132,7 +132,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
}

// handle function reference with namespaces
if ($prevToken->isGivenKind([T_NS_SEPARATOR])) {
if ($prevToken->isGivenKind(T_NS_SEPARATOR)) {
$twicePrevTokenIndex = $tokens->getPrevMeaningfulToken($prevTokenIndex);
$twicePrevToken = $tokens[$twicePrevTokenIndex];
if ($twicePrevToken->isGivenKind([T_DOUBLE_COLON, T_NEW, T_OBJECT_OPERATOR, T_FUNCTION, T_STRING, CT::T_NAMESPACE_OPERATOR])) {
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Basic/BracesFixer.php
Expand Up @@ -565,7 +565,7 @@ static function ($item) {
if (
self::LINE_SAME === $this->configuration['position_after_functions_and_oop_constructs']
&& (
$token->isGivenKind([T_FUNCTION]) && !$tokensAnalyzer->isLambda($index)
$token->isGivenKind(T_FUNCTION) && !$tokensAnalyzer->isLambda($index)
|| $token->isGivenKind($classyTokens) && !$tokensAnalyzer->isAnonymousClass($index)
)
&& !$tokens[$tokens->getPrevNonWhitespace($startBraceIndex)]->isComment()
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Casing/LowercaseStaticReferenceFixer.php
Expand Up @@ -95,7 +95,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
continue;
}

if ('static' === $newContent && $tokens[$nextIndex]->isGivenKind([T_VARIABLE])) {
if ('static' === $newContent && $tokens[$nextIndex]->isGivenKind(T_VARIABLE)) {
continue;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Fixer/ControlStructure/NoBreakCommentFixer.php
Expand Up @@ -335,7 +335,7 @@ private function getStructureEnd(Tokens $tokens, $position)
Tokens::BLOCK_TYPE_PARENTHESIS_BRACE,
$tokens->getNextTokenOfKind($position, ['('])
);
} elseif ($initialToken->isGivenKind([T_CLASS])) {
} elseif ($initialToken->isGivenKind(T_CLASS)) {
$openParenthesisPosition = $tokens->getNextMeaningfulToken($position);
if ('(' === $tokens[$openParenthesisPosition]->getContent()) {
$position = $tokens->findBlockEnd(
Expand All @@ -352,7 +352,7 @@ private function getStructureEnd(Tokens $tokens, $position)

$position = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $position);

if ($initialToken->isGivenKind([T_DO])) {
if ($initialToken->isGivenKind(T_DO)) {
$position = $tokens->findBlockEnd(
Tokens::BLOCK_TYPE_PARENTHESIS_BRACE,
$tokens->getNextTokenOfKind($position, ['('])
Expand Down
4 changes: 2 additions & 2 deletions src/Fixer/Import/OrderedImportsFixer.php
Expand Up @@ -343,9 +343,9 @@ private function getNewOrder(array $uses, Tokens $tokens)
$previous = $tokens->getPrevMeaningfulToken($endIndex);

$group = $tokens[$previous]->isGivenKind(CT::T_GROUP_IMPORT_BRACE_CLOSE);
if ($tokens[$startIndex]->isGivenKind([CT::T_CONST_IMPORT])) {
if ($tokens[$startIndex]->isGivenKind(CT::T_CONST_IMPORT)) {
$type = self::IMPORT_TYPE_CONST;
} elseif ($tokens[$startIndex]->isGivenKind([CT::T_FUNCTION_IMPORT])) {
} elseif ($tokens[$startIndex]->isGivenKind(CT::T_FUNCTION_IMPORT)) {
$type = self::IMPORT_TYPE_FUNCTION;
} else {
$type = self::IMPORT_TYPE_CLASS;
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/LanguageConstruct/DirConstantFixer.php
Expand Up @@ -66,7 +66,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
$fileCandidateRight = $tokens[$fileCandidateRightIndex];
$fileCandidateLeftIndex = $tokens->getNextMeaningfulToken($openParenthesis);
$fileCandidateLeft = $tokens[$fileCandidateLeftIndex];
if (!$fileCandidateRight->isGivenKind([T_FILE]) || !$fileCandidateLeft->isGivenKind([T_FILE])) {
if (!$fileCandidateRight->isGivenKind(T_FILE) || !$fileCandidateLeft->isGivenKind(T_FILE)) {
continue;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Fixer/PhpUnit/PhpUnitInternalClassFixer.php
Expand Up @@ -116,11 +116,11 @@ private function markClassInternal(Tokens $tokens, $startIndex)
private function isAllowedByConfiguration(Tokens $tokens, $i)
{
$typeIndex = $tokens->getPrevMeaningfulToken($i);
if ($tokens[$typeIndex]->isGivenKind([T_FINAL])) {
if ($tokens[$typeIndex]->isGivenKind(T_FINAL)) {
return in_array('final', $this->configuration['types'], true);
}

if ($tokens[$typeIndex]->isGivenKind([T_ABSTRACT])) {
if ($tokens[$typeIndex]->isGivenKind(T_ABSTRACT)) {
return in_array('abstract', $this->configuration['types'], true);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Tokenizer/Analyzer/CommentsAnalyzer.php
Expand Up @@ -43,7 +43,7 @@ public function isHeaderComment(Tokens $tokens, $index)

$prevIndex = $tokens->getPrevMeaningfulToken($index);

return $tokens[$prevIndex]->isGivenKind([T_OPEN_TAG]) && null !== $tokens->getNextMeaningfulToken($index);
return $tokens[$prevIndex]->isGivenKind(T_OPEN_TAG) && null !== $tokens->getNextMeaningfulToken($index);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Tokenizer/Analyzer/NamespaceUsesAnalyzer.php
Expand Up @@ -83,7 +83,7 @@ private function parseDeclaration(Tokens $tokens, $startIndex, $endIndex)
$type = NamespaceUseAnalysis::TYPE_CONSTANT;
}

if ($token->isWhitespace() || $token->isComment() || $token->isGivenKind([T_USE])) {
if ($token->isWhitespace() || $token->isComment() || $token->isGivenKind(T_USE)) {
continue;
}

Expand Down
12 changes: 6 additions & 6 deletions src/Tokenizer/TokensAnalyzer.php
Expand Up @@ -202,39 +202,39 @@ public function getMethodAttributes($index)
$i = $tokenIndex;
$token = $tokens[$tokenIndex];

if ($token->isGivenKind([T_STATIC])) {
if ($token->isGivenKind(T_STATIC)) {
$attributes['static'] = true;

continue;
}

if ($token->isGivenKind([T_FINAL])) {
if ($token->isGivenKind(T_FINAL)) {
$attributes['final'] = true;

continue;
}

if ($token->isGivenKind([T_ABSTRACT])) {
if ($token->isGivenKind(T_ABSTRACT)) {
$attributes['abstract'] = true;

continue;
}

// visibility

if ($token->isGivenKind([T_PRIVATE])) {
if ($token->isGivenKind(T_PRIVATE)) {
$attributes['visibility'] = T_PRIVATE;

continue;
}

if ($token->isGivenKind([T_PROTECTED])) {
if ($token->isGivenKind(T_PROTECTED)) {
$attributes['visibility'] = T_PROTECTED;

continue;
}

if ($token->isGivenKind([T_PUBLIC])) {
if ($token->isGivenKind(T_PUBLIC)) {
$attributes['visibility'] = T_PUBLIC;

continue;
Expand Down