| Total Complexity | 8 |
| Total Lines | 59 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 18 | class ExceptionCollection extends \Exception implements \IteratorAggregate, \Countable, HttpCacheException |
||
| 19 | { |
||
| 20 | private $exceptions = []; |
||
| 21 | |||
| 22 | 40 | public function __construct(array $exceptions = []) |
|
| 23 | { |
||
| 24 | 40 | foreach ($exceptions as $exception) { |
|
| 25 | 1 | $this->add($exception); |
|
| 26 | } |
||
| 27 | 40 | } |
|
| 28 | |||
| 29 | /** |
||
| 30 | * Add an exception to the collection. |
||
| 31 | * |
||
| 32 | * @return $this |
||
| 33 | */ |
||
| 34 | 8 | public function add(\Exception $e) |
|
| 35 | { |
||
| 36 | 8 | if (!$this->message) { |
|
| 37 | 8 | $this->message = $e->getMessage(); |
|
| 38 | } |
||
| 39 | |||
| 40 | 8 | $this->exceptions[] = $e; |
|
| 41 | |||
| 42 | 8 | return $this; |
|
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Get first exception in collection or null, if there is none. |
||
| 47 | * |
||
| 48 | * @return \Exception|null |
||
| 49 | */ |
||
| 50 | 7 | public function getFirst() |
|
| 51 | { |
||
| 52 | 7 | if ($this->count() > 0) { |
|
| 53 | 7 | return $this->exceptions[0]; |
|
| 54 | } |
||
| 55 | 1 | } |
|
| 56 | |||
| 57 | /** |
||
| 58 | * Get exception iterator. |
||
| 59 | * |
||
| 60 | * @return \ArrayIterator |
||
| 61 | */ |
||
| 62 | #[\ReturnTypeWillChange] |
||
| 63 | 3 | public function getIterator() |
|
| 64 | { |
||
| 65 | 3 | return new \ArrayIterator($this->exceptions); |
|
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Get number of exceptions in collection. |
||
| 70 | * |
||
| 71 | * @return int |
||
| 72 | */ |
||
| 73 | #[\ReturnTypeWillChange] |
||
| 77 | } |
||
| 78 | } |
||
| 79 |