Skip to content
This repository has been archived by the owner on Dec 3, 2023. It is now read-only.

[ECS] SetList SKIPs are overwritten when ecs.php SKIPs are defined #3972

Closed
ghispi opened this issue Mar 2, 2022 · 4 comments
Closed

[ECS] SetList SKIPs are overwritten when ecs.php SKIPs are defined #3972

ghispi opened this issue Mar 2, 2022 · 4 comments

Comments

@ghispi
Copy link
Contributor

ghispi commented Mar 2, 2022

ISSUE
It is not possible to use setlist and add some customisation customised skips on top of them as the skips from setlist are overwritten.

config for reproduction:
Before testing please adjust namespace prefix for ContainerBuilder.

<?php

use ECSPrefix20220221\Symfony\Component\DependencyInjection\ContainerBuilder;
use PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineLengthSniff;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\EasyCodingStandard\ValueObject\Option;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

return static function (ContainerConfigurator $containerConfigurator, ContainerBuilder $container): void {
    $containerConfigurator->import(SetList::PSR_12);

    print_r($container->getParameterBag()->get(Option::SKIP));

    $parameters = $containerConfigurator->parameters();
    $parameters->set(Option::SKIP, [
        LineLengthSniff::class,
    ]);

    print_r($container->getParameterBag()->get(Option::SKIP));
    die();
};

output:

Array
(
    [0] => PhpCsFixer\Fixer\Import\SingleImportPerStatementFixer
)
Array
(
    [0] => PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineLengthSniff
)

I couldn't find reasonable way (without using prefixed ContainerBuilder) to grab already configured skips and in the end I had to copy them inside app config for ecs.

If there is already a way to overcome this behavior and I'm just being stupid then please let me know. All help appreciated.

@ghispi ghispi changed the title [ECS] RuleSet SKIPs are overwritten ecs.php skips are defined [ECS] SetList SKIPs are overwritten when ecs.php SKIPs are defined Mar 2, 2022
@TomasVotruba
Copy link
Member

Thanks for reporting. This is unfortunately default behavior of Symfony container.
See related PR and discussion with same report #697 (comment)

To fix it, it would have to be fixed in Symfony first.
See issue in Symfony symfony/symfony#26713

@ghispi
Copy link
Contributor Author

ghispi commented Mar 2, 2022

@TomasVotruba I think this behavior should be highlighted in the readme.
I think it would be common case to exclude some directories which unexpectedly modifies the SetList.

ghispi added a commit to ghispi/symplify that referenced this issue Mar 2, 2022
Added information about skip option overriding setlist skips deprecated-packages#3972
TomasVotruba pushed a commit that referenced this issue Mar 5, 2022
* Update README.md

Added information about skip option overriding setlist skips #3972

* Update README.md

added info about related symfony issue symfony/symfony#26713
@ghispi
Copy link
Contributor Author

ghispi commented Mar 5, 2022

@TomasVotruba I'm looking at vendor\symplify\easy-coding-standard\vendor\symfony\dependency-injection\Loader\PhpFileLoader.php and in executeCallback which basically loads config file we have the switch which prepares arguments to inject. There is ContainerConfigurator without prefix which makes sense because it is used inside config, can we maybe remove prefix from ContainerBuilder to be able inject it to config and use to grab params to workaround the behavior?

It seems to be feasible to configure in https://github.com/symplify/symplify/blob/main/packages/easy-ci/scoper.php

@TomasVotruba
Copy link
Member

Unprefixing can lead to undesired conflicts with existing code. Also the unprefixing is not 100 % reliable, as some frameworks use annotations or string magic types for reflection-based behavior (e.g. Nette and Symfony). Saying that, we should move the other direction and introduce own "ContainerConigurator" class. See rectorphp/rector-src#1891

Yet, if you manage to come up with container builder solution, we can include it in the core here.

@deprecated-packages deprecated-packages locked as resolved and limited conversation to collaborators Jun 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants