| Total Complexity | 4 | 
| Total Lines | 43 | 
| Duplicated Lines | 0 % | 
| Coverage | 0% | 
| Changes | 1 | ||
| Bugs | 0 | Features | 0 | 
| 1 | <?php declare(strict_types=1); | ||
| 20 | final class InvalidEntityException extends BadRequestException | ||
| 21 | { | ||
| 22 | |||
| 23 | /** | ||
| 24 | * Throws the exception if the given entity isn't valid | ||
| 25 | * | ||
| 26 | * @param object $entity | ||
| 27 | * @param ValidatorInterface $validator | ||
| 28 | * | ||
| 29 | * @return void | ||
| 30 | * | ||
| 31 | * @throws self | ||
| 32 | */ | ||
| 33 | public static function assert(object $entity, ValidatorInterface $validator) : void | ||
| 34 |     { | ||
| 35 | $violations = self::convertViolationsToArray($validator->validate($entity)); | ||
| 36 |         if ([] === $violations) { | ||
| 37 | return; | ||
| 38 | } | ||
| 39 | |||
| 40 |         throw new self('Invalid Entity ' . get_class($entity), [ | ||
| 41 | 'violations' => $violations, | ||
| 42 | ]); | ||
| 43 | } | ||
| 44 | |||
| 45 | /** | ||
| 46 | * Converts the given violation list object to array | ||
| 47 | * | ||
| 48 | * @param ConstraintViolationListInterface $violations | ||
| 49 | * | ||
| 50 | * @return array | ||
| 51 | */ | ||
| 52 | private static function convertViolationsToArray(ConstraintViolationListInterface $violations) : array | ||
| 63 | } | ||
| 64 | } | ||
| 65 |