Skip to content

Commit

Permalink
PhpdocNoIncorrectVarAnnotationFixer - support promoted properties (#922)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos committed Nov 19, 2023
1 parent d753404 commit bbfb4ff
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,8 @@
# CHANGELOG for PHP CS Fixer: custom fixers

## v3.17.0
- PhpdocNoIncorrectVarAnnotationFixer - support promoted properties

## v3.16.0
- Deprecate DataProviderReturnTypeFixer - use "php_unit_data_provider_return_type"
- Update minimum PHP CS Fixer version to 3.22.0
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -3,7 +3,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-3454-brightgreen.svg)
![Tests](https://img.shields.io/badge/tests-3455-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/workflows/CI/badge.svg?branch=main)](https://github.com/kubawerlos/php-cs-fixer-custom-fixers/actions)
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/PhpdocNoIncorrectVarAnnotationFixer.php
Expand Up @@ -70,7 +70,7 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void
continue;
}

if ($tokens[$nextIndex]->isGivenKind([\T_PRIVATE, \T_PROTECTED, \T_PUBLIC, \T_VAR, \T_STATIC])) {
if ($tokens[$nextIndex]->isGivenKind([\T_PRIVATE, \T_PROTECTED, \T_PUBLIC, \T_VAR, \T_STATIC, CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PUBLIC, CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PROTECTED, CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PRIVATE])) {
$this->removeForClassElement($tokens, $index, $nextIndex);
continue;
}
Expand Down
16 changes: 16 additions & 0 deletions tests/Fixer/PhpdocNoIncorrectVarAnnotationFixerTest.php
Expand Up @@ -267,6 +267,22 @@ class Foo
private int|string $intOrString;
}',
];

yield 'keep correct PHPDoc for promoted properties, PHP 8.0' => [
'<?php class Foo
{
public function __construct(
/** @var array<Foo> */
public array $a,
/** @var array<Foo> */
public array $b,
/** @var array<Foo> */
protected array $c,
/** @var array<Foo> */
private array $d,
) {}
}',
];
}

if (\PHP_VERSION_ID >= 80100) {
Expand Down

0 comments on commit bbfb4ff

Please sign in to comment.