Skip to content

Commit

Permalink
Deprecate PhpdocTypeListFixer (#960)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos committed Feb 3, 2024
1 parent 559b405 commit 60cb712
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 7 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
@@ -1,7 +1,11 @@
# CHANGELOG for PHP CS Fixer: custom fixers

## v3.20.0
- Deprecate PhpdocTypeListFixer - use "phpdoc_list_type"
- Update minimum PHP CS Fixer version to 3.49.0

## v3.19.0
- Deprecate NumericLiteralSeparatorFixer - use "numeric_literal_separator "
- Deprecate NumericLiteralSeparatorFixer - use "numeric_literal_separator"
- Update minimum PHP CS Fixer version to 3.47.0

## v3.18.0
Expand Down
3 changes: 2 additions & 1 deletion README.md
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-3534-brightgreen.svg)
![Tests](https://img.shields.io/badge/tests-3535-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 @@ -548,6 +548,7 @@ The `@var` annotation must be on a single line if it is the only content.

#### PhpdocTypeListFixer
PHPDoc type `list` must be used instead of `array` without a key type.
DEPRECATED: use `phpdoc_list_type` instead.
```diff
<?php
/**
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -13,7 +13,7 @@
"php": "^7.4 || ^8.0",
"ext-filter": "*",
"ext-tokenizer": "*",
"friendsofphp/php-cs-fixer": "^3.47"
"friendsofphp/php-cs-fixer": "^3.49"
},
"require-dev": {
"phpunit/phpunit": "^9.6.4 || ^10.0.14"
Expand Down
38 changes: 34 additions & 4 deletions src/Fixer/PhpdocTypeListFixer.php
Expand Up @@ -11,13 +11,25 @@

namespace PhpCsFixerCustomFixers\Fixer;

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

final class PhpdocTypeListFixer extends AbstractTypesFixer
/**
* @deprecated
*/
final class PhpdocTypeListFixer extends AbstractFixer implements DeprecatedFixerInterface
{
private PhpdocListTypeFixer $phpdocListTypeFixer;

public function __construct()
{
$this->phpdocListTypeFixer = new PhpdocListTypeFixer();
}

public function getDefinition(): FixerDefinitionInterface
{
return new FixerDefinition(
Expand All @@ -41,8 +53,26 @@ public function getPriority(): int
return 1;
}

protected function fixType(string $type): string
public function isCandidate(Tokens $tokens): bool
{
return $this->phpdocListTypeFixer->isCandidate($tokens);
}

public function isRisky(): bool
{
return false;
}

public function fix(\SplFileInfo $file, Tokens $tokens): void
{
$this->phpdocListTypeFixer->fix($file, $tokens);
}

/**
* @return list<string>
*/
public function getSuccessorsNames(): array
{
return Preg::replace('/array(?=<[^,]+(>|<|{|\\())/', 'list', $type);
return [$this->phpdocListTypeFixer->getName()];
}
}
5 changes: 5 additions & 0 deletions tests/Fixer/PhpdocTypeListFixerTest.php
Expand Up @@ -23,6 +23,11 @@ public function testIsRisky(): void
self::assertRiskiness(false);
}

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

/**
* @dataProvider provideFixCases
*/
Expand Down

0 comments on commit 60cb712

Please sign in to comment.