Lines
100.00%
2 / 2
Functions and Methods
100.00%
1 / 1
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| MultipleRecordsFoundException | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 1 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 1 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace BlueprintAU\Radiant\Exceptions; | |
| 6 | ||
| 7 | /** | |
| 8 | * Thrown by `sole()` when a query that must produce EXACTLY ONE model row | |
| 9 | * produces more than one. | |
| 10 | * | |
| 11 | * This is deliberately a different exception from | |
| 12 | * {@see ModelNotFoundException}: "too many results" is not "not found", | |
| 13 | * and callers catching one should not silently swallow the other. The | |
| 14 | * row count is carried so the message can state how many rows matched. | |
| 15 | */ | |
| 16 | final class MultipleRecordsFoundException extends \RuntimeException | |
| 17 | { | |
| 18 | /** @var int The number of rows the query matched (always >= 2). */ | |
| 19 | public readonly int $count; | |
| 20 | ||
| 21 | /** | |
| 22 | * @param int $count | |
| 23 | * @param class-string<\BlueprintAU\Radiant\Model> $modelClass | |
| 24 | */ | |
| 25 | public function __construct(int $count, string $modelClass) | |
| 26 | { | |
| 27 | $this->count = $count; | |
| 28 | ||
| 29 | parent::__construct('Query returned '.$count.' rows for model ['.$modelClass.'], expected exactly 1.'); | |
| 30 | } | |
| 31 | } |