From 520445393e7e8cc0ae34c7aa337bead2808fdcc8 Mon Sep 17 00:00:00 2001 From: Markus Gerdes Date: Wed, 24 Jul 2024 13:28:13 +0200 Subject: [PATCH 1/9] fix: import the fractor configuration if found in fractor.php file Otherwise there was an error: ``` FRACTOR: Fatal error: Uncaught TypeError: a9f\Fractor\Configuration\FractorConfigurationBuilder::__invoke(): Argument #1 ($containerConfigurator) must be of type Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator, a9f\Fractor\Configuration\FractorConfigurationBuilder given, called in /var/www/html/lifter/vendor/a9f/lifter/res/run_fractor.php on line 19 and defined in /var/www/html/lifter/vendor/a9f/fractor/src/Configuration/FractorConfigurationBuilder.php:49 ``` --- res/run_fractor.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/res/run_fractor.php b/res/run_fractor.php index e05981a..3950f1a 100644 --- a/res/run_fractor.php +++ b/res/run_fractor.php @@ -14,9 +14,7 @@ if (!is_string($fractorConfigFile)) { throw new \RuntimeException('No file passed in env variable FRACTOR_CONFIG_FILE', 1712507292); } - $fractorConfigClosure = (require $fractorConfigFile); - Assert::isCallable($fractorConfigClosure, 'FRACTOR_CONFIG_FILE did not yield a callable'); - $fractorConfigClosure($fractorConfig); + $fractorConfig->import($fractorConfigFile); $lifterConfigFile = getenv('LIFTER_CONFIG_FILE'); if (!is_string($lifterConfigFile)) { From e2bf5a44b930486ed02b272f74f3f44a95974c49 Mon Sep 17 00:00:00 2001 From: Markus Gerdes <107911221+mgerdes-atl@users.noreply.github.com> Date: Tue, 3 Dec 2024 14:05:23 +0100 Subject: [PATCH 2/9] Additonally allow Fractor 0.4 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 33d5173..f9ac32e 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ ], "require": { "php": "^8.2", - "a9f/fractor": "^0.3", + "a9f/fractor": "^0.3 || ^0.4", "rector/rector": "^1.0", "symfony/config": "^6.4 || ^7.0", "symfony/console": "^6.4 || ^7.0", From c4c835b545dd4e10e31bd6139ef05078df7aa4e6 Mon Sep 17 00:00:00 2001 From: Andreas Wolf Date: Mon, 16 Dec 2024 15:24:18 +0100 Subject: [PATCH 3/9] fix: Use new Fractor config in e2e tests --- e2e/fractor/fractor.php | 7 +++---- e2e/fractor/lifter.php | 14 +++++++------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/e2e/fractor/fractor.php b/e2e/fractor/fractor.php index 61e6515..3682131 100644 --- a/e2e/fractor/fractor.php +++ b/e2e/fractor/fractor.php @@ -1,7 +1,6 @@ withPaths([__DIR__ . '/result/**']); \ No newline at end of file diff --git a/e2e/fractor/lifter.php b/e2e/fractor/lifter.php index 8711ed7..40133d9 100644 --- a/e2e/fractor/lifter.php +++ b/e2e/fractor/lifter.php @@ -17,13 +17,13 @@ new FractorStep( 'Update phpunit/phpunit to 11.x', static function (FractorConfigurationBuilder $fractorConfig) { - $fractorConfig->withPaths([__DIR__ . '/result/**']); - $fractorConfig->withConfiguredRule( - ChangePackageVersionComposerJsonFractor::class, - [ - new PackageAndVersion('phpunit/phpunit', '^11.2') - ] - ); + return $fractorConfig + ->withConfiguredRule( + ChangePackageVersionComposerJsonFractor::class, + [ + new PackageAndVersion('phpunit/phpunit', '^11.2') + ] + ); } ) ]); From e77a8c3836baa0afa58816fe6ab3998b68196fc2 Mon Sep 17 00:00:00 2001 From: Andreas Wolf Date: Mon, 16 Dec 2024 15:25:49 +0100 Subject: [PATCH 4/9] cleanup: Remove unused import --- res/run_fractor.php | 1 - 1 file changed, 1 deletion(-) diff --git a/res/run_fractor.php b/res/run_fractor.php index 3950f1a..4a11068 100644 --- a/res/run_fractor.php +++ b/res/run_fractor.php @@ -4,7 +4,6 @@ use a9f\Lifter\Configuration\LifterConfigFactory; use a9f\Lifter\Upgrade\Step\FractorStep; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; -use Webmozart\Assert\Assert; return static function (ContainerConfigurator $configurator) { $fractorConfig = FractorConfiguration::configure(); From 0763235e3cb2e540eb3155bf6269b6635c176839 Mon Sep 17 00:00:00 2001 From: Andreas Wolf Date: Mon, 16 Dec 2024 15:24:18 +0100 Subject: [PATCH 5/9] Drop support for Fractor 0.3 Since 0.4 changes the config format, we can hardly support both versions at the same time --- composer.json | 2 +- e2e/composer.json | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index f9ac32e..e575a02 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ ], "require": { "php": "^8.2", - "a9f/fractor": "^0.3 || ^0.4", + "a9f/fractor": "^0.4", "rector/rector": "^1.0", "symfony/config": "^6.4 || ^7.0", "symfony/console": "^6.4 || ^7.0", diff --git a/e2e/composer.json b/e2e/composer.json index 0f49140..95d68c0 100644 --- a/e2e/composer.json +++ b/e2e/composer.json @@ -3,10 +3,10 @@ "type": "project", "require": { "a9f/lifter": "@dev", - "a9f/fractor": "^0.3", - "a9f/fractor-composer-json": "^0.3", - "a9f/fractor-doc-generator": "^0.3", - "a9f/fractor-extension-installer": "^0.3", + "a9f/fractor": "^0.4", + "a9f/fractor-composer-json": "^0.4", + "a9f/fractor-doc-generator": "^0.4", + "a9f/fractor-extension-installer": "^0.4", "symplify/rule-doc-generator-contracts": "^11.2" }, "require-dev": { From ca992d7dc7dccb98d8495ab34e81b1eed0c9ea2a Mon Sep 17 00:00:00 2001 From: Andreas Wolf Date: Mon, 16 Dec 2024 15:38:47 +0100 Subject: [PATCH 6/9] fix: Adjust expected test output for Rector --- e2e/rector/expected-output.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/e2e/rector/expected-output.txt b/e2e/rector/expected-output.txt index 632fde4..95446e1 100644 --- a/e2e/rector/expected-output.txt +++ b/e2e/rector/expected-output.txt @@ -1,3 +1,4 @@ RECTOR: RECTOR: [OK] 1 file has been changed by Rector +RECTOR: From f1278080e63a39bbd3082502992b9edf1bb45f08 Mon Sep 17 00:00:00 2001 From: Andreas Wolf Date: Mon, 16 Dec 2024 15:46:50 +0100 Subject: [PATCH 7/9] TMP --- e2e/rector/expected-output.txt | 1 - src/Upgrade/Step/FractorStepExecutor.php | 8 +++++++- src/Upgrade/Step/RectorStepExecutor.php | 18 ++++++++++++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/e2e/rector/expected-output.txt b/e2e/rector/expected-output.txt index 95446e1..6d093dc 100644 --- a/e2e/rector/expected-output.txt +++ b/e2e/rector/expected-output.txt @@ -1,4 +1,3 @@ RECTOR: RECTOR: [OK] 1 file has been changed by Rector RECTOR: - diff --git a/src/Upgrade/Step/FractorStepExecutor.php b/src/Upgrade/Step/FractorStepExecutor.php index c9d3499..3c41fe4 100644 --- a/src/Upgrade/Step/FractorStepExecutor.php +++ b/src/Upgrade/Step/FractorStepExecutor.php @@ -56,11 +56,17 @@ public function run(int $index, UpgradeStep $step): void ], timeout: 3600 ); - $process->run(static function ($type, $data) { + $firstLine = true; + $process->run(static function ($type, $data) use (&$firstLine) { $data = trim($data); // TODO do we need to handle CRLF separately here? $lines = explode("\n", $data); + if (!$firstLine) { + echo array_shift($lines); + } else { + $firstLine = false; + } $lines = array_map( static fn (string $line) => "FRACTOR: $line", $lines diff --git a/src/Upgrade/Step/RectorStepExecutor.php b/src/Upgrade/Step/RectorStepExecutor.php index 0d11ef7..60d70cb 100644 --- a/src/Upgrade/Step/RectorStepExecutor.php +++ b/src/Upgrade/Step/RectorStepExecutor.php @@ -56,8 +56,22 @@ public function run(int $index, UpgradeStep $step): void ], timeout: 3600 ); - $process->run(static function ($type, $data) { - echo 'RECTOR: ' . $data; + $firstLine = true; + $process->run(static function ($type, $data) use (&$firstLine) { + $data = trim($data); + + // TODO do we need to handle CRLF separately here? + $lines = explode("\n", $data); + if (!$firstLine) { + echo array_shift($lines); + } else { + $firstLine = false; + } + $lines = array_map( + static fn (string $line) => "RECTOR: $line", + $lines + ); + echo implode("\n", $lines), "\n"; }); } } From 75d7fe00ef989eef287e934624f470c7a12dc0da Mon Sep 17 00:00:00 2001 From: Andreas Wolf Date: Mon, 16 Dec 2024 14:22:19 +0100 Subject: [PATCH 8/9] Update PhpStan to 2.0 --- composer.json | 6 +++--- phpstan.neon | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index e575a02..2aaa13b 100644 --- a/composer.json +++ b/composer.json @@ -23,11 +23,11 @@ }, "require-dev": { "ergebnis/composer-normalize": "^2.42", - "phpstan/extension-installer": "^1.3", - "phpstan/phpstan": "^1.10", + "phpstan/extension-installer": "^1.4", + "phpstan/phpstan": "^2.0", "phpunit/phpunit": "^11.0", "symplify/easy-coding-standard": "^12.1", - "thecodingmachine/phpstan-safe-rule": "^1.2" + "thecodingmachine/phpstan-safe-rule": "^2.0-dev" }, "autoload": { "psr-4": { diff --git a/phpstan.neon b/phpstan.neon index fb53f61..df2971a 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -8,4 +8,6 @@ parameters: # this is required because of our generic interface StepExecutor that we use w/o specifying a concrete subtype, # e.g. in UpgradeRunner - checkGenericClassInNonGenericObjectType: false + ignoreErrors: + - + identifier: missingType.generics From 50dec90e2096c0fedfc69c7ad10fb68d70cb414a Mon Sep 17 00:00:00 2001 From: Andreas Wolf Date: Mon, 16 Dec 2024 14:16:26 +0100 Subject: [PATCH 9/9] Require Rector 2.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2aaa13b..e9a2db2 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "require": { "php": "^8.2", "a9f/fractor": "^0.4", - "rector/rector": "^1.0", + "rector/rector": "^2.0", "symfony/config": "^6.4 || ^7.0", "symfony/console": "^6.4 || ^7.0", "symfony/dependency-injection": "^6.4 || ^7.0",