PHP

PHP

Made by DeepSource

Attribute class cannot target class constants PHP-W1005

Bug risk
Critical

The referenced Attribute class does not target class constants. This issue will be raised if a class constant is marked with an attribute that does not have the Attribute::TARGET_CLASS_CONSTANT property.

Bad practice

#[Attribute(Attribute::TARGET_CLASS)]
class Setup {}

class CopyFile
{
    #[Setup] // invalid: "Setup" cannot target class constants
    private const SET = 1;
}

Recommended

#[Attribute(Attribute::TARGET_CLASS_CONSTANT)]
class Setup {}

class CopyFile
{
    #[Setup]
    private const SET = 1;
}

References