Skip to content

Commit 720492b

Browse files
authored
Merge pull request #282 from derrabus/improvement/reverse-patches
Upgrade fixtures to PHP 8.1 and reverse patches
2 parents e64b67f + cb35b8f commit 720492b

31 files changed

+1172
-1012
lines changed

Makefile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ test-report: vendor
88
test-fix: vendor
99
./bin/test-fix
1010

11+
update-compatibility-patch-72:
12+
@git apply tests/php72-compatibility.patch
13+
@printf "Please open your editor and apply your changes\n"
14+
@until [ "$${compatibility_resolved}" == "y" ]; do read -p "Have finished your changes (y|n)? " compatibility_resolved; done && compatibility_resolved=
15+
@git diff -- tests/expected_report.txt tests/fixed tests/input > .tmp-patch && mv .tmp-patch tests/php72-compatibility.patch && git apply -R tests/php72-compatibility.patch
16+
@git commit -m 'Update compatibility patch' tests/php72-compatibility.patch
17+
1118
update-compatibility-patch-73:
1219
@git apply tests/php73-compatibility.patch
1320
@printf "Please open your editor and apply your changes\n"
@@ -29,13 +36,6 @@ update-compatibility-patch-80:
2936
@git diff -- tests/expected_report.txt tests/fixed tests/input > .tmp-patch && mv .tmp-patch tests/php80-compatibility.patch && git apply -R tests/php80-compatibility.patch
3037
@git commit -m 'Update compatibility patch' tests/php80-compatibility.patch
3138

32-
update-compatibility-patch-81:
33-
@git apply tests/php81-compatibility.patch
34-
@printf "Please open your editor and apply your changes\n"
35-
@until [ "$${compatibility_resolved}" == "y" ]; do read -p "Have finished your changes (y|n)? " compatibility_resolved; done && compatibility_resolved=
36-
@git diff -- tests/expected_report.txt tests/fixed tests/input > .tmp-patch && mv .tmp-patch tests/php81-compatibility.patch && git apply -R tests/php81-compatibility.patch
37-
@git commit -m 'Update compatibility patch' tests/php81-compatibility.patch
38-
3939
vendor: composer.json
4040
composer update
4141
touch -c vendor

tests/expected_report.txt

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,26 @@ tests/input/constants-var.php 7 0
1414
tests/input/ControlStructures.php 28 0
1515
tests/input/doc-comment-spacing.php 11 0
1616
tests/input/duplicate-assignment-variable.php 1 0
17-
tests/input/EarlyReturn.php 6 0
18-
tests/input/example-class.php 38 0
17+
tests/input/EarlyReturn.php 7 0
18+
tests/input/example-class.php 43 0
19+
tests/input/ExampleBackedEnum.php 3 0
20+
tests/input/Exceptions.php 1 0
1921
tests/input/forbidden-comments.php 14 0
2022
tests/input/forbidden-functions.php 6 0
2123
tests/input/inline_type_hint_assertions.php 7 0
2224
tests/input/LowCaseTypes.php 2 0
2325
tests/input/namespaces-spacing.php 7 0
24-
tests/input/NamingCamelCase.php 6 0
26+
tests/input/NamingCamelCase.php 9 0
2527
tests/input/negation-operator.php 2 0
26-
tests/input/new_with_parentheses.php 18 0
28+
tests/input/new_with_parentheses.php 19 0
2729
tests/input/not_spacing.php 8 0
28-
tests/input/null_coalesce_equal_operator.php 1 0
30+
tests/input/null_coalesce_equal_operator.php 5 0
2931
tests/input/null_coalesce_operator.php 3 0
32+
tests/input/null_safe_operator.php 1 0
3033
tests/input/optimized-functions.php 1 0
31-
tests/input/PropertyDeclaration.php 6 0
32-
tests/input/return_type_on_closures.php 21 0
33-
tests/input/return_type_on_methods.php 17 0
34+
tests/input/PropertyDeclaration.php 14 0
35+
tests/input/return_type_on_closures.php 26 0
36+
tests/input/return_type_on_methods.php 22 0
3437
tests/input/semicolon_spacing.php 3 0
3538
tests/input/single-line-array-spacing.php 5 0
3639
tests/input/spread-operator.php 6 0
@@ -39,16 +42,17 @@ tests/input/strings.php 1 0
3942
tests/input/superfluous-naming.php 11 0
4043
tests/input/test-case.php 8 0
4144
tests/input/trailing_comma_on_array.php 1 0
45+
tests/input/TrailingCommaOnFunctions.php 6 0
4246
tests/input/traits-uses.php 11 0
43-
tests/input/type-hints.php 7 0
47+
tests/input/type-hints.php 9 0
4448
tests/input/UnusedVariables.php 1 0
4549
tests/input/use-ordering.php 1 0
4650
tests/input/useless-semicolon.php 2 0
47-
tests/input/UselessConditions.php 20 0
51+
tests/input/UselessConditions.php 21 0
4852
----------------------------------------------------------------------
49-
A TOTAL OF 382 ERRORS AND 0 WARNINGS WERE FOUND IN 42 FILES
53+
A TOTAL OF 428 ERRORS AND 0 WARNINGS WERE FOUND IN 46 FILES
5054
----------------------------------------------------------------------
51-
PHPCBF CAN FIX 317 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
55+
PHPCBF CAN FIX 363 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
5256
----------------------------------------------------------------------
5357

