Skip to content

Commit

Permalink
Merge pull request #282 from derrabus/improvement/reverse-patches
Browse files Browse the repository at this point in the history
Upgrade fixtures to PHP 8.1 and reverse patches
  • Loading branch information
derrabus committed Jul 20, 2022
2 parents e64b67f + cb35b8f commit 720492b
Show file tree
Hide file tree
Showing 31 changed files with 1,172 additions and 1,012 deletions.
14 changes: 7 additions & 7 deletions Makefile
Expand Up @@ -8,6 +8,13 @@ test-report: vendor
test-fix: vendor
./bin/test-fix

update-compatibility-patch-72:
@git apply tests/php72-compatibility.patch
@printf "Please open your editor and apply your changes\n"
@until [ "$${compatibility_resolved}" == "y" ]; do read -p "Have finished your changes (y|n)? " compatibility_resolved; done && compatibility_resolved=
@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
@git commit -m 'Update compatibility patch' tests/php72-compatibility.patch

update-compatibility-patch-73:
@git apply tests/php73-compatibility.patch
@printf "Please open your editor and apply your changes\n"
Expand All @@ -29,13 +36,6 @@ update-compatibility-patch-80:
@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
@git commit -m 'Update compatibility patch' tests/php80-compatibility.patch

update-compatibility-patch-81:
@git apply tests/php81-compatibility.patch
@printf "Please open your editor and apply your changes\n"
@until [ "$${compatibility_resolved}" == "y" ]; do read -p "Have finished your changes (y|n)? " compatibility_resolved; done && compatibility_resolved=
@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
@git commit -m 'Update compatibility patch' tests/php81-compatibility.patch

vendor: composer.json
composer update
touch -c vendor
28 changes: 16 additions & 12 deletions tests/expected_report.txt
Expand Up @@ -14,23 +14,26 @@ tests/input/constants-var.php 7 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 6 0
tests/input/example-class.php 38 0
tests/input/EarlyReturn.php 7 0
tests/input/example-class.php 43 0
tests/input/ExampleBackedEnum.php 3 0
tests/input/Exceptions.php 1 0
tests/input/forbidden-comments.php 14 0
tests/input/forbidden-functions.php 6 0
tests/input/inline_type_hint_assertions.php 7 0
tests/input/LowCaseTypes.php 2 0
tests/input/namespaces-spacing.php 7 0
tests/input/NamingCamelCase.php 6 0
tests/input/NamingCamelCase.php 9 0
tests/input/negation-operator.php 2 0
tests/input/new_with_parentheses.php 18 0
tests/input/new_with_parentheses.php 19 0
tests/input/not_spacing.php 8 0
tests/input/null_coalesce_equal_operator.php 1 0
tests/input/null_coalesce_equal_operator.php 5 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 6 0
tests/input/return_type_on_closures.php 21 0
tests/input/return_type_on_methods.php 17 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/semicolon_spacing.php 3 0
tests/input/single-line-array-spacing.php 5 0
tests/input/spread-operator.php 6 0
Expand All @@ -39,16 +42,17 @@ tests/input/strings.php 1 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 7 0
tests/input/type-hints.php 9 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 20 0
tests/input/UselessConditions.php 21 0
----------------------------------------------------------------------
A TOTAL OF 382 ERRORS AND 0 WARNINGS WERE FOUND IN 42 FILES
A TOTAL OF 428 ERRORS AND 0 WARNINGS WERE FOUND IN 46 FILES
----------------------------------------------------------------------
PHPCBF CAN FIX 317 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
PHPCBF CAN FIX 363 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


2 changes: 1 addition & 1 deletion tests/fixed/ControlStructures.php
Expand Up @@ -104,7 +104,7 @@ public function spaceBelowBlocks(): void

try {
echo 4;
} catch (Throwable $throwable) {
} catch (Throwable) {
}

echo 5;
Expand Down
2 changes: 1 addition & 1 deletion tests/fixed/EarlyReturn.php
Expand Up @@ -11,7 +11,7 @@ public function bar(): bool
return $bar === 'bar';
}

