Skip to content

Commit 3f40833

Browse files
committed
Update
1 parent 22a6dd4 commit 3f40833

File tree

3 files changed

+51
-7
lines changed

3 files changed

+51
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![Latest stable version](https://img.shields.io/packagist/v/kubawerlos/php-cs-fixer-custom-fixers.svg?label=current%20version)](https://packagist.org/packages/kubawerlos/php-cs-fixer-custom-fixers)
66
[![PHP version](https://img.shields.io/packagist/php-v/kubawerlos/php-cs-fixer-custom-fixers.svg)](https://php.net)
77
[![License](https://img.shields.io/github/license/kubawerlos/php-cs-fixer-custom-fixers.svg)](LICENSE)
8-
![Tests](https://img.shields.io/badge/tests-3637-brightgreen.svg)
8+
![Tests](https://img.shields.io/badge/tests-3640-brightgreen.svg)
99
[![Downloads](https://img.shields.io/packagist/dt/kubawerlos/php-cs-fixer-custom-fixers.svg)](https://packagist.org/packages/kubawerlos/php-cs-fixer-custom-fixers)
1010

1111
[![CI status](https://github.com/kubawerlos/php-cs-fixer-custom-fixers/actions/workflows/ci.yaml/badge.svg)](https://github.com/kubawerlos/php-cs-fixer-custom-fixers/actions/workflows/ci.yaml)

src/Fixer/NoUselessWriteVisibilityFixer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void
7878
private function fixVisibility(Tokens $tokens, int $index, int $kind, bool $makePublicIfNone): void
7979
{
8080
$prevIndex = $tokens->getPrevMeaningfulToken($index);
81+
\assert(\is_int($prevIndex));
82+
while ($tokens[$prevIndex]->isGivenKind([\T_ABSTRACT, \T_READONLY])) {
83+
$prevIndex = $tokens->getPrevMeaningfulToken($prevIndex);
84+
\assert(\is_int($prevIndex));
85+
}
8186

8287
if (!$tokens[$prevIndex]->isGivenKind($this->predecessorKindMap[$kind])) {
8388
if ($makePublicIfNone) {

tests/Fixer/NoUselessWriteVisibilityFixerTest.php

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* @internal
1616
*
1717
* @covers \PhpCsFixerCustomFixers\Fixer\NoUselessWriteVisibilityFixer
18+
*
19+
* @requires PHP >= 8.4
1820
*/
1921
final class NoUselessWriteVisibilityFixerTest extends AbstractFixerTestCase
2022
{
@@ -24,8 +26,6 @@ public function testIsRisky(): void
2426
}
2527

2628
/**
27-
* @requires PHP >= 8.4
28-
*
2929
* @dataProvider provideFixCases
3030
*/
3131
public function testFix(string $expected, ?string $input = null): void
@@ -34,11 +34,11 @@ public function testFix(string $expected, ?string $input = null): void
3434
}
3535

3636
/**
37-
* @return iterable<array{0: string, 1?: string}>
37+
* @return iterable<string, array{0: string, 1?: string}>
3838
*/
3939
public static function provideFixCases(): iterable
4040
{
41-
yield [
41+
yield 'class properties' => [
4242
<<<'PHP'
4343
<?php class Foo {
4444
public $x;
@@ -55,7 +55,7 @@ public static function provideFixCases(): iterable
5555
PHP,
5656
];
5757

58-
yield [
58+
yield 'only write visibility' => [
5959
<<<'PHP'
6060
<?php class Foo {
6161
public $x;
@@ -68,7 +68,7 @@ public static function provideFixCases(): iterable
6868
PHP,
6969
];
7070

71-
yield [
71+
yield 'promoted properties' => [
7272
<<<'PHP'
7373
<?php class Foo {
7474
public function __construct(
@@ -88,5 +88,44 @@ public function __construct(
8888
}
8989
PHP,
9090
];
91+
92+
yield 'readonly property' => [
93+
<<<'PHP'
94+
<?php class Foo {
95+
public readonly $x { get => 'x'; }
96+
}
97+
PHP,
98+
<<<'PHP'
99+
<?php class Foo {
100+
public readonly public(set) $x { get => 'x'; }
101+
}
102+
PHP,
103+
];
104+
105+
yield 'abstract property' => [
106+
<<<'PHP'
107+
<?php abstract class Foo {
108+
public abstract $x { get => 'x'; }
109+
}
110+
PHP,
111+
<<<'PHP'
112+
<?php abstract class Foo {
113+
public abstract public(set) $x { get => 'x'; }
114+
}
115+
PHP,
116+
];
117+
118+
yield 'abstract readonly property' => [
119+
<<<'PHP'
120+
<?php abstract class Foo {
121+
public abstract readonly $x { get => 'x'; }
122+
}
123+
PHP,
124+
<<<'PHP'
125+
<?php abstract class Foo {
126+
public abstract readonly public(set) $x { get => 'x'; }
127+
}
128+
PHP,
129+
];
91130
}
92131
}

0 commit comments

Comments
 (0)