Skip to content

Commit 3a1041b

Browse files
authored
Refactor PhpdocArrayStyleFixer (#663)
1 parent 6b36324 commit 3a1041b

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

README.md

Lines changed: 1 addition & 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-3063-brightgreen.svg)
6+
![Tests](https://img.shields.io/badge/tests-3064-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)

src/Fixer/PhpdocArrayStyleFixer.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,13 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void
9393

9494
private function fixType(string $type): string
9595
{
96-
do {
97-
/** @var string $type */
98-
$type = Preg::replace('/([\\\\a-zA-Z0-9>]+)\[\]/', 'array<$1>', $type, -1, $count);
99-
} while ($count > 0);
96+
/** @var string $newType */
97+
$newType = Preg::replace('/([\\\\a-zA-Z0-9>]+)\[\]/', 'array<$1>', $type, -1, $count);
10098

101-
return $type;
99+
if ($newType === $type) {
100+
return $type;
101+
}
102+
103+
return $this->fixType($newType);
102104
}
103105
}

tests/Fixer/PhpdocArrayStyleFixerTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,16 @@ public static function provideFixCases(): iterable
104104
/** @var int[] */
105105
',
106106
];
107+
108+
$expected = $input = 'string';
109+
for ($i = 0; $i < 1000; $i++) {
110+
$expected = 'array<' . $expected . '>';
111+
$input .= '[]';
112+
}
113+
114+
yield [
115+
\sprintf('<?php /** @var %s */', $expected),
116+
\sprintf('<?php /** @var %s */', $input),
117+
];
107118
}
108119
}

0 commit comments

Comments
 (0)