Lines
100.00%
6 / 6
Functions and Methods
100.00%
2 / 2
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| MqttLinkResolver | 100.00% | 6 / 6 | 100.00% | 2 / 2 | 4 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| resolveMqttLink | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 3 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Runtime\Broker\Mqtt; | |
| 6 | ||
| 7 | use Stewart\Runtime\Config\StewartConfig; | |
| 8 | use Stewart\Runtime\Exception\ConfigurationError; | |
| 9 | use Stewart\Runtime\Exception\ConfigurationException; | |
| 10 | ||
| 11 | final readonly class MqttLinkResolver | |
| 12 | { | |
| 13 | public function __construct( | |
| 14 | private StewartConfig $config, | |
| 15 | private DisabledMqttLink $disabledLink, | |
| 16 | private ?MqttLinkFactory $mqttLinkFactory = null, | |
| 17 | ) {} | |
| 18 | ||
| 19 | /** @throws ConfigurationException */ | |
| 20 | public function resolveMqttLink(): MqttLink | |
| 21 | { | |
| 22 | if ($this->config->mqtt === null) { | |
| 23 | return $this->disabledLink; | |
| 24 | } | |
| 25 | ||
| 26 | if ($this->mqttLinkFactory === null) { | |
| 27 | throw ConfigurationException::createForReason(ConfigurationError::MqttPackageMissing); | |
| 28 | } | |
| 29 | ||
| 30 | return $this->mqttLinkFactory->createMqttLink($this->config->mqtt); | |
| 31 | } | |
| 32 | } |