Skip to content

Commit 3d1bb75

Browse files
authored
Deprecate PhpdocArrayStyleFixer (#966)
1 parent 5a66d72 commit 3d1bb75

File tree

5 files changed

+46
-10
lines changed

5 files changed

+46
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG for PHP CS Fixer: custom fixers
22

3+
## v3.21.0
4+
- Deprecate PhpdocArrayStyleFixer - use "phpdoc_array_type"
5+
- Update minimum PHP CS Fixer version to 3.50.0
6+
37
## v3.20.0
48
- Deprecate PhpdocTypeListFixer - use "phpdoc_list_type"
59
- Update minimum PHP CS Fixer version to 3.49.0

README.md

Lines changed: 2 additions & 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-3540-brightgreen.svg)
8+
![Tests](https://img.shields.io/badge/tests-3541-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)
@@ -449,6 +449,7 @@ PHPUnit `fail`, `markTestIncomplete` and `markTestSkipped` functions must not be
449449

450450
#### PhpdocArrayStyleFixer
451451
Generic array style should be used in PHPDoc.
452+
DEPRECATED: use `phpdoc_array_type` instead.
452453
```diff
453454
<?php
454455
/**

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"php": "^7.4 || ^8.0",
1414
"ext-filter": "*",
1515
"ext-tokenizer": "*",
16-
"friendsofphp/php-cs-fixer": "^3.49"
16+
"friendsofphp/php-cs-fixer": "^3.50"
1717
},
1818
"require-dev": {
1919
"phpunit/phpunit": "^9.6.4 || ^10.0.14"

src/Fixer/PhpdocArrayStyleFixer.php

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,25 @@
1111

1212
namespace PhpCsFixerCustomFixers\Fixer;
1313

14+
use PhpCsFixer\Fixer\DeprecatedFixerInterface;
15+
use PhpCsFixer\Fixer\Phpdoc\PhpdocArrayTypeFixer;
1416
use PhpCsFixer\FixerDefinition\CodeSample;
1517
use PhpCsFixer\FixerDefinition\FixerDefinition;
1618
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
17-
use PhpCsFixer\Preg;
19+
use PhpCsFixer\Tokenizer\Tokens;
1820

19-
final class PhpdocArrayStyleFixer extends AbstractTypesFixer
21+
/**
22+
* @deprecated
23+
*/
24+
final class PhpdocArrayStyleFixer extends AbstractFixer implements DeprecatedFixerInterface
2025
{
26+
private PhpdocArrayTypeFixer $phpdocArrayTypeFixer;
27+
28+
public function __construct()
29+
{
30+
$this->phpdocArrayTypeFixer = new PhpdocArrayTypeFixer();
31+
}
32+
2133
public function getDefinition(): FixerDefinitionInterface
2234
{
2335
return new FixerDefinition(
@@ -41,15 +53,29 @@ function foo() { return [1, 2]; }
4153
*/
4254
public function getPriority(): int
4355
{
44-
return 2;
56+
return $this->phpdocArrayTypeFixer->getPriority();
57+
}
58+
59+
public function isCandidate(Tokens $tokens): bool
60+
{
61+
return $this->phpdocArrayTypeFixer->isCandidate($tokens);
62+
}
63+
64+
public function isRisky(): bool
65+
{
66+
return false;
4567
}
4668

47-
protected function fixType(string $type): string
69+
public function fix(\SplFileInfo $file, Tokens $tokens): void
4870
{
49-
do {
50-
$type = Preg::replace('/([\\\a-zA-Z0-9_>]+)\[\]/', 'array<$1>', $type, -1, $count);
51-
} while ($count > 0);
71+
$this->phpdocArrayTypeFixer->fix($file, $tokens);
72+
}
5273

53-
return $type;
74+
/**
75+
* @return list<string>
76+
*/
77+
public function getSuccessorsNames(): array
78+
{
79+
return [$this->phpdocArrayTypeFixer->getName()];
5480
}
5581
}

tests/Fixer/PhpdocArrayStyleFixerTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ public function testIsRisky(): void
2323
self::assertRiskiness(false);
2424
}
2525

26+
public function testSuccessorName(): void
27+
{
28+
self::assertSuccessorName('phpdoc_array_type');
29+
}
30+
2631
/**
2732
* @dataProvider provideFixCases
2833
*/

0 commit comments

Comments
 (0)