Lines 0.00% 0 / 30
Methods 0.00% 0 / 1
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 messageTemplate 0.00% 0 / 30 0.00% 0 / 1 930
9enum ConfigurationError: string implements ExceptionReason
10{
11    case SchemaViolation = 'schema_violation';
12    case ConfigFileMissing = 'config_file_missing';
13    case ConfigFileUnparsable = 'config_file_unparsable';
14    case ConfigFileNotAMap = 'config_file_not_a_map';
15    case ValueInvalid = 'value_invalid';
16    case KeyInvalid = 'key_invalid';
17    case KeyParseFailed = 'key_parse_failed';
18    case DurationTooShort = 'duration_too_short';
19    case DurationTooLong = 'duration_too_long';
20    case MaxDelayBelowInitialDelay = 'max_delay_below_initial_delay';
21    case RestartWindowTooShort = 'restart_window_too_short';
22    case HomeAssistantMissing = 'home_assistant_missing';
23    case PlaceholderUnset = 'placeholder_unset';
24    case ControlTokenMissing = 'control_token_missing';
25    case AdminTokenMissing = 'admin_token_missing';
26    case HttpListenAddressShared = 'http_listen_address_shared';
27    case GeneratedNamespaceAmbiguous = 'generated_namespace_ambiguous';
28    case WorkerIndexOutOfRange = 'worker_index_out_of_range';
29    case AppSelectionUnknown = 'app_selection_unknown';
30    case OptionsConflict = 'options_conflict';
31    case KeyRenamed = 'key_renamed';
32    case EnvironmentVariableUnknown = 'environment_variable_unknown';
33    case EnvironmentVariableTooDeep = 'environment_variable_too_deep';
34    case EnvironmentVariableNamesSection = 'environment_variable_names_section';
35    case EnvironmentValueInvalid = 'environment_value_invalid';
36    case EnvironmentValueUnparsable = 'environment_value_unparsable';
37    case EnvironmentVariableConflict = 'environment_variable_conflict';
38    case EnvironmentSecretFileUnreadable = 'environment_secret_file_unreadable';
39    case MqttPackageMissing = 'mqtt_package_missing';
40
41    public function messageTemplate(): string
42    {
43        return match ($this) {
44            self::SchemaViolation => '{cause}',
45            self::ConfigFileMissing => 'Config file {path} not found.',
46            self::ConfigFileUnparsable => 'Could not parse {path}: {cause}',
47            self::ConfigFileNotAMap => '{path} holds {actualType}; expected a map of settings.',
48            self::ValueInvalid => '"{value}" is not {expected}.',
49            self::KeyInvalid => '{path} must be {expected}.',
50            self::KeyParseFailed => '{path} is invalid: {cause}',
51            self::DurationTooShort => '{path} is {value}; expected at least {minimum}.',
52            self::DurationTooLong => '{path} is {value}; expected at most {maximum}.',
53            self::MaxDelayBelowInitialDelay => '{path} is {value}; expected at least {initialDelayPath} ({initialDelay}).',
54            self::RestartWindowTooShort => 'supervision.restart_window is {window}, but the backoff for restart_attempts ({attempts}) adds up to {backoffTotal}, so a crash-looping worker is never quarantined.',
55            self::HomeAssistantMissing => 'home_assistant is not configured. Set STEWART_HOME_ASSISTANT__URL and STEWART_HOME_ASSISTANT__TOKEN.',
56            self::PlaceholderUnset => '{setting} refers to ${{variable}}, which is not set. Set it or add a default: ${{variable}:-value}.',
57            self::ControlTokenMissing => 'control.token is required while control.listen is set; set STEWART_CONTROL__TOKEN or set control.listen to "off".',
58            self::AdminTokenMissing => 'http.admin.token is required while http.admin.listen is set; set STEWART_HTTP__ADMIN__TOKEN or set http.admin.listen to "off".',
59            self::GeneratedNamespaceAmbiguous => 'composer.json maps {namespaces} to {directory}/; set codegen.namespace to the one the generated classes use.',
60            self::HttpListenAddressShared => '{setting} ({address}) and {otherSetting} ({otherAddress}) use the same port; give each HTTP listener a port of its own.',
61            self::WorkerIndexOutOfRange => 'App "{appId}" is pinned to worker {worker}, but the highest worker index is {highestIndex}.',
62            self::AppSelectionUnknown => '{option} names app "{appId}", but no automation has that ID.',
63            self::OptionsConflict => '{option} cannot be combined with {conflicting}.',
64            self::KeyRenamed => '{setting} was renamed to {renamedTo}.',
65            self::EnvironmentVariableUnknown => '{variable} is not a Stewart setting; run `stewart config:reference` for all options.',
66            self::EnvironmentVariableTooDeep => '{variable} is deeper than the configuration; {valuePath} is a value, not a section.',
67            self::EnvironmentVariableNamesSection => '{variable} names a section; set the keys under it, such as {variable}{separator}KEY.',
68            self::EnvironmentValueInvalid => '{variable} is "{raw}"; expected {expected}.',
69            self::EnvironmentValueUnparsable => '{variable} is not a valid inline list or map: {cause}',
70            self::EnvironmentVariableConflict => '{variable} and {otherVariable} both set {valuePath}; keep one.',
71            self::EnvironmentSecretFileUnreadable => '{variable} points to {path}, which cannot be read.',
72            self::MqttPackageMissing => 'mqtt.url is set, but the MQTT client is not installed; run `composer require stewart-php/mqtt`.',
73        };
74    }
75}