Skip to content

Commit ef6f7c9

Browse files
authored
Improvements (#554)
1 parent a024353 commit ef6f7c9

File tree

4 files changed

+50
-69
lines changed

4 files changed

+50
-69
lines changed

.github/workflows/ci.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ jobs:
3636
os: [ macos-latest, ubuntu-latest, windows-latest ]
3737
php-version: [ '7.4', '8.0' ]
3838
include:
39-
- os: ubuntu-18.04
39+
- os: ubuntu-latest
4040
php-version: '8.0'
4141
php-cs-fixer-version: '^2'
42-
- os: ubuntu-18.04
42+
- os: ubuntu-latest
4343
php-version: '7.4'
4444
php-cs-fixer-version: '^2'
45-
- os: ubuntu-latest
45+
- os: ubuntu-20.04
4646
php-version: '7.3'
47-
- os: ubuntu-latest
47+
- os: ubuntu-18.04
4848
php-version: '7.2'
4949
- os: ubuntu-latest
5050
php-version: '7.2'

.php-cs-fixer.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@
2222
unset($rules['phpdoc_tag_type']); // TODO: remove when fixer: https://github.com/FriendsOfPHP/PHP-CS-Fixer/pull/5395
2323
unset($rules['use_arrow_functions']); // TODO: remove when dropping support to PHP <7.4
2424

25+
// add new fixers that are not in PhpCsFixerConfig yet
26+
foreach (new PhpCsFixerCustomFixers\Fixers() as $fixer) {
27+
if (!isset($rules[$fixer->getName()])) {
28+
$rules[$fixer->getName()] = true;
29+
}
30+
}
31+
2532
foreach (new PhpCsFixerCustomFixersDev\Fixers() as $fixer) {
2633
$rules[$fixer->getName()] = true;
2734
}

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-2832-brightgreen.svg)
6+
![Tests](https://img.shields.io/badge/tests-2831-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)

tests/Fixer/PhpdocNoIncorrectVarAnnotationFixerTest.php

Lines changed: 38 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -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
8480
for ($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 */
9590
for ($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
10195
foreach ($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
118115
if (($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 */
129125
if (($value = getValue()) !== null) {}
130-
',
131-
];
126+
'];
132127

133-
yield [
128+
yield 'remove PHPDoc when variable name is different in "switch" condition' => [
134129
'<?php
135130
switch ($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 */
146140
switch ($value = getValue()) { default: break; }
147-
',
148-
];
141+
'];
149142

150-
yield [
143+
yield 'remove PHPDoc when variable name is different in "while" loop' => [
151144
'<?php
152145
while ($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 */
163155
while ($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
185177
return 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
231205
class Foo
232206
{
@@ -254,7 +228,7 @@ class Foo
254228
',
255229
];
256230

257-
yield [
231+
yield 'remove PHPDoc for class properties' => [
258232
'<?php
259233
class 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 */
312286
class 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

Comments
 (0)