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

ClassReferenceNameCasingFixer - Fix for double arrow #6279

Merged
merged 1 commit into from Feb 9, 2022
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/AbstractNoUselessElseFixer.php
Expand Up @@ -68,7 +68,7 @@ protected function isSuperfluousElse(Tokens $tokens, int $index): bool
return false;
}

if ($tokens[$candidateIndex]->equals([T_THROW])) {
if ($tokens[$candidateIndex]->isGivenKind(T_THROW)) {
$previousIndex = $tokens->getPrevMeaningfulToken($candidateIndex);

if (!$tokens[$previousIndex]->equalsAny([';', '{'])) {
Expand Down
Expand Up @@ -121,7 +121,7 @@ private function fixSpacing(int $index, Tokens $tokens): void

if (
$currentToken->equals(',') && !$tokens[$prevIndex]->isComment()
&& (true === $this->configuration['after_heredoc'] || !$tokens[$prevIndex]->equals([T_END_HEREDOC]))
&& (true === $this->configuration['after_heredoc'] || !$tokens[$prevIndex]->isGivenKind(T_END_HEREDOC))
) {
$tokens->removeLeadingWhitespace($i);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Fixer/Casing/ClassReferenceNameCasingFixer.php
Expand Up @@ -78,6 +78,7 @@ private function getClassReference(Tokens $tokens, NamespaceAnalysis $namespace)
T_CASE, // PHP 8.1 trait enum-case
T_CLASS,
T_CONST,
T_DOUBLE_ARROW,
T_DOUBLE_COLON,
T_FUNCTION,
T_INTERFACE,
Expand Down Expand Up @@ -120,7 +121,7 @@ private function getClassReference(Tokens $tokens, NamespaceAnalysis $namespace)
continue;
}

if (!$tokens[$prevIndex]->isGivenKind([T_NEW]) && $tokens[$nextIndex]->equals('(')) {
if (!$tokens[$prevIndex]->isGivenKind(T_NEW) && $tokens[$nextIndex]->equals('(')) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/ControlStructure/NoBreakCommentFixer.php
Expand Up @@ -154,7 +154,7 @@ private function fixCase(Tokens $tokens, int $casePosition): void
continue;
}

if ($tokens[$i]->isGivenKind([T_THROW])) {
if ($tokens[$i]->isGivenKind(T_THROW)) {
$previousIndex = $tokens->getPrevMeaningfulToken($i);

if ($previousIndex === $casePosition || $tokens[$previousIndex]->equalsAny(['{', ';', '}', [T_OPEN_TAG]])) {
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Import/SingleImportPerStatementFixer.php
Expand Up @@ -130,7 +130,7 @@ private function getGroupStatements(Tokens $tokens, string $groupPrefix, int $gr
for ($i = $groupOpenIndex + 1; $i <= $groupCloseIndex; ++$i) {
$token = $tokens[$i];

if ($token->equals(',') && $tokens[$tokens->getNextMeaningfulToken($i)]->equals([CT::T_GROUP_IMPORT_BRACE_CLOSE])) {
if ($token->equals(',') && $tokens[$tokens->getNextMeaningfulToken($i)]->isGivenKind(CT::T_GROUP_IMPORT_BRACE_CLOSE)) {
continue;
}

Expand Down
Expand Up @@ -169,7 +169,7 @@ protected function applyPhpUnitClassFix(Tokens $tokens, int $startIndex, int $en
$expectedTypeTokenIndex = $tokens->getNextMeaningfulToken($bracketTokenIndex);
$expectedTypeToken = $tokens[$expectedTypeTokenIndex];

if (!$expectedTypeToken->equals([T_CONSTANT_ENCAPSED_STRING])) {
if (!$expectedTypeToken->isGivenKind(T_CONSTANT_ENCAPSED_STRING)) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Tokenizer/AbstractTypeTransformer.php
Expand Up @@ -56,7 +56,7 @@ protected function doProcess(Tokens $tokens, int $index, $originalToken): void

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

if ($tokens[$prevPrevTokenIndex]->isGivenKind([T_CATCH])) {
if ($tokens[$prevPrevTokenIndex]->isGivenKind(T_CATCH)) {
$this->replaceToken($tokens, $index);

return;
Expand Down
Expand Up @@ -51,7 +51,7 @@ public function getRequiredPhpVersionId(): int
*/
public function process(Tokens $tokens, Token $token, int $index): void
{
if (!$tokens[$index]->equals('(') || !$tokens[$tokens->getNextMeaningfulToken($index)]->equals([T_NEW])) {
if (!$tokens[$index]->equals('(') || !$tokens[$tokens->getNextMeaningfulToken($index)]->isGivenKind(T_NEW)) {
return;
}

Expand Down
21 changes: 21 additions & 0 deletions tests/Fixer/Casing/ClassReferenceNameCasingFixerTest.php
Expand Up @@ -137,6 +137,10 @@ public function provideFixCases(): \Generator
'<?php class Foo { use exception; }',
];

yield [
'<?php $foo = ["const" => exception];',
SpacePossum marked this conversation as resolved.
Show resolved Hide resolved
];

yield [
'<?php
namespace {
Expand Down Expand Up @@ -181,6 +185,23 @@ public function provideFixCases(): \Generator
'<?php try { foo(); } catch(\LogicException $e) {}',
'<?php try { foo(); } catch(\logicexception $e) {}',
];

yield [
'<?php
Closure::bind(fn () => null, null, new class {});
\Closure::bind(fn () => null, null, new class {});

Foo\Bar::bind(fn () => null, null, new class {});
\A\B\\Bar::bind(fn () => null, null, new class {});
',
'<?php
CLOSURE::bind(fn () => null, null, new class {});
\CLOSURE::bind(fn () => null, null, new class {});

Foo\Bar::bind(fn () => null, null, new class {});
\A\B\\Bar::bind(fn () => null, null, new class {});
',
];
}

/**
Expand Down