From eb1e3d5dccd14cbb52b46db60e2a4956553e9063 Mon Sep 17 00:00:00 2001 From: SpacePossum Date: Fri, 4 Feb 2022 10:42:48 +0000 Subject: [PATCH] =?UTF-8?q?TokensAnalyzer=20-=20fix=20isConstantInvocation?= =?UTF-8?q?=20detection=20for=20mulitple=20exce=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Tokenizer/TokensAnalyzer.php | 5 +++++ tests/AutoReview/FixerFactoryTest.php | 4 ++-- .../NativeConstantInvocationFixerTest.php | 18 +++++++++++++---- tests/Tokenizer/TokensAnalyzerTest.php | 20 +++++++++++++++++++ 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/Tokenizer/TokensAnalyzer.php b/src/Tokenizer/TokensAnalyzer.php index b69254504b1..2e589de719a 100644 --- a/src/Tokenizer/TokensAnalyzer.php +++ b/src/Tokenizer/TokensAnalyzer.php @@ -381,6 +381,11 @@ public function isConstantInvocation(int $index): bool } // check for non-capturing catches + + while ($this->tokens[$prevIndex]->isGivenKind([CT::T_NAMESPACE_OPERATOR, T_NS_SEPARATOR, T_STRING, CT::T_TYPE_ALTERNATION])) { + $prevIndex = $this->tokens->getPrevMeaningfulToken($prevIndex); + } + if ($this->tokens[$prevIndex]->equals('(')) { $prevPrevIndex = $this->tokens->getPrevMeaningfulToken($prevIndex); diff --git a/tests/AutoReview/FixerFactoryTest.php b/tests/AutoReview/FixerFactoryTest.php index ddbe087353e..80fc59dd4e2 100644 --- a/tests/AutoReview/FixerFactoryTest.php +++ b/tests/AutoReview/FixerFactoryTest.php @@ -62,7 +62,7 @@ public function testFixersPriority(): void foreach ($edges as $edge) { $second = $fixers[$edge]; - static::assertLessThan($first->getPriority(), $second->getPriority(), sprintf('"%s" should have less priority than "%s"', $fixerName, $edge)); + static::assertLessThan($first->getPriority(), $second->getPriority(), sprintf('"%s" should have less priority than "%s"', $edge, $fixerName)); } } } @@ -232,7 +232,7 @@ public function testFixersPriorityComment(): void ksort($fixersPhpDocIssues); foreach ($fixersPhpDocIssues as $fixerName => $issue) { - $message .= sprintf("\n--------------------------------------------------\n%s\n%s", $fixerName, $issue); + $message .= sprintf("\n--------------------------------------------------\n%s\n%s", $fixers[$fixerName]['short_classname'], $issue); } static::fail($message); diff --git a/tests/Fixer/ConstantNotation/NativeConstantInvocationFixerTest.php b/tests/Fixer/ConstantNotation/NativeConstantInvocationFixerTest.php index a66cbeb6bc1..4faf2536f3f 100644 --- a/tests/Fixer/ConstantNotation/NativeConstantInvocationFixerTest.php +++ b/tests/Fixer/ConstantNotation/NativeConstantInvocationFixerTest.php @@ -489,16 +489,26 @@ public function testFixPrePHP80(): void } /** + * @dataProvider provideFix80Cases * @requires PHP 8.0 */ - public function testFixPhp80(): void + public function testFixPhp80(string $expected): void { $this->fixer->configure(['strict' => true]); - $this->doTest( + $this->doTest($expected); + } + + public function provideFix80Cases(): iterable + { + yield [ ' false, 5 => false, 12 => false], ' [ + [5 => false, 15 => false, 18 => false], + ' [ + [5 => false, 15 => false, 18 => false], + ' [ + [5 => false, 15 => false, 17 => false, 19 => false, 21 => false, 24 => false, 27 => false], + ' [ + [5 => false, 14 => false, 16 => false, 19 => false, 22 => false], + '