Skip to content

Commit 57e2804

Browse files
authored
feat: NoSuperfluousPhpdocTagsFixer - support asymmetric visibility (#8700)
1 parent 88434aa commit 57e2804

File tree

2 files changed

+84
-1
lines changed

2 files changed

+84
-1
lines changed

src/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixer.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ final class NoSuperfluousPhpdocTagsFixer extends AbstractFixer implements Config
8383
T_FINAL,
8484
T_STATIC,
8585
FCT::T_READONLY,
86+
FCT::T_PRIVATE_SET,
87+
FCT::T_PROTECTED_SET,
88+
FCT::T_PUBLIC_SET,
8689
];
8790

8891
public function getDefinition(): FixerDefinitionInterface
@@ -515,7 +518,7 @@ private function parseTypeHint(Tokens $tokens, int $index): array
515518
while (true) {
516519
$type = '';
517520

518-
if ($tokens[$index]->isGivenKind(FCT::T_READONLY)) {
521+
if ($tokens[$index]->isGivenKind([FCT::T_READONLY, FCT::T_PRIVATE_SET, FCT::T_PROTECTED_SET, FCT::T_PUBLIC_SET])) {
519522
$index = $tokens->getNextMeaningfulToken($index);
520523
}
521524

tests/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixerTest.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3196,4 +3196,84 @@ public function foo(): null { return null; }
31963196
}',
31973197
];
31983198
}
3199+
3200+
/**
3201+
* @dataProvider provideFix84Cases
3202+
*
3203+
* @requires PHP 8.4
3204+
*/
3205+
public function testFix84(string $expected, ?string $input = null): void
3206+
{
3207+
$this->testFix($expected, $input);
3208+
}
3209+
3210+
/**
3211+
* @return iterable<string, array{0: string, 1?: string}>
3212+
*/
3213+
public static function provideFix84Cases(): iterable
3214+
{
3215+
yield 'asymmetric visibility in property' => [
3216+
<<<'PHP'
3217+
<?php class Foo
3218+
{
3219+
/**
3220+
*/
3221+
public public(set) bool $a;
3222+
/**
3223+
*/
3224+
public protected(set) bool $b;
3225+
/**
3226+
*/
3227+
public private(set) bool $c;
3228+
}
3229+
PHP,
3230+
<<<'PHP'
3231+
<?php class Foo
3232+
{
3233+
/**
3234+
* @var bool
3235+
*/
3236+
public public(set) bool $a;
3237+
/**
3238+
* @var bool
3239+
*/
3240+
public protected(set) bool $b;
3241+
/**
3242+
* @var bool
3243+
*/
3244+
public private(set) bool $c;
3245+
}
3246+
PHP,
3247+
];
3248+
3249+
yield 'asymmetric visibility in promoted property' => [
3250+
<<<'PHP'
3251+
<?php class Foo
3252+
{
3253+
/**
3254+
*/
3255+
public function __construct(
3256+
public public(set) bool $a,
3257+
public protected(set) bool $b,
3258+
public private(set) bool $c,
3259+
) {}
3260+
}
3261+
PHP,
3262+
<<<'PHP'
3263+
<?php class Foo
3264+
{
3265+
/**
3266+
* @param bool $a
3267+
* @param bool $b
3268+
* @param bool $c
3269+
*/
3270+
public function __construct(
3271+
public public(set) bool $a,
3272+
public protected(set) bool $b,
3273+
public private(set) bool $c,
3274+
) {}
3275+
}
3276+
PHP,
3277+
];
3278+
}
31993279
}

0 commit comments

Comments
 (0)