forked from doctrine/coding-standard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphp72-compatibility.patch
580 lines (520 loc) · 17.5 KB
/
php72-compatibility.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
diff --git a/tests/expected_report.txt b/tests/expected_report.txt
index a646ff6..84c9474 100644
--- a/tests/expected_report.txt
+++ b/tests/expected_report.txt
@@ -5,7 +5,7 @@ FILE ERRORS WARNINGS
----------------------------------------------------------------------
tests/input/annotation-name.php 8 0
tests/input/array_indentation.php 10 0
-tests/input/arrow-functions-format.php 12 0
+tests/input/arrow-functions-format.php 10 0
tests/input/assignment-operators.php 4 0
tests/input/attributes.php 15 0
tests/input/binary_operators.php 9 0
@@ -17,26 +17,23 @@ tests/input/constants-var.php 6 0
tests/input/ControlStructures.php 28 0
tests/input/doc-comment-spacing.php 11 0
tests/input/duplicate-assignment-variable.php 1 0
-tests/input/EarlyReturn.php 7 0
-tests/input/example-class.php 47 0
-tests/input/ExampleBackedEnum.php 3 0
-tests/input/Exceptions.php 1 0
+tests/input/EarlyReturn.php 6 0
+tests/input/example-class.php 41 0
tests/input/forbidden-comments.php 14 0
tests/input/forbidden-functions.php 6 0
tests/input/inline_type_hint_assertions.php 10 0
tests/input/LowCaseTypes.php 2 0
tests/input/namespaces-spacing.php 7 0
-tests/input/NamingCamelCase.php 9 0
+tests/input/NamingCamelCase.php 6 0
tests/input/negation-operator.php 2 0
-tests/input/new_with_parentheses.php 19 0
+tests/input/new_with_parentheses.php 18 0
tests/input/not_spacing.php 8 0
-tests/input/null_coalesce_equal_operator.php 5 0
+tests/input/null_coalesce_equal_operator.php 1 0
tests/input/null_coalesce_operator.php 3 0
-tests/input/null_safe_operator.php 1 0
tests/input/optimized-functions.php 1 0
-tests/input/PropertyDeclaration.php 14 0
-tests/input/return_type_on_closures.php 26 0
-tests/input/return_type_on_methods.php 22 0
+tests/input/PropertyDeclaration.php 6 0
+tests/input/return_type_on_closures.php 21 0
+tests/input/return_type_on_methods.php 17 0
tests/input/semicolon_spacing.php 3 0
tests/input/single-line-array-spacing.php 5 0
tests/input/spread-operator.php 6 0
@@ -46,17 +43,16 @@ tests/input/strings.php 3 0
tests/input/superfluous-naming.php 11 0
tests/input/test-case.php 8 0
tests/input/trailing_comma_on_array.php 1 0
-tests/input/TrailingCommaOnFunctions.php 6 0
tests/input/traits-uses.php 11 0
-tests/input/type-hints.php 9 0
+tests/input/type-hints.php 7 0
tests/input/UnusedVariables.php 1 0
tests/input/use-ordering.php 1 0
tests/input/useless-semicolon.php 2 0
-tests/input/UselessConditions.php 21 0
+tests/input/UselessConditions.php 20 0
----------------------------------------------------------------------
-A TOTAL OF 464 ERRORS AND 2 WARNINGS WERE FOUND IN 50 FILES
+A TOTAL OF 415 ERRORS AND 2 WARNINGS WERE FOUND IN 46 FILES
----------------------------------------------------------------------
-PHPCBF CAN FIX 380 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 331 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------
diff --git a/tests/fixed/ControlStructures.php b/tests/fixed/ControlStructures.php
index f8f7f65..a653086 100644
--- a/tests/fixed/ControlStructures.php
+++ b/tests/fixed/ControlStructures.php
@@ -104,7 +104,7 @@ public function spaceBelowBlocks(): void
try {
echo 4;
- } catch (Throwable) {
+ } catch (Throwable $throwable) {
}
echo 5;
diff --git a/tests/fixed/EarlyReturn.php b/tests/fixed/EarlyReturn.php
index fc734db..caf1dbb 100644
--- a/tests/fixed/EarlyReturn.php
+++ b/tests/fixed/EarlyReturn.php
@@ -11,7 +11,7 @@ public function bar(): bool
return $bar === 'bar';
}
- public function foo(): string|null
+ public function foo(): ?string
{
foreach ($items as $item) {
if (! $item->isItem()) {
diff --git a/tests/fixed/ExampleBackedEnum.php b/tests/fixed/ExampleBackedEnum.php
index cc38c54..fe54eb9 100644
--- a/tests/fixed/ExampleBackedEnum.php
+++ b/tests/fixed/ExampleBackedEnum.php
@@ -3,7 +3,3 @@
declare(strict_types=1);
namespace ExampleBackedEnum;
-
-enum ExampleBackedEnum: int
-{
-}
diff --git a/tests/fixed/Exceptions.php b/tests/fixed/Exceptions.php
index db7408b..9b146c6 100644
--- a/tests/fixed/Exceptions.php
+++ b/tests/fixed/Exceptions.php
@@ -3,11 +3,3 @@
declare(strict_types=1);
namespace Exceptions;
-
-use Exception;
-use Throwable;
-
-try {
- throw new Exception();
-} catch (Throwable) {
-}
diff --git a/tests/fixed/NamingCamelCase.php b/tests/fixed/NamingCamelCase.php
index 5493471..57d9f2b 100644
--- a/tests/fixed/NamingCamelCase.php
+++ b/tests/fixed/NamingCamelCase.php
@@ -6,11 +6,14 @@
class NamingCamelCase
{
- public mixed $A;
+ /** @var mixed */
+ public $A;
- protected mixed $B;
+ /** @var mixed */
+ protected $B;
- private mixed $C;
+ /** @var mixed */
+ private $C;
public function fcn(string $A): void
{
diff --git a/tests/fixed/PropertyDeclaration.php b/tests/fixed/PropertyDeclaration.php
index 9703897..5c3f27b 100644
--- a/tests/fixed/PropertyDeclaration.php
+++ b/tests/fixed/PropertyDeclaration.php
@@ -9,10 +9,5 @@ final class PropertyDeclaration
public bool $boolPropertyWithDefaultValue = false;
public string $stringProperty;
public int $intProperty;
- public string|null $nullableString = null;
-
- public function __construct(
- public readonly Foo $foo,
- ) {
- }
+ public ?string $nullableString = null;
}
diff --git a/tests/fixed/TrailingCommaOnFunctions.php b/tests/fixed/TrailingCommaOnFunctions.php
index 4248238..f3ffa91 100644
--- a/tests/fixed/TrailingCommaOnFunctions.php
+++ b/tests/fixed/TrailingCommaOnFunctions.php
@@ -15,7 +15,7 @@ public function a(int $arg): void
}
public function b(
- int $arg,
+ int $arg
): void {
}
@@ -28,7 +28,7 @@ public function uses(): void
};
$multiLine = static function (int $arg) use (
- $var,
+ $var
): void {
var_dump($var);
};
@@ -37,9 +37,8 @@ public function uses(): void
$class = new TrailingCommaOnFunctions();
-// phpcs:ignore Generic.Functions.FunctionCallArgumentSpacing.NoSpaceAfterComma
$class->a(1);
$class->a(
- 1,
+ 1
);
diff --git a/tests/fixed/UselessConditions.php b/tests/fixed/UselessConditions.php
index 71e0cfb..2151b17 100644
--- a/tests/fixed/UselessConditions.php
+++ b/tests/fixed/UselessConditions.php
@@ -95,7 +95,7 @@ public function necessaryIfConditionWithMethodCall(): bool
return false;
}
- public function nullShouldNotBeTreatedAsFalse(): bool|null
+ public function nullShouldNotBeTreatedAsFalse(): ?bool
{
if (! $this->isAdmin) {
return null;
diff --git a/tests/fixed/arrow-functions-format.php b/tests/fixed/arrow-functions-format.php
index dcb5a3e..a45074f 100644
--- a/tests/fixed/arrow-functions-format.php
+++ b/tests/fixed/arrow-functions-format.php
@@ -18,10 +18,10 @@
$multiLineArrowFunctions = Collection::from([1, 2])
->map(
- static fn (int $v): int => $v * 2,
+ static fn (int $v): int => $v * 2
)
->reduce(
- static fn (int $tmp, int $v): int => $tmp + $v,
+ static fn (int $tmp, int $v): int => $tmp + $v
);
$thisIsNotAnArrowFunction = [$this->fn => 'value'];
@@ -32,12 +32,12 @@
];
$singleLineArrayReturn = Collection::map(
- static fn () => [1, 2],
+ static fn () => [1, 2]
);
$wrongMultiLineArrayReturn = Collection::map(
static fn () => [
1,
2,
- ],
+ ]
);
diff --git a/tests/fixed/example-class.php b/tests/fixed/example-class.php
index 4988dab..2df56a0 100644
--- a/tests/fixed/example-class.php
+++ b/tests/fixed/example-class.php
@@ -29,10 +29,23 @@ class Example extends ParentClass implements IteratorAggregate
{
private const VERSION = PHP_VERSION - (PHP_MINOR_VERSION * 100) - PHP_PATCH_VERSION;
- private ControlStructureSniff|int|string|null $baxBax = null;
+ /** @var int|null */
+ private $foo;
- public function __construct(private int|null $foo = null, private array $bar = [], private bool $baz = false, $baxBax = 'unused')
+ /** @var string[] */
+ private $bar;
+
+ /** @var bool */
+ private $baz;
+
+ /** @var ControlStructureSniff|int|string|null */
+ private $baxBax;
+
+ public function __construct(?int $foo = null, array $bar = [], bool $baz = false, $baxBax = 'unused')
{
+ $this->foo = $foo;
+ $this->bar = $bar;
+ $this->baz = $baz;
$this->baxBax = $baxBax;
parent::__construct();
@@ -41,7 +54,7 @@ public function __construct(private int|null $foo = null, private array $bar = [
/**
* Description
*/
- public function getFoo(): int|null
+ public function getFoo(): ?int
{
return $this->foo;
}
diff --git a/tests/fixed/namespaces-spacing.php b/tests/fixed/namespaces-spacing.php
index 36cbae2..d42bbfe 100644
--- a/tests/fixed/namespaces-spacing.php
+++ b/tests/fixed/namespaces-spacing.php
@@ -16,5 +16,5 @@
strrev(
(new DateTimeImmutable('@' . time(), new DateTimeZone('UTC')))
->sub(new DateInterval('P1D'))
- ->format(DATE_RFC3339),
+ ->format(DATE_RFC3339)
);
diff --git a/tests/fixed/new_with_parentheses.php b/tests/fixed/new_with_parentheses.php
index 47a06ec..6e81bbe 100644
--- a/tests/fixed/new_with_parentheses.php
+++ b/tests/fixed/new_with_parentheses.php
@@ -24,5 +24,5 @@
$z = new stdClass() ? new stdClass() : new stdClass();
-$q = $q ?: new stdClass();
-$e ??= new stdClass();
+$q = $q ?: new stdClass();
+$e = $e ?? new stdClass();
diff --git a/tests/fixed/null_coalesce_equal_operator.php b/tests/fixed/null_coalesce_equal_operator.php
index 6703d30..b997469 100644
--- a/tests/fixed/null_coalesce_equal_operator.php
+++ b/tests/fixed/null_coalesce_equal_operator.php
@@ -2,12 +2,12 @@
declare(strict_types=1);
-$bar ??= 'bar';
+$bar = $bar ?? 'bar';
-$bar['baz'] ??= 'baz';
+$bar['baz'] = $bar['baz'] ?? 'baz';
-$bar ??= 'bar';
+$bar = $bar ?? 'bar';
-$object->property ??= 'Default Value';
+$object->property = $object->property ?? 'Default Value';
-Test::$foo ??= 123;
+Test::$foo = Test::$foo ?? 123;
diff --git a/tests/fixed/null_coalesce_operator.php b/tests/fixed/null_coalesce_operator.php
index 51c361c..8846dd1 100644
--- a/tests/fixed/null_coalesce_operator.php
+++ b/tests/fixed/null_coalesce_operator.php
@@ -4,7 +4,7 @@
$foo = $_GET['foo'] ?? 'foo';
-$bar ??= 'bar';
+$bar = $bar ?? 'bar';
$bar = $bar['baz'] ?? 'baz';
diff --git a/tests/fixed/null_safe_operator.php b/tests/fixed/null_safe_operator.php
index 7ce8a3d..5bbb636 100644
--- a/tests/fixed/null_safe_operator.php
+++ b/tests/fixed/null_safe_operator.php
@@ -2,4 +2,4 @@
declare(strict_types=1);
-$var = $object?->property;
+$var = $object === null ? null : $object->property;
diff --git a/tests/fixed/return_type_on_closures.php b/tests/fixed/return_type_on_closures.php
index 80ad413..134bade 100644
--- a/tests/fixed/return_type_on_closures.php
+++ b/tests/fixed/return_type_on_closures.php
@@ -22,7 +22,7 @@ static function (
int $c,
int $d,
int $e,
- int $b,
+ int $b
): void {
}
@@ -31,7 +31,7 @@ static function (
int $c,
int $d,
int $e,
- int $b,
+ int $b
): void {
}
@@ -40,7 +40,7 @@ static function (
int $c,
int $d,
int $e,
- int $b,
+ int $b
): void {
}
@@ -49,7 +49,7 @@ static function (
int $c,
int $d,
int $e,
- int $b,
+ int $b
): void {
}
@@ -58,6 +58,6 @@ static function (
int $c,
int $d,
int $e,
- int $b,
+ int $b
): void {
}
diff --git a/tests/fixed/return_type_on_methods.php b/tests/fixed/return_type_on_methods.php
index 0c897ae..8e2c6f7 100644
--- a/tests/fixed/return_type_on_methods.php
+++ b/tests/fixed/return_type_on_methods.php
@@ -31,7 +31,7 @@ public function f(
int $c,
int $d,
int $e,
- int $b,
+ int $b
): void {
}
@@ -40,7 +40,7 @@ public function g(
int $c,
int $d,
int $e,
- int $b,
+ int $b
): void {
}
@@ -49,7 +49,7 @@ public function h(
int $c,
int $d,
int $e,
- int $b,
+ int $b
): void {
}
@@ -58,7 +58,7 @@ public function i(
int $c,
int $d,
int $e,
- int $b,
+ int $b
): void {
}
@@ -67,7 +67,7 @@ public function j(
int $c,
int $d,
int $e,
- int $b,
+ int $b
): void {
}
}
diff --git a/tests/fixed/type-hints.php b/tests/fixed/type-hints.php
index 5e26ed8..10e6f34 100644
--- a/tests/fixed/type-hints.php
+++ b/tests/fixed/type-hints.php
@@ -10,7 +10,7 @@
class TraversableTypeHints
{
/** @var Traversable */
- private Traversable $parameter;
+ private $parameter;
/**
* @param Iterator $iterator
@@ -25,5 +25,6 @@ public function get(Iterator $iterator): Traversable
class UnionTypeHints
{
- private int|string|null $x = 1;
+ /** @var int|string|null */
+ private $x = 1;
}
diff --git a/tests/input/ControlStructures.php b/tests/input/ControlStructures.php
index 73944e3..a0e0b2e 100644
--- a/tests/input/ControlStructures.php
+++ b/tests/input/ControlStructures.php
@@ -93,7 +93,7 @@ public function spaceBelowBlocks(): void
}
try {
echo 4;
- } catch (Throwable) {
+ } catch (Throwable $throwable) {
}
echo 5;
}
diff --git a/tests/input/ExampleBackedEnum.php b/tests/input/ExampleBackedEnum.php
index 0c47286..fe54eb9 100644
--- a/tests/input/ExampleBackedEnum.php
+++ b/tests/input/ExampleBackedEnum.php
@@ -3,7 +3,3 @@
declare(strict_types=1);
namespace ExampleBackedEnum;
-
-enum ExampleBackedEnum : int
-{
-}
diff --git a/tests/input/Exceptions.php b/tests/input/Exceptions.php
index 3aaa30f..9b146c6 100644
--- a/tests/input/Exceptions.php
+++ b/tests/input/Exceptions.php
@@ -3,11 +3,3 @@
declare(strict_types=1);
namespace Exceptions;
-
-use Exception;
-use Throwable;
-
-try {
- throw new Exception();
-} catch (Throwable $throwable) {
-}
diff --git a/tests/input/PropertyDeclaration.php b/tests/input/PropertyDeclaration.php
index acdc445..0891e12 100644
--- a/tests/input/PropertyDeclaration.php
+++ b/tests/input/PropertyDeclaration.php
@@ -10,9 +10,4 @@ final class PropertyDeclaration
public string $stringProperty;
public int $intProperty;
public ? string $nullableString = null;
-
- public function __construct(
- public readonly Foo $foo,
- ) {
- }
}
diff --git a/tests/input/TrailingCommaOnFunctions.php b/tests/input/TrailingCommaOnFunctions.php
index fc5480e..f3ffa91 100644
--- a/tests/input/TrailingCommaOnFunctions.php
+++ b/tests/input/TrailingCommaOnFunctions.php
@@ -10,7 +10,7 @@
class TrailingCommaOnFunctions
{
- public function a(int $arg,): void
+ public function a(int $arg): void
{
}
@@ -23,7 +23,7 @@ public function uses(): void
{
$var = null;
- $singleLine = static function (int $arg) use ($var,): void {
+ $singleLine = static function (int $arg) use ($var): void {
var_dump($var);
};
@@ -37,8 +37,7 @@ public function uses(): void
$class = new TrailingCommaOnFunctions();
-// phpcs:ignore Generic.Functions.FunctionCallArgumentSpacing.NoSpaceAfterComma
-$class->a(1,);
+$class->a(1);
$class->a(
1
diff --git a/tests/input/arrow-functions-format.php b/tests/input/arrow-functions-format.php
index d3903ff..8a358e8 100644
--- a/tests/input/arrow-functions-format.php
+++ b/tests/input/arrow-functions-format.php
@@ -18,10 +18,10 @@
$multiLineArrowFunctions = Collection::from([1, 2])
->map(
- static fn (int $v): int => $v * 2,
+ static fn (int $v): int => $v * 2
)
->reduce(
- static fn (int $tmp, int $v): int => $tmp + $v,
+ static fn (int $tmp, int $v): int => $tmp + $v
);
$thisIsNotAnArrowFunction = [$this->fn => 'value'];
diff --git a/tests/input/namespaces-spacing.php b/tests/input/namespaces-spacing.php
index e7be018..e1ab639 100644
--- a/tests/input/namespaces-spacing.php
+++ b/tests/input/namespaces-spacing.php
@@ -11,5 +11,5 @@
strrev(
(new DateTimeImmutable('@' . time(), new DateTimeZone('UTC')))
->sub(new DateInterval('P1D'))
- ->format(DATE_RFC3339),
+ ->format(DATE_RFC3339)
);