@@ -38,28 +38,24 @@ public function testFix(string $expected, ?string $input = null): void
3838 */
3939 public static function provideFixCases (): iterable
4040 {
41- yield [
42- '<?php
41+ yield 'keep correct PHPDoc ' => ['<?php
4342/** @var Foo $foo */
4443$foo = new Foo();
45- ' ,
46- ];
44+ ' ];
4745
48- yield [
46+ yield ' keep correct PHPDoc with leading slash ' => [
4947 '<?php
5048/** @var \Foo $foo */
5149$foo = new Foo();
52- ' ,
53- ];
50+ ' , ];
5451
55- yield [
52+ yield ' keep correct PHPDoc with nullable ' => [
5653 '<?php
5754/** @var ?Foo $foo */
5855$foo = new Foo();
59- ' ,
60- ];
56+ ' , ];
6157
62- yield [
58+ yield ' remove PHPDoc when variable name is different ' => [
6359 '<?php
6460$bar = new Logger();
6561 ' ,
@@ -69,7 +65,7 @@ public static function provideFixCases(): iterable
6965 ' ,
7066 ];
7167
72- yield [
68+ yield ' remove PHPDoc when annotation hs no type ' => [
7369 '<?php
7470$bar = new Logger();
7571 ' ,
@@ -79,7 +75,7 @@ public static function provideFixCases(): iterable
7975 ' ,
8076 ];
8177
82- yield [
78+ yield ' remove PHPDoc when variable name is different in "for" loop ' => [
8379 '<?php
8480for ($i = 0; $i < 100; $i++) {}
8581 ' ,
@@ -89,14 +85,12 @@ public static function provideFixCases(): iterable
8985 ' ,
9086 ];
9187
92- yield [
93- '<?php
88+ yield 'keep correct PHPDoc for "for" loop ' => ['<?php
9489/** @var int $i */
9590for ($i = 0; $i < 100; $i++) {}
96- ' ,
97- ];
91+ ' ];
9892
99- yield [
93+ yield ' remove PHPDoc when variable name is different in "foreach" loop ' => [
10094 '<?php
10195foreach ($foo as $v) {}
10296 ' ,
@@ -106,14 +100,17 @@ public static function provideFixCases(): iterable
106100 ' ,
107101 ];
108102
109- yield [
110- '<?php
111- /** @var int $value */
112- foreach ($foo as $value) {}
103+ yield 'keep correct PHPDoc for array in "foreach" loop ' => ['<?php
104+ /** @var int[] $foo */
105+ foreach ($foo as $bar) {}
113106 ' ,
114107 ];
108+ yield 'keep correct PHPDoc for element in "foreach" loop ' => ['<?php
109+ /** @var int $value */
110+ foreach ($foo as $value) {}
111+ ' ];
115112
116- yield [
113+ yield ' remove PHPDoc when variable name is different in "if" condition ' => [
117114 '<?php
118115if (($v = getValue()) !== null) {}
119116 ' ,
@@ -123,14 +120,12 @@ public static function provideFixCases(): iterable
123120 ' ,
124121 ];
125122
126- yield [
127- '<?php
123+ yield 'keep correct PHPDoc for "if" condition ' => ['<?php
128124/** @var int $value */
129125if (($value = getValue()) !== null) {}
130- ' ,
131- ];
126+ ' ];
132127
133- yield [
128+ yield ' remove PHPDoc when variable name is different in "switch" condition ' => [
134129 '<?php
135130switch ($v = getValue()) { default: break; }
136131 ' ,
@@ -140,14 +135,12 @@ public static function provideFixCases(): iterable
140135 ' ,
141136 ];
142137
143- yield [
144- '<?php
138+ yield 'keep correct PHPDoc for "switch" condition ' => ['<?php
145139/** @var int $value */
146140switch ($value = getValue()) { default: break; }
147- ' ,
148- ];
141+ ' ];
149142
150- yield [
143+ yield ' remove PHPDoc when variable name is different in "while" loop ' => [
151144 '<?php
152145while ($i < 0) { $i++; }
153146 ' ,
@@ -157,14 +150,13 @@ public static function provideFixCases(): iterable
157150 ' ,
158151 ];
159152
160- yield [
161- '<?php
153+ yield 'keep correct PHPDoc for "while" loop ' => ['<?php
162154/** @var int $index */
163155while ($index < 0) { $i++; }
164156 ' ,
165157 ];
166158
167- yield [
159+ yield ' remove PHPDoc when variable name is different, but keep the rest of PHPDoc ' => [
168160 '<?php
169161/**
170162 * We create here new instance here
@@ -180,7 +172,7 @@ public static function provideFixCases(): iterable
180172 ' ,
181173 ];
182174
183- yield [
175+ yield ' remove PHPDoc from before "return" ' => [
184176 '<?php
185177return true;
186178 ' ,
@@ -190,43 +182,25 @@ public static function provideFixCases(): iterable
190182 ' ,
191183 ];
192184
193- yield [
185+ yield ' remove PHPDoc from end of file ' => [
194186 '<?php
195187 ' ,
196188 '<?php
197189/** @var LoggerInterface $foo */
198190 ' ,
199191 ];
200192
201- yield [
202- '<?php
193+ yield 'ignore other annotations ' => ['<?php
203194/** @see LoggerInterface $foo */
204195$bar = new Logger();
205- ' ,
206- ];
207-
208- yield [
209- '<?php
210- /** @var LoggerInterface[] $foo */
211- foreach ($foo as $bar) {}
212- ' ,
213- ];
214-
215- yield [
216- '<?php
217- /** @var LoggerInterface $bar */
218- foreach ($foo as $bar) {}
219- ' ,
220- ];
196+ ' ];
221197
222- yield [
223- '<?php
198+ yield 'ignore different variable name case ' => ['<?php
224199/** @var LoggerInterface $bar */
225200$Bar = 2;
226- ' ,
227- ];
201+ ' ];
228202
229- yield [
203+ yield ' keep correct PHPDoc for class properties ' => [
230204 '<?php
231205class Foo
232206{
@@ -254,7 +228,7 @@ class Foo
254228 ' ,
255229 ];
256230
257- yield [
231+ yield ' remove PHPDoc for class properties ' => [
258232 '<?php
259233class Foo
260234{
@@ -306,7 +280,7 @@ class Foo
306280 ' ,
307281 ];
308282
309- yield [
283+ yield ' remove PHPDoc from inside of function ' => [
310284 '<?php
311285/** Class Foo */
312286class Foo
@@ -345,7 +319,7 @@ public function hello()
345319 ' ,
346320 ];
347321
348- yield [
322+ yield ' incorrect PHPDoc at the end of the file ' => [
349323 '<?php
350324$x = 0;
351325 ' ,
0 commit comments