Skip to content

Mark overriden ERROR_NAMES from \Symfony\Component\Validator\Constraint as used #224

@ruudk

Description

@ruudk

When creating Symfony Validator constraints, like this:

final class Phone extends Constraint
{
    public const string PHONE_NUMBER_INVALID = 'b4093308-a26b-41cb-8248-5ec6583c77bf';
    public string $message = 'The phone number "%phone%" is not valid';
    public bool $allowEmpty = false;

    /**
     * @var array<string, string>
     */
    protected const array ERROR_NAMES = [
        self::PHONE_NUMBER_INVALID => 'PHONE_NUMBER_INVALID',
    ];

    #[Override]
    public function validatedBy() : string
    {
        return PhoneValidator::class;
    }
}

It complains that the ERORR_NAMES constant is not used. But it's part of the parent Constraint contract.

abstract class Constraint
{
    /**
     * Maps error codes to the names of their constants.
     *
     * @var array<string, string>
     */
    protected const ERROR_NAMES = [];
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions