Skip to content

[Validator] way to detect extra field violation #16452

Closed
@blanchonvincent

Description

@blanchonvincent

Hey,

I'm looking a way to detect extra field violation from a violation list.
Currently, when I got a violation list, the only way I found to detect them is :

$constraintViolationList = ...;
foreach ($constraintViolationList as $violation) {
    if (
        Collection::NO_SUCH_FIELD_ERROR === $violation->getCode() &&
        $violation->getMessage() === "This field was not expected."
    ) {
        // this is an extra field
    }
}

Comparison with string is pretty dirty :/

Am I missing something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions