for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types = 1);
/**
* /src/Exception/ValidatorException.php
*
* @author TLe, Tarmo Leppänen <[email protected]>
*/
namespace App\Exception;
use App\Exception\interfaces\ClientErrorInterface;
use App\Exception\models\ValidatorError;
use App\Utils\JSON;
use JsonException;
use Symfony\Component\Validator\ConstraintViolationInterface;
use Symfony\Component\Validator\ConstraintViolationListInterface;
use Symfony\Component\Validator\Exception\ValidatorException as BaseValidatorException;
use function array_map;
use function iterator_to_array;
* Class ValidatorException
* @package App\Exception
class ValidatorException extends BaseValidatorException implements ClientErrorInterface
{
* @throws JsonException
public function __construct(string $target, ConstraintViolationListInterface $errors)
parent::__construct(
JSON::encode(
array_map(
static fn (ConstraintViolationInterface $error): ValidatorError =>
new ValidatorError($error, $target),
iterator_to_array($errors),
),
);
}
public function getStatusCode(): int
return 400;