Skip to content

Commit

Permalink
Deprecate PhpdocArrayStyleFixer (#966)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos authored Feb 24, 2024
1 parent 5a66d72 commit 3d1bb75
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
<?php
/**
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"php": "^7.4 || ^8.0",
"ext-filter": "*",
"ext-tokenizer": "*",
"friendsofphp/php-cs-fixer": "^3.49"
"friendsofphp/php-cs-fixer": "^3.50"
},
"require-dev": {
"phpunit/phpunit": "^9.6.4 || ^10.0.14"
Expand Down
42 changes: 34 additions & 8 deletions src/Fixer/PhpdocArrayStyleFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,25 @@

namespace PhpCsFixerCustomFixers\Fixer;

use PhpCsFixer\Fixer\DeprecatedFixerInterface;
use PhpCsFixer\Fixer\Phpdoc\PhpdocArrayTypeFixer;
use PhpCsFixer\FixerDefinition\CodeSample;
use PhpCsFixer\FixerDefinition\FixerDefinition;
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
use PhpCsFixer\Preg;
use PhpCsFixer\Tokenizer\Tokens;

final class PhpdocArrayStyleFixer extends AbstractTypesFixer
/**
* @deprecated
*/
final class PhpdocArrayStyleFixer extends AbstractFixer implements DeprecatedFixerInterface
{
private PhpdocArrayTypeFixer $phpdocArrayTypeFixer;

public function __construct()
{
$this->phpdocArrayTypeFixer = new PhpdocArrayTypeFixer();
}

public function getDefinition(): FixerDefinitionInterface
{
return new FixerDefinition(
Expand All @@ -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<string>
*/
public function getSuccessorsNames(): array
{
return [$this->phpdocArrayTypeFixer->getName()];
}
}
5 changes: 5 additions & 0 deletions tests/Fixer/PhpdocArrayStyleFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public function testIsRisky(): void
self::assertRiskiness(false);
}

public function testSuccessorName(): void
{
self::assertSuccessorName('phpdoc_array_type');
}

/**
* @dataProvider provideFixCases
*/
Expand Down

0 comments on commit 3d1bb75

Please sign in to comment.