Skip to content

Commit 446672d

Browse files
committed
Create InvalidEntityException to replace RuntimeException in EntityUpdater
1 parent ae3ce67 commit 446672d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace EasyCorp\Bundle\EasyAdminBundle\Exception;
4+
5+
use Symfony\Component\Validator\ConstraintViolationListInterface;
6+
7+
class InvalidEntityException extends \RuntimeException
8+
{
9+
public function __construct(
10+
public readonly ConstraintViolationListInterface $violations,
11+
) {
12+
parent::__construct((string) $this->violations);
13+
}
14+
}

src/Orm/EntityUpdater.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Orm\EntityUpdaterInterface;
66
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
7+
use EasyCorp\Bundle\EasyAdminBundle\Exception\InvalidEntityException;
78
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
89
use Symfony\Component\Validator\ConstraintViolationList;
910
use Symfony\Component\Validator\Validator\ValidatorInterface;
@@ -34,7 +35,7 @@ public function updateProperty(EntityDto $entityDto, string $propertyName, $valu
3435
/** @var ConstraintViolationList $violations */
3536
$violations = $this->validator->validate($entityInstance);
3637
if (0 < \count($violations)) {
37-
throw new \RuntimeException((string) $violations);
38+
throw new InvalidEntityException($violations);
3839
}
3940

4041
$entityDto->setInstance($entityInstance);

0 commit comments

Comments
 (0)