Question from the Symfony 6 test

Check if an article has errors in Symfony

Easy
// src/Entity/Article.php
namespace App\Entity;

use Symfony\Component\Validator\Constraints as Assert;

class Article
{
    /**
     * @Assert\NotBlank
     */
    private $name;
}

use App\Entity\Article;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Validator\ValidatorInterface;

public function author(ValidatorInterface $validator)
{
    $article = new Article();
    $validation = $validator->validate($article);
}

How can i check that $article has errors?

Author: MounirStatus: Published(Update)Question passed 20 times
Edit
0
Community Evaluations
developer avatar
Ahmed
13/11/2024
Only count(validation) > 0 is correct