From 3d1bb75be0df6c6fba4487c75b9e425a2c1d27c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Wer=C5=82os?= Date: Sat, 24 Feb 2024 09:53:34 +0100 Subject: [PATCH] Deprecate PhpdocArrayStyleFixer (#966) --- CHANGELOG.md | 4 +++ README.md | 3 +- composer.json | 2 +- src/Fixer/PhpdocArrayStyleFixer.php | 42 ++++++++++++++++++----- tests/Fixer/PhpdocArrayStyleFixerTest.php | 5 +++ 5 files changed, 46 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 704a680b..c66c87d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG for PHP CS Fixer: custom fixers +## v3.21.0 +- Deprecate PhpdocArrayStyleFixer - use "phpdoc_array_type" +- Update minimum PHP CS Fixer version to 3.50.0 + ## v3.20.0 - Deprecate PhpdocTypeListFixer - use "phpdoc_list_type" - Update minimum PHP CS Fixer version to 3.49.0 diff --git a/README.md b/README.md index de844816..97e20842 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![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) [![PHP version](https://img.shields.io/packagist/php-v/kubawerlos/php-cs-fixer-custom-fixers.svg)](https://php.net) [![License](https://img.shields.io/github/license/kubawerlos/php-cs-fixer-custom-fixers.svg)](LICENSE) -![Tests](https://img.shields.io/badge/tests-3540-brightgreen.svg) +![Tests](https://img.shields.io/badge/tests-3541-brightgreen.svg) [![Downloads](https://img.shields.io/packagist/dt/kubawerlos/php-cs-fixer-custom-fixers.svg)](https://packagist.org/packages/kubawerlos/php-cs-fixer-custom-fixers) [![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 #### PhpdocArrayStyleFixer Generic array style should be used in PHPDoc. + DEPRECATED: use `phpdoc_array_type` instead. ```diff phpdocArrayTypeFixer = new PhpdocArrayTypeFixer(); + } + public function getDefinition(): FixerDefinitionInterface { return new FixerDefinition( @@ -41,15 +53,29 @@ function foo() { return [1, 2]; } */ public function getPriority(): int { - return 2; + return $this->phpdocArrayTypeFixer->getPriority(); + } + + public function isCandidate(Tokens $tokens): bool + { + return $this->phpdocArrayTypeFixer->isCandidate($tokens); + } + + public function isRisky(): bool + { + return false; } - protected function fixType(string $type): string + public function fix(\SplFileInfo $file, Tokens $tokens): void { - do { - $type = Preg::replace('/([\\\a-zA-Z0-9_>]+)\[\]/', 'array<$1>', $type, -1, $count); - } while ($count > 0); + $this->phpdocArrayTypeFixer->fix($file, $tokens); + } - return $type; + /** + * @return list + */ + public function getSuccessorsNames(): array + { + return [$this->phpdocArrayTypeFixer->getName()]; } } diff --git a/tests/Fixer/PhpdocArrayStyleFixerTest.php b/tests/Fixer/PhpdocArrayStyleFixerTest.php index 37fa2c72..7ca1bcdf 100644 --- a/tests/Fixer/PhpdocArrayStyleFixerTest.php +++ b/tests/Fixer/PhpdocArrayStyleFixerTest.php @@ -23,6 +23,11 @@ public function testIsRisky(): void self::assertRiskiness(false); } + public function testSuccessorName(): void + { + self::assertSuccessorName('phpdoc_array_type'); + } + /** * @dataProvider provideFixCases */