False Postive: Aliased PHP 8.0 Attributes on Class properties leading to "Namespaced classes/interfaces/traits should be referenced with use statements" #213
Closed this issue · 1 comments
WengerK commented
When having a class with Aliased PHP Attributes attached to properties we get the following phpcs error
Namespaced classes/interfaces/traits should be referenced with use statements
<?php
use Symfony\Component\Validator\Constraints as Assert;
/**
* Foo class description.
*/
class Foo {
#[Assert\NotBlank]
/**
* Bar property.
*
* @var bool
*/
private bool $bar;
}
This is a very commong Symfony community drive way to add assertion using a Namespace alias Assert
.
Workaround
A working workaround for now is to remove the namespace alias.
<?php
use Symfony\Component\Validator\Constraints\NotBlank;
/**
* Foo class description.
*/
class Foo {
#[NotBlank]
/**
* Bar property.
*
* @var bool
*/
private bool $bar;
}
PS : Openning related issue for missplaced Attribute before comment (see #213)
WengerK commented
Posted on drupal.org/project/coder/issues/3408527 follow-up there.