5458

tests/fixed/ControlStructures.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function spaceBelowBlocks(): void
104104

105105
try {
106106
echo 4;
107-
} catch (Throwable $throwable) {
107+
} catch (Throwable) {
108108
}
109109

110110
echo 5;

tests/fixed/EarlyReturn.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public function bar(): bool
1111
return $bar === 'bar';
1212
}
1313

14-
public function foo(): ?string
14+
public function foo(): string|null
1515
{
1616
foreach ($items as $item) {
1717
if (! $item->isItem()) {

tests/fixed/ExampleBackedEnum.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@
33
declare(strict_types=1);
44

55
namespace ExampleBackedEnum;
6+
7+
enum ExampleBackedEnum: int
8+
{
9+
}

tests/fixed/Exceptions.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,11 @@
33
declare(strict_types=1);
44

55
namespace Exceptions;
6+
7+
use Exception;
8+
use Throwable;
9+
10+
try {
11+
throw new Exception();
12+
} catch (Throwable) {
13+
}

tests/fixed/NamingCamelCase.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@
66

77
class NamingCamelCase
88
{
9-
/** @var mixed */
10-
public $A;
9+
public mixed $A;
1110

12-
/** @var mixed */
13-
protected $B;
11+
protected mixed $B;
1412

15-
/** @var mixed */
16-
private $C;
13+
private mixed $C;
1714

1815
public function fcn(string $A): void
1916
{

tests/fixed/PropertyDeclaration.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@ final class PropertyDeclaration
99
public bool $boolPropertyWithDefaultValue = false;
1010
public string $stringProperty;
1111
public int $intProperty;
12-
public ?string $nullableString = null;
12+
public string|null $nullableString = null;
13+
14+
public function __construct(
15+
public readonly Foo $foo,
16+
) {
17+
}
1318
}

tests/fixed/TrailingCommaOnFunctions.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function a(int $arg): void
1515
}
1616

1717
public function b(
18-
int $arg
18+
int $arg,
1919
): void {
2020
}
2121

@@ -28,7 +28,7 @@ public function uses(): void
2828
};
2929

3030
$multiLine = static function (int $arg) use (
31-
$var
31+
$var,
3232
): void {
3333
var_dump($var);
3434
};
@@ -37,8 +37,9 @@ public function uses(): void
3737

3838
$class = new TrailingCommaOnFunctions();
3939

40+
// phpcs:ignore Generic.Functions.FunctionCallArgumentSpacing.NoSpaceAfterComma
4041
$class->a(1);
4142

4243
$class->a(
43-
1
44+
1,
4445
);

tests/fixed/UselessConditions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function necessaryIfConditionWithMethodCall(): bool
9595
return false;
9696
}
9797

98-
public function nullShouldNotBeTreatedAsFalse(): ?bool
98+
public function nullShouldNotBeTreatedAsFalse(): bool|null
9999
{
100100
if (! $this->isAdmin) {
101101
return null;

tests/fixed/arrow-functions-format.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818

1919
$multiLineArrowFunctions = Collection::from([1, 2])
2020
->map(
21-
static fn (int $v): int => $v * 2
21+
static fn (int $v): int => $v * 2,
2222
)
2323
->reduce(
24-
static fn (int $tmp, int $v): int => $tmp + $v
24+
static fn (int $tmp, int $v): int => $tmp + $v,
2525
);
2626

2727
$thisIsNotAnArrowFunction = [$this->fn => 'value'];

tests/fixed/example-class.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,16 @@ class Example implements IteratorAggregate
2525
{
2626
private const VERSION = PHP_VERSION - (PHP_MINOR_VERSION * 100) - PHP_PATCH_VERSION;
2727

28-
/** @var int|null */
29-
private $foo;
28+
private int|null $foo = null;
3029

3130
/** @var string[] */
32-
private $bar;
31+
private array $bar;
3332

34-
/** @var bool */
35-
private $baz;
33+
private bool $baz;
3634

37-
/** @var ControlStructureSniff|int|string|null */
38-
private $baxBax;
35+
private ControlStructureSniff|int|string|null $baxBax = null;
3936

40-
public function __construct(?int $foo = null, array $bar = [], bool $baz = false, $baxBax = 'unused')
37+
public function __construct(int|null $foo = null, array $bar = [], bool $baz = false, $baxBax = 'unused')
4138
{
4239
$this->foo = $foo;
4340
$this->bar = $bar;
@@ -48,7 +45,7 @@ public function __construct(?int $foo = null, array $bar = [], bool $baz = false
4845
/**
4946
* Description
5047
*/
51-
public function getFoo(): ?int
48+
public function getFoo(): int|null
5249
{
5350
return $this->foo;
5451
}

tests/fixed/namespaces-spacing.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
strrev(
1717
(new DateTimeImmutable('@' . time(), new DateTimeZone('UTC')))
1818
->sub(new DateInterval('P1D'))
19-
->format(DATE_RFC3339)
19+
->format(DATE_RFC3339),
2020
);

tests/fixed/new_with_parentheses.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@
2424

2525
$z = new stdClass() ? new stdClass() : new stdClass();
2626

27-
$q = $q ?: new stdClass();
28-
$e = $e ?? new stdClass();
27+
$q = $q ?: new stdClass();
28+
$e ??= new stdClass();

tests/fixed/null_coalesce_equal_operator.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
declare(strict_types=1);
44

5-
$bar = $bar ?? 'bar';
5+
$bar ??= 'bar';
66

7-
$bar['baz'] = $bar['baz'] ?? 'baz';
7+
$bar['baz'] ??= 'baz';
88

9-
$bar = $bar ?? 'bar';
9+
$bar ??= 'bar';
1010

11-
$object->property = $object->property ?? 'Default Value';
11+
$object->property ??= 'Default Value';
1212

13-
Test::$foo = Test::$foo ?? 123;
13+
Test::$foo ??= 123;

tests/fixed/null_coalesce_operator.php

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

55
$foo = $_GET['foo'] ?? 'foo';
66

7-
$bar = $bar ?? 'bar';
7+
$bar ??= 'bar';
88

99
$bar = $bar['baz'] ?? 'baz';
1010

tests/fixed/null_safe_operator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
declare(strict_types=1);
44

5-
$var = $object === null ? null : $object->property;
5+
$var = $object?->property;

tests/fixed/return_type_on_closures.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static function (
2222
int $c,
2323
int $d,
2424
int $e,
25-
int $b
25+
int $b,
2626
): void {
2727
}
2828

@@ -31,7 +31,7 @@ static function (
3131
int $c,
3232
int $d,
3333
int $e,
34-
int $b
34+
int $b,
3535
): void {
3636
}
3737

@@ -40,7 +40,7 @@ static function (
4040
int $c,
4141
int $d,
4242
int $e,
43-
int $b
43+
int $b,
4444
): void {
4545
}
4646

@@ -49,7 +49,7 @@ static function (
4949
int $c,
5050
int $d,
5151
int $e,
52-
int $b
52+
int $b,
5353
): void {
5454
}
5555

@@ -58,6 +58,6 @@ static function (
5858
int $c,
5959
int $d,
6060
int $e,
61-
int $b
61+
int $b,
6262
): void {
6363
}

tests/fixed/return_type_on_methods.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function f(
3131
int $c,
3232
int $d,
3333
int $e,
34-
int $b
34+
int $b,
3535
): void {
3636
}
3737

@@ -40,7 +40,7 @@ public function g(
4040
int $c,
4141
int $d,
4242
int $e,
43-
int $b
43+
int $b,
4444
): void {
4545
}
4646

@@ -49,7 +49,7 @@ public function h(
4949
int $c,
5050
int $d,
5151
int $e,
52-
int $b
52+
int $b,
5353
): void {
5454
}
5555

@@ -58,7 +58,7 @@ public function i(
5858
int $c,
5959
int $d,
6060
int $e,
61-
int $b
61+
int $b,
6262
): void {
6363
}
6464

@@ -67,7 +67,7 @@ public function j(
6767
int $c,
6868
int $d,
6969
int $e,
70-
int $b
70+
int $b,
7171
): void {
7272
}
7373
}

tests/fixed/type-hints.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class TraversableTypeHints
1111
{
1212
/** @var Traversable */
13-
private $parameter;
13+
private Traversable $parameter;
1414

1515
/**
1616
* @param Iterator $iterator
@@ -25,6 +25,5 @@ public function get(Iterator $iterator): Traversable
2525

2626
class UnionTypeHints
2727
{
28-
/** @var int|string|null */
29-
private $x = 1;
28+
private int|string|null $x = 1;
3029
}

0 commit comments

Comments
 (0)