Upgrade a symfony 2.8 project
Question
Hello,
I'm trying to upgrade a symfony 2.8 project to a least the LTS and if it's not too difficult maybe to version 5.2.
I tried to use the last version of rector-prefixed but it was not working, as suggested by @arnaud-fr here I instaled the version 0.8.52 but it's still not working, now I have this error :

If I clear cache I only have the first error, all the next errors are similar.
This is my rector.php file :
use Rector\Core\Configuration\Option;
use Rector\Php74\Rector\Property\TypedPropertyRector;
use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
// here we can define, what sets of rules will be applied
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::SETS, [
SetList::SYMFONY_28,
// SetList::SYMFONY_30
]);
// // set paths to directories with your code
$parameters->set(Option::PATHS, [
__DIR__ . '/app',
__DIR__ . '/src',
]);
$parameters->set(Option::AUTOLOAD_PATHS, [
// autoload specific file
__DIR__ . '/app/autoload.php',
]);
// register single rule
$services = $containerConfigurator->services();
$services->set(TypedPropertyRector::class);
};
The project was running in php 7.1 in production but I'm actully running it in a php 7.2 container, I would like to also update to the lts version of php.
Am I missing something ?
Thanks for your help.
Hi,
thanks for detailed screenshots including configuration. From a quick look, you're trying to process Symfony files. Those Symfony files probably use some magic, and should be rather part of vendor (as in Symfony 3, 4...).
Personally I'd exclude them and run Rector only on your own custom code. Somethign like:
// // set paths to directories with your code
$parameters->set(Option::PATHS, [
__DIR__ . '/app/Controller',
__DIR__ . '/src',
]);
$parameters->set(Option::EXCLUDE_PATHS, [
// here put files you want to exclude from paths above
__DIR__ . '/app/Controller/SomeSymfonyClass.php',
]);
Hi,
Thank you for your reply.
I actually tried to do that and I didn’t have errors but when I ran the process, it just says OK in green, I tried with all symfony version in my rector.php and it’s the same ...
The only way to get a diff was with setlist::CODE_QUALITY
Is it a normal behavior ?
Thanks.
It usually change some code, but it depends how you run Rector on what code. Upgrading from Symfony 2.8 will take a long time, there are many blockers that you need to know of. Like PHP version with Symfony matrix, replacements of deprecated packages that don't support future PHP versions anymore, migrating from XML configs to PHP etc.
If you need fasten up the upgrade, you can contact us: https://getrector.org/contact We handle private upgrades as a services and will save you some frustrating times.