Skip to content

Commit 580825c

Browse files
authored
feat: SingleClassElementPerStatementFixer - support asymmetric visibility (#8696)
1 parent dad95b1 commit 580825c

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/Fixer/ClassNotation/SingleClassElementPerStatementFixer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ private function expandElement(Tokens $tokens, string $type, int $startIndex, in
213213
private function getModifiersSequences(Tokens $tokens, string $type, int $startIndex, int $endIndex): array
214214
{
215215
if ('property' === $type) {
216-
$tokenKinds = [T_PUBLIC, T_PROTECTED, T_PRIVATE, T_STATIC, T_VAR, T_STRING, T_NS_SEPARATOR, CT::T_NULLABLE_TYPE, CT::T_ARRAY_TYPEHINT, CT::T_TYPE_ALTERNATION, CT::T_TYPE_INTERSECTION, FCT::T_READONLY];
216+
$tokenKinds = [T_PUBLIC, T_PROTECTED, T_PRIVATE, T_STATIC, T_VAR, T_STRING, T_NS_SEPARATOR, CT::T_NULLABLE_TYPE, CT::T_ARRAY_TYPEHINT, CT::T_TYPE_ALTERNATION, CT::T_TYPE_INTERSECTION, FCT::T_READONLY, FCT::T_PRIVATE_SET, FCT::T_PROTECTED_SET, FCT::T_PUBLIC_SET];
217217
} else {
218218
$tokenKinds = [T_PUBLIC, T_PROTECTED, T_PRIVATE, T_CONST];
219219
}

tests/Fixer/ClassNotation/SingleClassElementPerStatementFixerTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,42 @@ public static function provideFix82Cases(): iterable
987987
];
988988
}
989989

990+
/**
991+
* @dataProvider provideFix84Cases
992+
*
993+
* @requires PHP 8.4
994+
*/
995+
public function testFix84(string $expected, ?string $input = null): void
996+
{
997+
$this->doTest($expected, $input);
998+
}
999+
1000+
/**
1001+
* @return iterable<string, array{string, string}>
1002+
*/
1003+
public static function provideFix84Cases(): iterable
1004+
{
1005+
yield 'asymmetric visibility' => [
1006+
<<<'PHP'
1007+
<?php trait Foo {
1008+
public public(set) int $a;
1009+
public public(set) int $b;
1010+
public protected(set) int $c;
1011+
public protected(set) int $d;
1012+
public private(set) int $e;
1013+
public private(set) int $f;
1014+
}
1015+
PHP,
1016+
<<<'PHP'
1017+
<?php trait Foo {
1018+
public public(set) int $a, $b;
1019+
public protected(set) int $c, $d;
1020+
public private(set) int $e, $f;
1021+
}
1022+
PHP,
1023+
];
1024+
}
1025+
9901026
public function testInvalidConfiguration(): void
9911027
{
9921028
$this->expectException(InvalidFixerConfigurationException::class);

0 commit comments

Comments
 (0)