Lines 0.00% 0 / 6
Methods 0.00% 0 / 1
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 messageTemplate 0.00% 0 / 6 0.00% 0 / 1 42
7enum MqttError: string implements ExceptionReason
8{
9    case TopicInvalid = 'mqtt_topic_invalid';
10    case PayloadUnencodable = 'mqtt_payload_unencodable';
11    case PayloadNotJson = 'mqtt_payload_not_json';
12    case NotConfigured = 'mqtt_not_configured';
13    case PublishFailed = 'mqtt_publish_failed';
14
15    public function messageTemplate(): string
16    {
17        return match ($this) {
18            self::TopicInvalid => 'MQTT topic {topic} must be non-empty UTF-8, free of +, # and NUL characters.',
19            self::PayloadUnencodable => 'MQTT payload for {topic} cannot be encoded as JSON: {cause}',
20            self::PayloadNotJson => 'MQTT payload on {topic} is not valid JSON: {cause}',
21            self::NotConfigured => 'MQTT is not configured; set mqtt.url in stewart.yaml or STEWART_MQTT__URL in .env.',
22            self::PublishFailed => 'Could not hand the MQTT message for {topic} to the broker: {cause}',
23        };
24    }
25}