Lines
100.00%
9 / 9
Methods
100.00%
2 / 2
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 6 / 6 | 100.00% | 1 / 1 | 2 | ||
| renderKey | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 2 | ||
| 25 | final class ModelNotFoundException extends \RuntimeException | |
| 26 | { | |
| 27 | /** | |
| 28 | * The class-string of the model that had no matching row. | |
| 29 | * | |
| 30 | * @var class-string<\BlueprintAU\Radiant\Model> | |
| 31 | */ | |
| 32 | public readonly string $model; | |
| 33 | ||
| 34 | /** | |
| 35 | * The key used for the lookup: null when no key was involved, a scalar | |
| 36 | * or a composite column map otherwise. | |
| 37 | * | |
| 38 | * @var KeyValue | |
| 39 | */ | |
| 40 | public readonly int|string|null|array $key; | |
| 41 | ||
| 42 | /** | |
| 43 | * @param class-string<\BlueprintAU\Radiant\Model> $modelClass | |
| 44 | * @param KeyValue $key Null when no key was involved; a scalar or a column => value map otherwise. | |
| 45 | */ | |
| 46 | public function __construct(string $modelClass, int|string|null|array $key = null) | |
| 47 | { | |
| 48 | $this->model = $modelClass; | |
| 49 | $this->key = $key; | |
| 50 | ||
| 51 | $message = 'No query results for model ['.$modelClass.']'; | |
| 52 | ||
| 53 | if ($key !== null) { | |
| 54 | $message .= ' '.self::renderKey($key); | |
| 55 | } | |
| 56 | ||
| 57 | parent::__construct($message.'.'); | |
| 58 | } | |
| 59 | ||
| 60 | /** | |
| 61 | * Renders the lookup key for the exception message. | |
| 62 | * | |
| 63 | * @param KeyValue $key | |
| 64 | * @return string | |
| 65 | */ | |
| 66 | private static function renderKey(int|string|null|array $key): string | |
| 67 | { | |
| 68 | if (\is_array($key)) { | |
| 69 | return (string) json_encode($key); | |
| 70 | } | |
| 71 | ||
| 72 | return (string) $key; | |
| 73 | } | |
| 74 | } |