rector-src icon indicating copy to clipboard operation
rector-src copied to clipboard

[Experiment] Use composer.json as priority, fallback to php version features on when parameter exists on ComposerJsonPhpVersionResolver

Open samsonasik opened this issue 1 year ago • 3 comments

Ref https://github.com/rectorphp/rector-src/pull/6261#pullrequestreview-2371088505

samsonasik avatar Oct 16 '24 04:10 samsonasik

implemented :tada:, here the summary:

This PR provide a way to set withPhpVersion() even composer.json not exists or doesn't define "php" config, so it fallback php version feature defined, with priority:

  1. read composer.json, if exists and define "php" config, then use it
  2. verify if it has Option::PHP_VERSION_FEATURES via withPhpVersion(), if exists, then use it as fallback
  3. throw error because nothing to rely

The config can be:

use Rector\Config\RectorConfig;
use Rector\ValueObject\PhpVersionFeature;

return RectorConfig::configure()
    ->withPaths([__DIR__ . '/src'])
    ->withPhpVersion(PhpVersionFeature::ATTRIBUTES)
    ->withPhpLevel(2);

I add e2e test on this PR for proof that it works for apply on level 2, but current php version is php 8, which only apply php 5.2 change:

-ldap_first_attribute($ldap, $entry, $more);
+ldap_first_attribute($ldap, $entry);

By this PR, I found a bug duplicated ContinueToBreakInSwitchRector register which registered in php52 and php73 config https://github.com/rectorphp/rector-src/pull/6384/commits/06026a06605cb1a37f420772e722019f66d4ccf0

I will create separate PR to remove duplicated register ContinueToBreakInSwitchRector

samsonasik avatar Oct 16 '24 04:10 samsonasik

I created separate PR to remove duplicated register ContinueToBreakInSwitchRector that exists in both php52 and php73 config

  • https://github.com/rectorphp/rector-src/pull/6385

samsonasik avatar Oct 16 '24 04:10 samsonasik

All checks have passed 🎉 @TomasVotruba it is ready for review.

I don't rebase cherry-pick patch https://github.com/rectorphp/rector-src/pull/6385 so you can see the process and how it found a bug with e2e test :)

samsonasik avatar Oct 16 '24 05:10 samsonasik

Closing for now

samsonasik avatar Dec 12 '24 04:12 samsonasik