| Conditions | 7 |
| Paths | 8 |
| Total Lines | 23 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 22 | public function get(?string $name = null): TestTransport |
||
| 23 | { |
||
| 24 | if (0 === \count($this->transports)) { |
||
| 25 | throw new \LogicException('No transports registered.'); |
||
| 26 | } |
||
| 27 | |||
| 28 | if (null === $name && 1 !== \count($this->transports)) { |
||
| 29 | throw new \InvalidArgumentException(\sprintf('Multiple transports are registered (%s), you must specify a name.', \implode(', ', \array_keys($this->transports)))); |
||
| 30 | } |
||
| 31 | |||
| 32 | if (null === $name) { |
||
| 33 | $name = \array_key_first($this->transports); |
||
| 34 | } |
||
| 35 | |||
| 36 | if (!$transport = $this->transports[$name] ?? null) { |
||
| 37 | throw new \InvalidArgumentException("Transport \"{$name}\" not registered."); |
||
| 38 | } |
||
| 39 | |||
| 40 | if (!$transport instanceof TestTransport) { |
||
| 41 | throw new \LogicException("Transport \"{$name}\" needs to be set to \"test://\" in your test config to use this feature."); |
||
| 42 | } |
||
| 43 | |||
| 44 | return $transport; |
||
| 45 | } |
||
| 47 |