Lines 0.00% 0 / 27
Methods 0.00% 0 / 1
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 messageTemplate 0.00% 0 / 27 0.00% 0 / 1 756
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 WorkerIndexOutOfRange = 'worker_index_out_of_range';
27    case AppUnknown = 'app_unknown';
28    case AppSelectionUnknown = 'app_selection_unknown';
29    case EnvironmentVariableUnknown = 'environment_variable_unknown';
30    case EnvironmentVariableTooDeep = 'environment_variable_too_deep';
31    case EnvironmentVariableNamesSection = 'environment_variable_names_section';
32    case EnvironmentValueInvalid = 'environment_value_invalid';
33    case EnvironmentValueUnparsable = 'environment_value_unparsable';
34    case EnvironmentVariableConflict = 'environment_variable_conflict';
35    case EnvironmentSecretFileUnreadable = 'environment_secret_file_unreadable';
36    case MqttPackageMissing = 'mqtt_package_missing';
37
38    public function messageTemplate(): string
39    {
40        return match ($this) {
41            self::SchemaViolation => '{cause}',
42            self::ConfigFileMissing => 'Config file {path} not found.',
43            self::ConfigFileUnparsable => 'Could not parse {path}: {cause}',
44            self::ConfigFileNotAMap => '{path} holds {actualType}; expected a map of settings.',
45            self::ValueInvalid => '"{value}" is not {expected}.',
46            self::KeyInvalid => '{path} must be {expected}.',
47            self::KeyParseFailed => '{path} is invalid: {cause}',
48            self::DurationTooShort => '{path} is {value}; expected at least {minimum}.',
49            self::DurationTooLong => '{path} is {value}; expected at most {maximum}.',
50            self::MaxDelayBelowInitialDelay => '{path} is {value}; expected at least {initialDelayPath} ({initialDelay}).',
51            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.',
52            self::HomeAssistantMissing => 'home_assistant is not configured. Set STEWART_HOME_ASSISTANT__URL and STEWART_HOME_ASSISTANT__TOKEN.',
53            self::PlaceholderUnset => '{setting} refers to ${{variable}}, which is not set. Set it or add a default: ${{variable}:-value}.',
54            self::ControlTokenMissing => 'control.token is required while control.listen is set; set STEWART_CONTROL__TOKEN or set control.listen to "off".',
55            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".',
56            self::WorkerIndexOutOfRange => 'App "{appId}" is pinned to worker {worker}, but the highest worker index is {highestIndex}.',
57            self::AppUnknown => 'stewart.yaml configures app "{appId}", but no automation has that ID.',
58            self::AppSelectionUnknown => '--only names app "{appId}", but no automation has that ID.',
59            self::EnvironmentVariableUnknown => '{variable} is not a Stewart setting; run `stewart config:reference` for all options.',
60            self::EnvironmentVariableTooDeep => '{variable} is deeper than the configuration; {valuePath} is a value, not a section.',
61            self::EnvironmentVariableNamesSection => '{variable} names a section; set the keys under it, such as {variable}{separator}KEY.',
62            self::EnvironmentValueInvalid => '{variable} is "{raw}"; expected {expected}.',
63            self::EnvironmentValueUnparsable => '{variable} is not a valid inline list or map: {cause}',
64            self::EnvironmentVariableConflict => '{variable} and {otherVariable} both set {valuePath}; keep one.',
65            self::EnvironmentSecretFileUnreadable => '{variable} points to {path}, which cannot be read.',
66            self::MqttPackageMissing => 'mqtt.url is set, but the MQTT client is not installed; run `composer require stewart-php/mqtt`.',
67        };
68    }
69}