Lines 100.00% 6 / 6
Methods 100.00% 2 / 2
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 resolveMqttLink 100.00% 5 / 5 100.00% 1 / 1 3
11final 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}