Rector: [docs] upgrade to symfony 3.3 without somes rules

Created on 18 Aug 2020  路  15Comments  路  Source: rectorphp/rector

Hello,

I try to upgrade to SF 3.3, and when I run rector with tu rules symfony33, it runs somes rules I don't need or don't want : by example : the fluent class thing that remove the return $this in setters.

How can I upgrade the minimum thing needed to upgrade ?

Thank you :)

bug

All 15 comments

Hi,

what ruleset is causing this?
What exact rule is reported?

Sounds it's
Rector\MagicDisclosure\Rector\ClassMethod\ReturnThisRemoveRector
and
Rector\MagicDisclosure\Rector\MethodCall\FluentChainMethodCallToNormalMethodCallRector

They don't seem to be part of symfony33.php - https://github.com/rectorphp/rector/blob/master/config/set/symfony33.php

  • In what set are they located?
  • What is in your rector.php?
<?php

declare(strict_types=1);

use Rector\MagicDisclosure\Rector\ClassMethod\ReturnThisRemoveRector;
use Rector\MagicDisclosure\Rector\MethodCall\FluentChainMethodCallToNormalMethodCallRector;
use Rector\MagicDisclosure\Rector\MethodCall\InArgFluentChainMethodCallToStandaloneMethodCallRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Rector\Set\ValueObject\SetList;
use Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector;
use Rector\Core\Configuration\Option;
return static function (ContainerConfigurator $containerConfigurator): void {
    $parameters = $containerConfigurator->parameters();

    $parameters->set('auto_import_names', false);

    $parameters->set('import_short_classes', false);

    $parameters->set('import_doc_blocks', false);

    $parameters->set('sets', [
        SetList::PHP_72,
        SetList::SYMFONY_28,
        SetList::SYMFONY_30,
        SetList::SYMFONY_31,
        SetList::SYMFONY_32,
        SetList::SYMFONY_33,
        SetList::SYMFONY_34,
    ]);

    $parameters->set(Option::EXCLUDE_RECTORS, [
        FluentChainMethodCallToNormalMethodCallRector::class,
        ReturnThisRemoveRector::class,
        InArgFluentChainMethodCallToStandaloneMethodCallRector::class
    ]);

    $parameters->set('symfony_container_xml_path', __DIR__.'/var/cache/dev/appDevDebugProjectContainer.xml');

    $parameters->set('exclude_paths', ['app/DoctrineMigrations/*', 'app/cache/*', 'src/AmazonBundle/*', 'src/AllegroBundle/Model/ReturnPolicyAvailability.php']);

    $parameters->set('autoload_paths', [__DIR__.'/vendor/autoload.php', __DIR__.'/app/AppCache.php', __DIR__.'/app/AppKernel.php']);


};

Having the same issue with https://github.com/rectorphp/rector-prefixed
// [applying] Rector\MagicDisclosure\Rector\Return_\DefluentReturnMethodCallRector
// [applying] Rector\MagicDisclosure\Rector\MethodCall\FluentChainMethodCallToNormalMethodCallRector
// [applying] Rector\MagicDisclosure\Rector\MethodCall\MethodCallOnSetterMethodCallToStandaloneAssignRector
// [applying] Rector\MagicDisclosure\Rector\MethodCall\InArgFluentChainMethodCallToStandaloneMethodCallRector
I think these rules are applied due to the php version that you are running

@numerogeek does your script applys the symfony rules?
I have a simple config

 return static function (ContainerConfigurator $containerConfigurator): void {
    $parameters = $containerConfigurator->parameters();

    $parameters->set(Option::SETS, [SetList::SYMFONY_30]);

    $parameters->set(Option::EXCLUDE_RECTORS, [
        ReturnThisRemoveRector::class,
    ]);
};

When running vendor/rector/rector-prefixed/rector process src --config=rector.php -vvv --dry-run --debug
I don't see the of the https://github.com/rectorphp/rector/blob/master/config/set/symfony30.php rules being applyied
`

I though my code was all cleaned already 馃ぃ but maybe it doesnt run, in fact ^^

Hello @TomasVotruba ,

Could you please have a check on my rector.php config file posted above ?
I have the feeling that it doesnt take any rule of this files when I run vendor/bin/rector process src despite the fact that it shows config file : rector.php.

I am currently upgrading a symfony 3.4 project, and there is obviously some change.

Even the SetList::SYMFONY_CONSTRUCTOR_INJECTION does not return anything despite there's a lot of container thing in controllers.

Thanks !

So after many hours try trying to debug the phar(rectorphp/rector-prefixed) i finaly found my issue.
https://github.com/rectorphp/rector/blob/09f67341eeb361b2d9d00ce384bb20fe20c701d0/packages/set/src/SetProvider.php#L46 it goes into the class Symplify\SetConfigResolver\Provider\AbstractSetProvider line 37 and when doing

 // 2. path-based approach
        foreach ($this->provide() as $set) {
            if (realpath($set->getSetFileInfo()->getRealPath()) !== realpath($setName)) {
                continue;
            }

            return $set;
        }

it returns the first set it finds which happens to be defluent, because apparently when comparing both values are false because of realpath
These are what's being compared

var_dump(realpath("phar:///var/www/html/myproject/vendor/rector/rector-prefixed/rector.phar/packages/set/src/ValueObject/../../../../config/set/defluent.php")); //This rerutns false
var_dump(realpath("phar:///var/www/html/myproject/vendor/rector/rector-prefixed/rector.phar/packages/set/src/ValueObject/../../../../config/set/symfony30.php")); //This returns false

@TomasVotruba maybe this is a bug or I'm mising something on my sistem, I'm using php7.4?

@numerogeek for a workaround I use
$parameters->set(Option::SETS, ['symfony-30']); instead of
$parameters->set(Option::SETS, [SetList::SYMFONY_30]);
Maybe you can give it a try and see if it works for you too, you can try 'symfony-34' or 'symfony-33' or whichever you need but with a dash separated

This is very complex. Could you make minimal reproducible repository on GitHub with failing GitHub action?

Minimal PHP code and minimal rector config.

It would be much easier to review for me, so I could fix it sooner

Sure I will try on Monday, but its basic. I just require rector-prefixed and then run the command php vendor/.../rector.phar --config=myConfig.php
And myConfig its a standard config from the README of this repo with

 $parameters->set(Option::SETS, [
        SetList::SYMFONY_30,

    ]);

@razvantomareea

it returns the first set it finds which happens to be defluent, because apparently when comparing both values are false because of realpath These are what's being compared.

Excelent work, thank you.

I vaguelly recall the realpath fails in PHAR, so this might be used instead to make it work:

https://github.com/symplify/symplify/blob/5acded3ad852178e9ebf9790c867827cf8a63b82/packages/smart-file-system/src/SmartFileInfo.php#L112-L116

Maybe it throw exception on false too, just to be sure.

Command to show registered rules might help to better debug:

vendor/bin/rector show

This might help: #4006

The set name was used incorrectly, as symfony-33 without any report.
Now the symfony33 version is back + invalid set is reported.

image


Could you confirm current master helped?

Also #4007 will make debugging easier, mainly with merged configuratoin from multiple configs

Closing as answered and fixed in linked PRs

Was this page helpful?
0 / 5 - 0 ratings