Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Merge Config instead of Replace on RectorConfig->ruleWithConfiguration() take - 2 #2656

Closed
wants to merge 17 commits into from

Conversation

samsonasik
Copy link
Member

Re-create closed PR #2655

@samsonasik
Copy link
Member Author

samsonasik commented Jul 12, 2022

@TomasVotruba Finally working 🎉 🎉 🎉 , the trick is:

  • Save to variable the original config which not converted to InlineServiceConfigurator yet early
  • Merge config if there is existing config with rule
  • Convert to InlineServiceConfigurator after merged if values are object and use to decorate the service.
  • Save the original config to property fetch configuration collection.

@samsonasik
Copy link
Member Author

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

@MartinMystikJonas
Copy link
Contributor

I would really like to see this merged. Current way with possible unnoticed accidental loose of configured rule does not seem to follow rule of least surprise. Merging inside config same was as between different configs seems logical to me.

@TomasVotruba
Copy link
Member

TomasVotruba commented Jul 12, 2022

This should rather raise an exception, as convention in DI configs is to add them once.

@samsonasik
Copy link
Member Author

raise an exception could cause issue if user want to use SetList but want to override one of the rule, eg:

<?php

use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\SetList;

return static function (RectorConfig $rectorConfig): void {
    
    $rectorConfig->sets([
        SetList::CODING_STYLE
    ]);
    
    $rectorConfig
        ->ruleWithConfiguration(Rector\Transform\Rector\FuncCall\FuncCallToConstFetchRector::class, [
            'php_sapi' => 'NEW_Constant'
        ]);

    };

to override existing config

->ruleWithConfiguration(FuncCallToConstFetchRector::class, [

@MartinMystikJonas
Copy link
Contributor

@samsonasik My solution do not raise exception in this case.

@MartinMystikJonas
Copy link
Contributor

MartinMystikJonas commented Jul 12, 2022

@TomasVotruba From user point of view I do not know and do not care about fact that RectorConfig internally uses Symfony DI to register rules. I expect that if I add two rules to rename class it would rename them both. Or at least notify me that I must add rule only once with merged configs.

@TomasVotruba
Copy link
Member

TomasVotruba commented Jul 12, 2022

Even if we don't use any fw package, registering the same service twice in single config is not valid. Allowing it spread bad practise and expose us to handle all other unexpected behaviors. We won't go that way.

@TomasVotruba
Copy link
Member

@samsonasik That's different case. I talk about same config with 2 explicit registration of 1 service.

@samsonasik
Copy link
Member Author

@MartinMystikJonas I see, that's possibly due to imported config, that's will need unit tests tho, eg, under tests/Issues

@TomasVotruba ok, I am closing it then.

@samsonasik samsonasik closed this Jul 12, 2022
@samsonasik samsonasik deleted the merge-config-take-2 branch July 12, 2022 11:11
@MartinMystikJonas
Copy link
Contributor

@TomasVotruba Ok so do we keep current status quo with silently ignoring these usage error or should I add tests coverage as @samsonasik suggested and finish my PR that throws error when same rule is added twice?

@TomasVotruba
Copy link
Member

This must be resolved on Symfony level, as that's the architecture pattern we respect.
Let's mark it won't fix here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants