diff --git a/src/TokenRunner/Analyzer/FixerAnalyzer/BlockFinder.php b/src/TokenRunner/Analyzer/FixerAnalyzer/BlockFinder.php index f00eb166..9f296234 100644 --- a/src/TokenRunner/Analyzer/FixerAnalyzer/BlockFinder.php +++ b/src/TokenRunner/Analyzer/FixerAnalyzer/BlockFinder.php @@ -54,6 +54,11 @@ public function findInTokensByEdge(Tokens $tokens, int $position): ?BlockInfo if ($token->isGivenKind([T_FUNCTION, CT::T_USE_LAMBDA, T_NEW])) { $position = $tokens->getNextTokenOfKind($position, ['(', ';']); + + if ($position === null) { + return null; + } + /** @var Token $token */ $token = $tokens[$position]; diff --git a/tests/Issues/Fixture/line_length_parentheses.php.inc b/tests/Issues/Fixture/line_length_parentheses.php.inc new file mode 100644 index 00000000..b9c9d759 --- /dev/null +++ b/tests/Issues/Fixture/line_length_parentheses.php.inc @@ -0,0 +1,21 @@ + +----- + diff --git a/tests/Issues/LineLengthParenthesesTest.php b/tests/Issues/LineLengthParenthesesTest.php new file mode 100644 index 00000000..2297a0b5 --- /dev/null +++ b/tests/Issues/LineLengthParenthesesTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + yield [__DIR__ . '/Fixture/line_length_parentheses.php.inc']; + } + + public function provideConfig(): string + { + return __DIR__ . '/config/line_length_parentheses.php'; + } +} diff --git a/tests/Issues/config/line_length_parentheses.php b/tests/Issues/config/line_length_parentheses.php new file mode 100644 index 00000000..124a20cd --- /dev/null +++ b/tests/Issues/config/line_length_parentheses.php @@ -0,0 +1,18 @@ +rules([ + LineLengthFixer::class, + ]); + + $ecsConfig->ruleWithConfiguration(NewWithParenthesesFixer::class, [ + 'anonymous_class' => false, + 'named_class' => false, + ]); +}; \ No newline at end of file