Skip to content

[Validator] Add hasViolation method to ConstraintViolationListInterface #33230

@ismail1432

Description

@ismail1432

I know that is not the PR of the century but I would like to add an helper to check if a ConstraintViolationList contains or not violation.

At the moment we have to do this to check if ConstraintViolationList has some errors,

if (0 !== count($violations)) {

This is what is done in doc and Api Platform and I would like to replace it by

if($violations->hasViolation())

It's better to reading and easier to be implemented with IDE autocompletion for newcomers that are not familiar with the Validator API

To avoid BC break I would like to target Symfony 5.
I will update documentation if code is merged.

WDYT ?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions