Rector: Upgrading from Symfony 2.8 to 3.0

Created on 3 Jun 2020  路  9Comments  路  Source: rectorphp/rector

Question

I could run the prefixed version (Rector v0.7.27) as 'vendor/rector/rector-prefixed/rector process src --set symfony28 --dry-run' successfully on my v2.8 application. It went well, however if I want to move forward and upgrade to Symfony 3.0 with '--set symfony30', I get the following error message:

[ERROR] Could not process "src/project/AppBundle/Controller/DefaultController.php" file, due to: "File path "phar:///<projectDir>/vendor/rector/rector-prefixed/rector/src/Rector/AbstractRector/NameResolverTrait.php" was not found while creating "_HumbugBox3c08e8add8e1\Symplify\SmartFileSystem\SmartFileInfo" object.".

Did I miss anything?

bug

All 9 comments

Could you provide --debug output?

Is this enough?

...
    [applying] Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector
    [applying] Rector\Symfony\Rector\Form\FormTypeGetParentRector
    [applying] Rector\Symfony\Rector\HttpKernel\GetRequestRector

Fatal error: Uncaught _HumbugBox3c08e8add8e1\Symplify\SmartFileSystem\Exception\FileNotFoundException: File path "phar:///<projectDir>/vendor/rector/rector-prefixed/rector/src/Rector/AbstractRector/NameResolverTrait.php" was not found while creating "_HumbugBox3c08e8add8e1\Symplify\SmartFileSystem\SmartFileInfo" object. in phar:///<projectDir>/vendor/rector/rector-prefixed/rector/vendor/symplify/smart-file-system/src/SmartFileInfo.php:22

Stack trace:
#0 phar:///<projectDir>/vendor/rector/rector-prefixed/rector/packages/node-name-resolver/src/NodeNameResolver.php(175): _HumbugBox3c08e8add8e1\Symplify\SmartFileSystem\SmartFileInfo->__construct('phar:///<projectDir>...')
#1 phar:///<projectDir>/vendor/rector/rector-prefixed/rector/packages/node-name-resolver/src/NodeNameResolver.php(95): Rector\NodeNameResolver\NodeNameResolver->reportInvalidNodeForName(Object(PhpParser\Node\Expr\StaticCall))
#2 phar:/// in phar:///<projectDir>/vendor/rector/rector-prefixed/rector/vendor/symplify/smart-file-system/src/SmartFileInfo.php on line 22

after some trial and error, I could narrow down the issue to this code:

$serializer = SerializerBuilder::create()
    ->setMetadataDirs(array("App\\AppBundle" => realpath('/dummyfolder/dummyfile')))
    ->setMetadataDriverFactory()

after I replaced to this, rector could refactor the class

$serializer = SerializerBuilder::create();
$serializer->setMetadataDirs(array("App\\AppBundle" => realpath('/folder/file')))
    ->setMetadataDriverFactory()

hope this helps.

Where is $serializer = SerializerBuilder::create() located?

JMS\Serializer\SerializerBuilder

I'm not sure I understand. Is that code part of Rector?
Or is the code in your application that Rector fails on.

ahh, sorry, yes this is the code Rector fails on.

Got it, thanks. There were actually 2 bugs:

  • one with file location in Phar, where debug_back_trace() provided non existing path
  • the other getting a name on $method->call(), which is invalid node to get name from

Thanks so much for taking care! Great job!

Was this page helpful?
0 / 5 - 0 ratings