Skip to content

Commit

Permalink
bug #6279 ClassReferenceNameCasingFixer - Fix for double arrow (Space…
Browse files Browse the repository at this point in the history
…Possum)

This PR was squashed before being merged into the master branch (closes #6279).

Discussion
----------

ClassReferenceNameCasingFixer - Fix for double arrow

closes #6278

Commits
-------

004f634 ClassReferenceNameCasingFixer - Fix for double arrow
  • Loading branch information
SpacePossum committed Feb 9, 2022
2 parents dbd830d + 004f634 commit 17823f7
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 8 deletions.
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];',
];

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

0 comments on commit 17823f7

Please sign in to comment.