public function foo(): ?string
public function foo(): string|null
{
foreach ($items as $item) {
if (! $item->isItem()) {
Expand Down
4 changes: 4 additions & 0 deletions tests/fixed/ExampleBackedEnum.php
Expand Up @@ -3,3 +3,7 @@
declare(strict_types=1);

namespace ExampleBackedEnum;

enum ExampleBackedEnum: int
{
}
8 changes: 8 additions & 0 deletions tests/fixed/Exceptions.php
Expand Up @@ -3,3 +3,11 @@
declare(strict_types=1);

namespace Exceptions;

use Exception;
use Throwable;

try {
throw new Exception();
} catch (Throwable) {
}
9 changes: 3 additions & 6 deletions tests/fixed/NamingCamelCase.php
Expand Up @@ -6,14 +6,11 @@

class NamingCamelCase
{
/** @var mixed */
public $A;
public mixed $A;

/** @var mixed */
protected $B;
protected mixed $B;

/** @var mixed */
private $C;
private mixed $C;

public function fcn(string $A): void
{
Expand Down
7 changes: 6 additions & 1 deletion tests/fixed/PropertyDeclaration.php
Expand Up @@ -9,5 +9,10 @@ final class PropertyDeclaration
public bool $boolPropertyWithDefaultValue = false;
public string $stringProperty;
public int $intProperty;
public ?string $nullableString = null;
public string|null $nullableString = null;

public function __construct(
public readonly Foo $foo,
) {
}
}
7 changes: 4 additions & 3 deletions tests/fixed/TrailingCommaOnFunctions.php
Expand Up @@ -15,7 +15,7 @@ public function a(int $arg): void
}

public function b(
int $arg
int $arg,
): void {
}

Expand All @@ -28,7 +28,7 @@ public function uses(): void
};

$multiLine = static function (int $arg) use (
$var
$var,
): void {
var_dump($var);
};
Expand All @@ -37,8 +37,9 @@ public function uses(): void

$class = new TrailingCommaOnFunctions();

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

$class->a(
1
1,
);
2 changes: 1 addition & 1 deletion tests/fixed/UselessConditions.php
Expand Up @@ -95,7 +95,7 @@ public function necessaryIfConditionWithMethodCall(): bool
return false;
}

public function nullShouldNotBeTreatedAsFalse(): ?bool
public function nullShouldNotBeTreatedAsFalse(): bool|null
{
if (! $this->isAdmin) {
return null;
Expand Down
4 changes: 2 additions & 2 deletions tests/fixed/arrow-functions-format.php
Expand Up @@ -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'];
Expand Down
15 changes: 6 additions & 9 deletions tests/fixed/example-class.php
Expand Up @@ -25,19 +25,16 @@ class Example implements IteratorAggregate
{
private const VERSION = PHP_VERSION - (PHP_MINOR_VERSION * 100) - PHP_PATCH_VERSION;

/** @var int|null */
private $foo;
private int|null $foo = null;

/** @var string[] */
private $bar;
private array $bar;

/** @var bool */
private $baz;
private bool $baz;

/** @var ControlStructureSniff|int|string|null */
private $baxBax;
private ControlStructureSniff|int|string|null $baxBax = null;

public function __construct(?int $foo = null, array $bar = [], bool $baz = false, $baxBax = 'unused')
public function __construct(int|null $foo = null, array $bar = [], bool $baz = false, $baxBax = 'unused')
{
$this->foo = $foo;
$this->bar = $bar;
Expand All @@ -48,7 +45,7 @@ public function __construct(?int $foo = null, array $bar = [], bool $baz = false
/**
* Description
*/
public function getFoo(): ?int
public function getFoo(): int|null
{
return $this->foo;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/fixed/namespaces-spacing.php
Expand Up @@ -16,5 +16,5 @@
strrev(
(new DateTimeImmutable('@' . time(), new DateTimeZone('UTC')))
->sub(new DateInterval('P1D'))
->format(DATE_RFC3339)
->format(DATE_RFC3339),
);
4 changes: 2 additions & 2 deletions tests/fixed/new_with_parentheses.php
Expand Up @@ -24,5 +24,5 @@

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

$q = $q ?: new stdClass();
$e = $e ?? new stdClass();
$q = $q ?: new stdClass();
$e ??= new stdClass();
10 changes: 5 additions & 5 deletions tests/fixed/null_coalesce_equal_operator.php
Expand Up @@ -2,12 +2,12 @@

declare(strict_types=1);

$bar = $bar ?? 'bar';
$bar ??= 'bar';

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

$bar = $bar ?? 'bar';
$bar ??= 'bar';

$object->property = $object->property ?? 'Default Value';
$object->property ??= 'Default Value';

Test::$foo = Test::$foo ?? 123;
Test::$foo ??= 123;
2 changes: 1 addition & 1 deletion tests/fixed/null_coalesce_operator.php
Expand Up @@ -4,7 +4,7 @@

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

$bar = $bar ?? 'bar';
$bar ??= 'bar';

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

Expand Down
2 changes: 1 addition & 1 deletion tests/fixed/null_safe_operator.php
Expand Up @@ -2,4 +2,4 @@

declare(strict_types=1);

$var = $object === null ? null : $object->property;
$var = $object?->property;
10 changes: 5 additions & 5 deletions tests/fixed/return_type_on_closures.php
Expand Up @@ -22,7 +22,7 @@ static function (
int $c,
int $d,
int $e,
int $b
int $b,
): void {
}

Expand All @@ -31,7 +31,7 @@ static function (
int $c,
int $d,
int $e,
int $b
int $b,
): void {
}

Expand All @@ -40,7 +40,7 @@ static function (
int $c,
int $d,
int $e,
int $b
int $b,
): void {
}

Expand All @@ -49,7 +49,7 @@ static function (
int $c,
int $d,
int $e,
int $b
int $b,
): void {
}

Expand All @@ -58,6 +58,6 @@ static function (
int $c,
int $d,
int $e,
int $b
int $b,
): void {
}
10 changes: 5 additions & 5 deletions tests/fixed/return_type_on_methods.php
Expand Up @@ -31,7 +31,7 @@ public function f(
int $c,
int $d,
int $e,
int $b
int $b,
): void {
}

Expand All @@ -40,7 +40,7 @@ public function g(
int $c,
int $d,
int $e,
int $b
int $b,
): void {
}

Expand All @@ -49,7 +49,7 @@ public function h(
int $c,
int $d,
int $e,
int $b
int $b,
): void {
}

Expand All @@ -58,7 +58,7 @@ public function i(
int $c,
int $d,
int $e,
int $b
int $b,
): void {
}

Expand All @@ -67,7 +67,7 @@ public function j(
int $c,
int $d,
int $e,
int $b
int $b,
): void {
}
}
5 changes: 2 additions & 3 deletions tests/fixed/type-hints.php
Expand Up @@ -10,7 +10,7 @@
class TraversableTypeHints
{
/** @var Traversable */
private $parameter;
private Traversable $parameter;

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

class UnionTypeHints
{
/** @var int|string|null */
private $x = 1;
private int|string|null $x = 1;
}

0 comments on commit 720492b

Please sign in to comment.