Closed ili101 closed 10 months ago
Hi, good morning.
I think I can achieve this case
#[Assert\NotBlank]
but, due to the nature of Attributes in PHP it'd be far far from perfect. Things like
#[Attribute(Attribute::TARGET_CLASS_CONSTANT|Attribute::TARGET_PROPERTY)]
won't be really doable as the contents of the Attributes, when parsed, are treated like "strings". So, the parser wouldn't know if "Attribute::TARGET_PROPERTY " is a class constante (though it obviously seems to) or just a string you use to mark your code. The same happens with
#[Test]
Is it a class? A "tag"? We would've to do a lot of magic to try to guess what is a class and what's not inside an attribute.
While I think about it I'd recommend disabling "OrderAndRemoveUseClauses" and enabling "OnlyOrderUseClauses".
Any though about this would be appreciated :)
Hi thank you I added the workaround to .vscode/settings.json for now
"phpfmt.exclude": [
"OrderAndRemoveUseClauses"
],
"phpfmt.passes": [
"OnlyOrderUseClauses"
],
I didn't understand why you say that the same happens with #[Test]
, for example this has no problem, the "use" isn't removed
<?php
namespace App\Entity;
use Symfony\Component\Validator\Constraints\Ip as AssertIp;
class Author
{
#[AssertIp]
public string $name;
}
I now see it's probably not related to attributes but actually any "use" of something that you then use only its child, this "use" also getting removed:
<?php
namespace App\Entity;
use Symfony\Component\Validator\Constraints;
new Constraints\Ip();
Hi @ili101 I've uploaded a patch, not a perfect one but it'd be good. May you please check?
I'll the other case you mention.
As far as I see both examples are working correctly now (:
Before:
After:
Example from: https://symfony.com/doc/current/validation.html#the-basics-of-validation