Skip to content

Commit 560c193

Browse files
committed
patched BracesPositionFixer, allows { on next line in multiline function declaration
Preserves this format: private static function isEqual( mixed $expected, mixed $actual, ): bool {
1 parent da1031b commit 560c193

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

preset-fixer/common/Nette.php

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
// overriden rules
3333

3434
// Curly braces must be placed as configured
35+
'braces_position' => false,
3536
'Nette/braces_position' => true,
3637

3738
// Each statement must be indented

src/Fixer/BracesPositionFixer.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -298,12 +298,14 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
298298
if (self::NEXT_LINE_UNLESS_NEWLINE_AT_SIGNATURE_END === $this->configuration[$positionOption]) {
299299
$whitespace = $this->whitespacesConfig->getLineEnding().$this->getLineIndentation($tokens, $index);
300300

301-
$previousTokenIndex = $openBraceIndex;
301+
$colon = false;
302+
$previousTokenIndex = $openBraceIndex;
302303
do {
303304
$previousTokenIndex = $tokens->getPrevMeaningfulToken($previousTokenIndex);
305+
$colon = $colon || $tokens[$previousTokenIndex]->isGivenKind([CT::T_TYPE_COLON]);
304306
} while ($tokens[$previousTokenIndex]->isGivenKind([CT::T_TYPE_COLON, CT::T_NULLABLE_TYPE, T_STRING, T_NS_SEPARATOR, CT::T_ARRAY_TYPEHINT, T_STATIC, CT::T_TYPE_ALTERNATION, CT::T_TYPE_INTERSECTION, T_CALLABLE, CT::T_DISJUNCTIVE_NORMAL_FORM_TYPE_PARENTHESIS_OPEN, CT::T_DISJUNCTIVE_NORMAL_FORM_TYPE_PARENTHESIS_CLOSE]));
305307

306-
if ($tokens[$previousTokenIndex]->equals(')')) {
308+
if (!$colon && $tokens[$previousTokenIndex]->equals(')')) {
307309
if ($tokens[--$previousTokenIndex]->isComment()) {
308310
--$previousTokenIndex;
309311
}
@@ -439,4 +441,9 @@ private function hasCommentOnSameLine(Tokens $tokens, int $index): bool
439441

440442
return $token->isComment();
441443
}
444+
445+
public function getName(): string
446+
{
447+
return 'Nette/' . parent::getName();
448+
}
442449
}

0 commit comments

Comments
 (0)