From d883bb4a2af8dfad7d50f079e6a097536911e10b Mon Sep 17 00:00:00 2001 From: Simon Podlipsky Date: Sat, 18 Jun 2022 09:22:28 +0300 Subject: [PATCH 1/4] ci: run checks on php 8.0 and 8.1 --- .github/workflows/continuous-integration.yml | 3 + Makefile | 7 + tests/php81-compatibility.patch | 165 +++++++++++++++++++ 3 files changed, 175 insertions(+) create mode 100644 tests/php81-compatibility.patch diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 16e50260..653d66c5 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -94,6 +94,8 @@ jobs: - "7.2" - "7.3" - "7.4" + - "8.0" + - "8.1" steps: - name: "Checkout" @@ -129,6 +131,7 @@ jobs: - "7.1" - "7.4" - "8.0" + - "8.1" steps: - name: "Checkout" diff --git a/Makefile b/Makefile index 7c6c5c69..88551bb2 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,13 @@ update-compatibility-patch-80: @git diff -- tests/expected_report.txt tests/fixed > .tmp-patch-80 && mv .tmp-patch-80 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 > .tmp-patch-81 && mv .tmp-patch-80 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 diff --git a/tests/php81-compatibility.patch b/tests/php81-compatibility.patch new file mode 100644 index 00000000..7cceac94 --- /dev/null +++ b/tests/php81-compatibility.patch @@ -0,0 +1,165 @@ +diff --git a/tests/expected_report.txt b/tests/expected_report.txt +index c644926..d0f0a44 100644 +--- a/tests/expected_report.txt ++++ b/tests/expected_report.txt +@@ -15,18 +15,19 @@ 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/example-class.php 42 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/PropertyTypeHintSpacing.php 6 0 + tests/input/return_type_on_closures.php 21 0 +@@ -39,15 +40,15 @@ 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/traits-uses.php 11 0 +-tests/input/type-hints.php 4 0 ++tests/input/type-hints.php 5 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 + ---------------------------------------------------------------------- +-A TOTAL OF 377 ERRORS AND 0 WARNINGS WERE FOUND IN 41 FILES ++A TOTAL OF 391 ERRORS AND 0 WARNINGS WERE FOUND IN 42 FILES + ---------------------------------------------------------------------- +-PHPCBF CAN FIX 313 OF THESE SNIFF VIOLATIONS AUTOMATICALLY ++PHPCBF CAN FIX 327 OF THESE SNIFF VIOLATIONS AUTOMATICALLY + ---------------------------------------------------------------------- + + +diff --git a/tests/fixed/NamingCamelCase.php b/tests/fixed/NamingCamelCase.php +index 57d9f2b..5493471 100644 +--- a/tests/fixed/NamingCamelCase.php ++++ b/tests/fixed/NamingCamelCase.php +@@ -6,14 +6,11 @@ namespace Example; + + 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 + { +diff --git a/tests/fixed/example-class.php b/tests/fixed/example-class.php +index 998e51d..b47d358 100644 +--- a/tests/fixed/example-class.php ++++ b/tests/fixed/example-class.php +@@ -25,17 +25,14 @@ class Example implements IteratorAggregate + { + private const VERSION = PHP_VERSION - (PHP_MINOR_VERSION * 100) - PHP_PATCH_VERSION; + +- /** @var int|null */ +- private $foo; ++ private ?int $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') + { +diff --git a/tests/fixed/new_with_parentheses.php b/tests/fixed/new_with_parentheses.php +index 6e81bbe..47a06ec 100644 +--- a/tests/fixed/new_with_parentheses.php ++++ b/tests/fixed/new_with_parentheses.php +@@ -24,5 +24,5 @@ $y = [new stdClass()]; + + $z = new stdClass() ? new stdClass() : new stdClass(); + +-$q = $q ?: new stdClass(); +-$e = $e ?? new stdClass(); ++$q = $q ?: new stdClass(); ++$e ??= new stdClass(); +diff --git a/tests/fixed/null_coalesce_equal_operator.php b/tests/fixed/null_coalesce_equal_operator.php +index b997469..6703d30 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'] = $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; +diff --git a/tests/fixed/null_coalesce_operator.php b/tests/fixed/null_coalesce_operator.php +index 8846dd1..51c361c 100644 +--- a/tests/fixed/null_coalesce_operator.php ++++ b/tests/fixed/null_coalesce_operator.php +@@ -4,7 +4,7 @@ declare(strict_types=1); + + $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 5bbb636..7ce8a3d 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 === null ? null : $object->property; ++$var = $object?->property; +diff --git a/tests/fixed/type-hints.php b/tests/fixed/type-hints.php +index 0e952fc..9824fb0 100644 +--- a/tests/fixed/type-hints.php ++++ b/tests/fixed/type-hints.php +@@ -10,7 +10,7 @@ use Traversable; + class TraversableTypeHints + { + /** @var Traversable */ +- private $parameter; ++ private Traversable $parameter; + + /** + * @param Iterator $iterator From 0c870cc6db33411f7a1ea7ccd583612c7d70eab9 Mon Sep 17 00:00:00 2001 From: Simon Podlipsky Date: Tue, 21 Jun 2022 11:21:36 +0300 Subject: [PATCH 2/4] fix: use tmp-patch file name We cannot run multiple update-compatibility-patch-* make targets at the same time so there's no need for having php version suffix in tmp-patch filename --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 88551bb2..967efdd6 100644 --- a/Makefile +++ b/Makefile @@ -28,14 +28,14 @@ update-compatibility-patch-80: @git apply tests/php80-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 > .tmp-patch-80 && mv .tmp-patch-80 tests/php80-compatibility.patch && git apply -R tests/php80-compatibility.patch + @git diff -- tests/expected_report.txt tests/fixed > .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 > .tmp-patch-81 && mv .tmp-patch-80 tests/php81-compatibility.patch && git apply -R tests/php81-compatibility.patch + @git diff -- tests/expected_report.txt tests/fixed > .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 From fd9171ded2fe711bd2e7134253f3e8f2340bc394 Mon Sep 17 00:00:00 2001 From: Simon Podlipsky Date: Sat, 18 Jun 2022 09:11:28 +0300 Subject: [PATCH 3/4] chore(deps): require slevomat/coding-standard v8 and squizlabs/php_codesniffer v3.7 - Bump min php to 7.2 --- .github/workflows/continuous-integration.yml | 3 +-- composer.json | 6 +++--- lib/Doctrine/ruleset.xml | 3 ++- tests/expected_report.txt | 2 +- ...{PropertyTypeHintSpacing.php => PropertyDeclaration.php} | 2 +- ...{PropertyTypeHintSpacing.php => PropertyDeclaration.php} | 2 +- tests/php74-compatibility.patch | 2 +- tests/php80-compatibility.patch | 2 +- tests/php81-compatibility.patch | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) rename tests/fixed/{PropertyTypeHintSpacing.php => PropertyDeclaration.php} (85%) rename tests/input/{PropertyTypeHintSpacing.php => PropertyDeclaration.php} (86%) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 653d66c5..09e02194 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -90,7 +90,6 @@ jobs: strategy: matrix: php-version: - - "7.1" - "7.2" - "7.3" - "7.4" @@ -128,7 +127,7 @@ jobs: strategy: matrix: php-version: - - "7.1" + - "7.2" - "7.4" - "8.0" - "8.1" diff --git a/composer.json b/composer.json index 56f6640a..fba38976 100644 --- a/composer.json +++ b/composer.json @@ -21,10 +21,10 @@ {"name": "Steve Müller", "email": "st.mueller@dzh-online.de"} ], "require": { - "php": "^7.1 || ^8.0", + "php": "^7.2 || ^8.0", "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7", - "slevomat/coding-standard": "^7.0.0", - "squizlabs/php_codesniffer": "^3.6.0" + "slevomat/coding-standard": "^8", + "squizlabs/php_codesniffer": "^3.7" }, "config": { "sort-packages": true diff --git a/lib/Doctrine/ruleset.xml b/lib/Doctrine/ruleset.xml index d841c154..f3bc93b4 100644 --- a/lib/Doctrine/ruleset.xml +++ b/lib/Doctrine/ruleset.xml @@ -133,6 +133,8 @@ + + @@ -408,7 +410,6 @@ - diff --git a/tests/expected_report.txt b/tests/expected_report.txt index c6449260..476a58b9 100644 --- a/tests/expected_report.txt +++ b/tests/expected_report.txt @@ -28,7 +28,7 @@ tests/input/not_spacing.php 8 0 tests/input/null_coalesce_equal_operator.php 1 0 tests/input/null_coalesce_operator.php 3 0 tests/input/optimized-functions.php 1 0 -tests/input/PropertyTypeHintSpacing.php 6 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 diff --git a/tests/fixed/PropertyTypeHintSpacing.php b/tests/fixed/PropertyDeclaration.php similarity index 85% rename from tests/fixed/PropertyTypeHintSpacing.php rename to tests/fixed/PropertyDeclaration.php index 14219130..5c3f27b7 100644 --- a/tests/fixed/PropertyTypeHintSpacing.php +++ b/tests/fixed/PropertyDeclaration.php @@ -4,7 +4,7 @@ namespace Spacing; -final class PropertyTypeHintSpacing +final class PropertyDeclaration { public bool $boolPropertyWithDefaultValue = false; public string $stringProperty; diff --git a/tests/input/PropertyTypeHintSpacing.php b/tests/input/PropertyDeclaration.php similarity index 86% rename from tests/input/PropertyTypeHintSpacing.php rename to tests/input/PropertyDeclaration.php index 40475e96..0891e125 100644 --- a/tests/input/PropertyTypeHintSpacing.php +++ b/tests/input/PropertyDeclaration.php @@ -4,7 +4,7 @@ namespace Spacing; -final class PropertyTypeHintSpacing +final class PropertyDeclaration { public bool $boolPropertyWithDefaultValue = false; public string $stringProperty; diff --git a/tests/php74-compatibility.patch b/tests/php74-compatibility.patch index 1301ea75..f9ca8be0 100644 --- a/tests/php74-compatibility.patch +++ b/tests/php74-compatibility.patch @@ -22,7 +22,7 @@ index fd5432c..233e24d 100644 +tests/input/null_coalesce_equal_operator.php 5 0 tests/input/null_coalesce_operator.php 3 0 tests/input/optimized-functions.php 1 0 - tests/input/PropertyTypeHintSpacing.php 6 0 + tests/input/PropertyDeclaration.php 6 0 @@ -39,15 +39,15 @@ tests/input/superfluous-naming.php 11 0 tests/input/test-case.php 8 0 tests/input/trailing_comma_on_array.php 1 0 diff --git a/tests/php80-compatibility.patch b/tests/php80-compatibility.patch index 7cceac94..9bfdfa1d 100644 --- a/tests/php80-compatibility.patch +++ b/tests/php80-compatibility.patch @@ -24,7 +24,7 @@ index c644926..d0f0a44 100644 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/PropertyTypeHintSpacing.php 6 0 + tests/input/PropertyDeclaration.php 6 0 tests/input/return_type_on_closures.php 21 0 @@ -39,15 +40,15 @@ tests/input/superfluous-naming.php 11 0 tests/input/test-case.php 8 0 diff --git a/tests/php81-compatibility.patch b/tests/php81-compatibility.patch index 7cceac94..9bfdfa1d 100644 --- a/tests/php81-compatibility.patch +++ b/tests/php81-compatibility.patch @@ -24,7 +24,7 @@ index c644926..d0f0a44 100644 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/PropertyTypeHintSpacing.php 6 0 + tests/input/PropertyDeclaration.php 6 0 tests/input/return_type_on_closures.php 21 0 @@ -39,15 +40,15 @@ tests/input/superfluous-naming.php 11 0 tests/input/test-case.php 8 0 From 161c8202d29a38d9393a3d674d45c6d4922b5186 Mon Sep 17 00:00:00 2001 From: Simon Podlipsky Date: Sun, 26 Jun 2022 14:27:41 +0300 Subject: [PATCH 4/4] fix: rename itens to items --- tests/fixed/EarlyReturn.php | 2 +- tests/input/EarlyReturn.php | 2 +- tests/php80-compatibility.patch | 2 +- tests/php81-compatibility.patch | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/fixed/EarlyReturn.php b/tests/fixed/EarlyReturn.php index 5a82a937..caf1dbb6 100644 --- a/tests/fixed/EarlyReturn.php +++ b/tests/fixed/EarlyReturn.php @@ -13,7 +13,7 @@ public function bar(): bool public function foo(): ?string { - foreach ($itens as $item) { + foreach ($items as $item) { if (! $item->isItem()) { return 'There is an item that is not an item'; } diff --git a/tests/input/EarlyReturn.php b/tests/input/EarlyReturn.php index 7d90c6d6..9f13d86e 100644 --- a/tests/input/EarlyReturn.php +++ b/tests/input/EarlyReturn.php @@ -17,7 +17,7 @@ public function bar(): bool public function foo(): ?string { - foreach ($itens as $item) { + foreach ($items as $item) { if (! ($item->isItem())) { return 'There is an item that is not an item'; } else { diff --git a/tests/php80-compatibility.patch b/tests/php80-compatibility.patch index cedc03c0..0963401f 100644 --- a/tests/php80-compatibility.patch +++ b/tests/php80-compatibility.patch @@ -69,7 +69,7 @@ index 5a82a93..7d5eb01 100644 - public function foo(): ?string + public function foo(): string|null { - foreach ($itens as $item) { + foreach ($items as $item) { if (! $item->isItem()) { diff --git a/tests/fixed/NamingCamelCase.php b/tests/fixed/NamingCamelCase.php index 57d9f2b..5493471 100644 diff --git a/tests/php81-compatibility.patch b/tests/php81-compatibility.patch index cedc03c0..0963401f 100644 --- a/tests/php81-compatibility.patch +++ b/tests/php81-compatibility.patch @@ -69,7 +69,7 @@ index 5a82a93..7d5eb01 100644 - public function foo(): ?string + public function foo(): string|null { - foreach ($itens as $item) { + foreach ($items as $item) { if (! $item->isItem()) { diff --git a/tests/fixed/NamingCamelCase.php b/tests/fixed/NamingCamelCase.php index 57d9f2b..5493471 100644