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

Cannot declare class - Level symfony 34 throws an error on 2.8 Symfony Code #985

Closed
theovach opened this issue Jan 24, 2019 · 9 comments
Closed
Labels

Comments

@theovach
Copy link

When I try to dry run with level symfony 3.4 on 2.8 code I get every time:
PHP v7.2.14
rector v0.3.37
PHP Fatal error: Cannot declare class Symfony\Component\HttpFoundation\ParameterBag, because the name is already in use in /var/www/html/adb_webapp/var/bootstrap.php.cache on line 6

@TomasVotruba
Copy link
Member

How did you install Rector?

What exact command do you run?

This might be due to conflicting version of Symfony. Rector uses Symfony 3.4/4.2, your app probably older.

@theovach
Copy link
Author

Installed via
composer require rector/rector --dev
Symfony is 3.4.21

@TomasVotruba
Copy link
Member

What exact Rector command do you run?

@theovach
Copy link
Author

theovach commented Jan 29, 2019

What exact Rector command do you run?

./rector process {SYMFONY_PROJECT_FOLDER}/src --level symfony34 --dry-run

@TomasVotruba
Copy link
Member

This issues is quite common. It's caused by the fact Rector loads Symfony coce from your project and from itself - twice.

The only solution in the future will be prefixed PHAR. It's being worked on in https://github.com/rectorphp/compiler
Any help there would make it sooner.

@TomasVotruba
Copy link
Member

Duplicated issue to better described: #177

@TomasVotruba
Copy link
Member

There is a solution now: https://github.com/rectorphp/rector-prefixed

@tuc0w
Copy link

tuc0w commented Feb 28, 2020

@TomasVotruba I am using the latest prefixed version (0.7.2) in a Symfony 3.4 project and I am running the two sets 'php72' and 'symfony40'.

Fatal error: Cannot declare class XXXX\YYYYBundle\Entity\Xyz, because the name is already in use in /vagrant/yyyy/src/XXXX/YYYYBundle/Entity/Xyz.php on line 14

# rector.yaml
parameters:
    auto_import_names: true
    autoload_paths:
        - 'src/zzz/DrunkenWizardBundle'
        - 'src/zzz/OfficeOpenXmlBundle'
    exclude_paths:
        - '/src/zzz/OfficeOpenXmlBundle/Classes'
    paths:
        - 'src'
    sets:
        - 'php72'
        - 'symfony40'

Any idea why it is still happening?

@TomasVotruba
Copy link
Member

Could you provide demo link?

https://getrector.org/demo

TomasVotruba added a commit that referenced this issue Oct 10, 2021
rectorphp/rector-src@f6d0037 [TypeDeclaration] Skip nullable generic typed on ReturnTypeDeclarationRector (#985)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants