Skip to content

Commit 25adefa

Browse files
authored
Add PhpdocArrayStyleFixer (#421)
1 parent df778d2 commit 25adefa

32 files changed

+303
-50
lines changed

CHANGELOG.md

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

3+
## v3.1.0
4+
- Add PhpdocArrayStyleFixer
5+
36
## v3.0.0
47
- Drop support for PHP CS Fixer v2
58
- Add StringableInterfaceFixer

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![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)
44
[![PHP version](https://img.shields.io/packagist/php-v/kubawerlos/php-cs-fixer-custom-fixers.svg)](https://php.net)
55
[![License](https://img.shields.io/github/license/kubawerlos/php-cs-fixer-custom-fixers.svg)](LICENSE)
6-
![Tests](https://img.shields.io/badge/tests-2684-brightgreen.svg)
6+
![Tests](https://img.shields.io/badge/tests-2716-brightgreen.svg)
77
[![Downloads](https://img.shields.io/packagist/dt/kubawerlos/php-cs-fixer-custom-fixers.svg)](https://packagist.org/packages/kubawerlos/php-cs-fixer-custom-fixers)
88

99
[![CI Status](https://github.com/kubawerlos/php-cs-fixer-custom-fixers/workflows/CI/badge.svg?branch=main&event=push)](https://github.com/kubawerlos/php-cs-fixer-custom-fixers/actions)
@@ -326,6 +326,17 @@ PHPUnit `fail`, `markTestIncomplete` and `markTestSkipped` functions should not
326326
}
327327
```
328328

329+
#### PhpdocArrayStyleFixer
330+
Generic array style should be used in PHPDoc.
331+
```diff
332+
<?php
333+
/**
334+
- * @return int[]
335+
+ * @return array<int>
336+
*/
337+
function foo() { return [1, 2]; }
338+
```
339+
329340
#### PhpdocNoIncorrectVarAnnotationFixer
330341
The `@var` annotations must be used correctly in code.
331342
```diff

dev-tools/src/Fixer/OrderedClassElementsInternalFixer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ function usort(array &$elements): void
9797
\usort(
9898
$elements,
9999
/**
100-
* @param string[] $a
101-
* @param string[] $b
100+
* @param array<string> $a
101+
* @param array<string> $b
102102
*/
103103
static function (array $a, array $b): int {
104104
if (

dev-tools/src/Fixer/PriorityInternalFixer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function isRisky(): bool
5858

5959
public function fix(\SplFileInfo $file, Tokens $tokens): void
6060
{
61-
/** @var int[] $indices */
61+
/** @var array<int> $indices */
6262
$indices = $tokens->findSequence([[\T_EXTENDS], [\T_STRING, 'AbstractFixer']]);
6363

6464
/** @var int $sequencesStartIndex */
@@ -77,7 +77,7 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void
7777

7878
$endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $startIndex);
7979

80-
/** @var int[] $indices */
80+
/** @var array<int> $indices */
8181
$indices = $tokens->findSequence([[\T_PUBLIC], [\T_FUNCTION], [\T_STRING, 'getPriority']], $startIndex, $endIndex);
8282

8383
/** @var int $sequencesStartIndex */

dev-tools/src/Priority/PriorityCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
final class PriorityCollection
2222
{
23-
/** @var PriorityFixer[] */
23+
/** @var array<PriorityFixer> */
2424
private $priorityFixers = [];
2525

2626
public static function create(): self

dev-tools/src/Priority/PriorityFixer.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ final class PriorityFixer
2020
/** @var FixerInterface */
2121
private $fixer;
2222

23-
/** @var self[] */
23+
/** @var array<self> */
2424
private $fixersToRunAfter = [];
2525

26-
/** @var self[] */
26+
/** @var array<self> */
2727
private $fixersToRunBefore = [];
2828

2929
/** @var null|int */
@@ -60,25 +60,25 @@ public function getPriority(): int
6060
}
6161

6262
/**
63-
* @return string[]
63+
* @return array<string>
6464
*/
6565
public function getFixerToRunAfterNames(): array
6666
{
6767
return $this->getFixerNames($this->fixersToRunAfter);
6868
}
6969

7070
/**
71-
* @return string[]
71+
* @return array<string>
7272
*/
7373
public function getFixerToRunBeforeNames(): array
7474
{
7575
return $this->getFixerNames($this->fixersToRunBefore);
7676
}
7777

7878
/**
79-
* @param self[] $priorityFixers
79+
* @param array<self> $priorityFixers
8080
*
81-
* @return string[]
81+
* @return array<string>
8282
*/
8383
private function getFixerNames(array $priorityFixers): array
8484
{

dev-tools/src/Readme/ReadmeCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ private function fixers(): string
199199
return \sprintf('\'%s\'', $value);
200200
}, $option->getAllowedValues());
201201
} else {
202-
/** @var string[] $allowed */
202+
/** @var array<string> $allowed */
203203
$allowed = $option->getAllowedTypes();
204204
}
205205
$output .= \sprintf(

src/Analyzer/Analysis/DataProviderAnalysis.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ final class DataProviderAnalysis
2424
/** @var int */
2525
private $nameIndex;
2626

27-
/** @var int[] */
27+
/** @var array<int> */
2828
private $usageIndices;
2929

3030
/**
31-
* @param int[] $usageIndices
31+
* @param array<int> $usageIndices
3232
*/
3333
public function __construct(string $name, int $nameIndex, array $usageIndices)
3434
{
@@ -48,7 +48,7 @@ public function getNameIndex(): int
4848
}
4949

5050
/**
51-
* @return int[]
51+
* @return array<int>
5252
*/
5353
public function getUsageIndices(): array
5454
{

src/Analyzer/ArrayAnalyzer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
final class ArrayAnalyzer
2525
{
2626
/**
27-
* @return ArrayElementAnalysis[]
27+
* @return array<ArrayElementAnalysis>
2828
*/
2929
public function getElements(Tokens $tokens, int $index): array
3030
{
@@ -58,7 +58,7 @@ public function getElements(Tokens $tokens, int $index): array
5858
}
5959

6060
/**
61-
* @return ArrayElementAnalysis[]
61+
* @return array<ArrayElementAnalysis>
6262
*/
6363
private function getElementsForArrayContent(Tokens $tokens, int $startIndex, int $endIndex): array
6464
{

src/Analyzer/DataProviderAnalyzer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
final class DataProviderAnalyzer
2525
{
2626
/**
27-
* @return DataProviderAnalysis[]
27+
* @return array<DataProviderAnalysis>
2828
*/
2929
public function getDataProviders(Tokens $tokens, int $startIndex, int $endIndex): array
3030
{
@@ -48,7 +48,7 @@ public function getDataProviders(Tokens $tokens, int $startIndex, int $endIndex)
4848

4949
Preg::matchAll('/@dataProvider\s+([a-zA-Z0-9._:-\\\\x7f-\xff]+)/', $docCommentToken->getContent(), $matches);
5050

51-
/** @var string[] $matches */
51+
/** @var array<string> $matches */
5252
$matches = $matches[1];
5353

5454
foreach ($matches as $dataProviderName) {

0 commit comments

Comments
 (0)