Skip to content

Commit f8b1a81

Browse files
authored
feat: BracesPositionFixer - support property hooks in promoted properties (#8613)
1 parent 9d6fdfe commit f8b1a81

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

src/Fixer/Basic/BracesPositionFixer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,9 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
228228
$positionOption = 'classes_opening_brace';
229229
}
230230
} elseif ($token->isGivenKind(T_FUNCTION)) {
231-
$openBraceIndex = $tokens->getNextTokenOfKind($index, ['{', ';']);
231+
$openBraceIndex = $tokens->getNextTokenOfKind($index, ['{', ';', [CT::T_PROPERTY_HOOK_BRACE_OPEN]]);
232232

233-
if ($tokens[$openBraceIndex]->equals(';')) {
233+
if (!$tokens[$openBraceIndex]->equals('{')) {
234234
continue;
235235
}
236236

tests/Fixer/Basic/BracesPositionFixerTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,4 +881,37 @@ function foo(
881881
}',
882882
];
883883
}
884+
885+
/**
886+
* @dataProvider provideFix84Cases
887+
*
888+
* @requires PHP 8.4
889+
*/
890+
public function testFix84(string $expected, ?string $input = null): void
891+
{
892+
$this->doTest($expected, $input);
893+
}
894+
895+
/**
896+
* @return iterable<string, array{0: string, 1?: string}>
897+
*/
898+
public static function provideFix84Cases(): iterable
899+
{
900+
yield 'property hook in promoted property' => [
901+
<<<'PHP'
902+
<?php class CarPark
903+
{
904+
public function __construct(
905+
public Car $car {
906+
set(Car $car)
907+
{
908+
$this->car = $car;
909+
$this->car->parked();
910+
}
911+
},
912+
) {}
913+
}
914+
PHP,
915+
];
916+
}
884917
}

0 commit comments

Comments
 (0)