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

Formatting bug for Symfony Constraints #3645

Closed
ghost opened this issue Jul 3, 2020 · 9 comments
Closed

Formatting bug for Symfony Constraints #3645

ghost opened this issue Jul 3, 2020 · 9 comments
Labels

Comments

@ghost
Copy link

ghost commented Jul 3, 2020

Bug Report

Subject Details
Rector version 0.8.x-dev@0a8bef3
Installed as docker latest image
 <?php

 use Symfony\Component\Validator\Constraints as Assert;

 class User
 {
     /**
-     * @Assert\Email(message = "email.email")
+     * @Assert\Email(message=email.email)
      */
     private $email;
 }

Expected Behaviour

Rector should not touch it.

SF 4.4 application. My rector.yaml:

services:
    Rector\Php74\Rector\Property\TypedPropertyRector:
    Rector\Php74\Rector\Property\RestoreDefaultNullToNullableTypePropertyRector:

parameters:
    auto_import_names: true
    import_short_classes: false
    autoload_paths:
        - /project/config/bootstrap.php 

Can't run demo, getting Function 'mail()' is not allowed..
Screenshot at 2020-07-03 18-09-59

@TomasVotruba
Copy link
Member

TomasVotruba commented Jul 3, 2020

Can't run demo, getting Function 'mail()' is not allowed.

That's correct. The code needs to be complete. Include it to the analysed code:

function mail() {}

@ghost
Copy link
Author

ghost commented Jul 3, 2020

Getting Fix PHP syntax wherever I put this function (inside class, outside class).

@ghost ghost changed the title Fformatting bug for Symfony Constraints Formatting bug for Symfony Constraints Jul 3, 2020
@TomasVotruba
Copy link
Member

TomasVotruba commented Jul 3, 2020

Could you share the link to that demo?

@ghost
Copy link
Author

ghost commented Jul 3, 2020

I can't. It's still /demo when I press Process. Form is filled as in the picture above.
Edit: Same after adding function mail() {};

@TomasVotruba
Copy link
Member

TomasVotruba commented Jul 3, 2020

I see...

New I remember! The @Email annotation is using mail() function, which is invoked for some reason.

If we'd allow mail() on demo, it could be exploited. Thus it's forbidden.


Just use different "safe" annotation: https://getrector.org/demo/2d619dcb-71bd-48ed-a212-8d644df3614f#result

@TomasVotruba
Copy link
Member

As for annotation formatting, there is often nothing we can do, as there is no tool to preserve format.

If the behavior doesn't change, we close it as won't fix.

@ghost
Copy link
Author

ghost commented Jul 3, 2020

Actually NotNull cannot be used as $email should be also validated with @Email. I wonder why rector even touches this line (especially with this configuration).
This will happen only with @Email annotation or there are plenty of others annotations that will couse this buggy formatting?
Can I skip this line with @Email somehow?

@TomasVotruba
Copy link
Member

TomasVotruba commented Jul 4, 2020

Actually NotNull cannot be used as $email

It can. It's not relevant for this example. It is basically "any annotation class".

Can I skip this line with @Email somehow?

The solution is to correct formatting in whole project, e.g. with some regex. Anything else will disable Rector rules.

@TomasVotruba
Copy link
Member

Related to and duplicate of #4334

TomasVotruba added a commit that referenced this issue Jun 2, 2023
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

2 participants