Lines
0.00%
0 / 26
Functions and Methods
0.00%
0 / 6
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| ConfigurationException | 0.00% | 0 / 26 | 0.00% | 0 / 6 | 72 | 0.00% | 0 / 1 | |||
| valueInvalid | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| workerIndexOutOfRange | 0.00% | 0 / 7 | 0.00% | 0 / 1 | 2 | |||||
| appUnknown | 0.00% | 0 / 5 | 0.00% | 0 / 1 | 2 | |||||
| appSelectionUnknown | 0.00% | 0 / 5 | 0.00% | 0 / 1 | 2 | |||||
| environmentVariableUnknown | 0.00% | 0 / 5 | 0.00% | 0 / 1 | 6 | |||||
| describeKnownApps | 0.00% | 0 / 3 | 0.00% | 0 / 1 | 6 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Runtime\Exception; | |
| 6 | ||
| 7 | use Stewart\Contracts\App\AppId; | |
| 8 | use Stewart\Contracts\App\Collection\AppIdCollection; | |
| 9 | use Stewart\Contracts\Exception\StewartException; | |
| 10 | ||
| 11 | /** @extends StewartException<ConfigurationError> */ | |
| 12 | final class ConfigurationException extends StewartException | |
| 13 | { | |
| 14 | public static function valueInvalid(string $value, string $expected): self | |
| 15 | { | |
| 16 | return self::createForReason(ConfigurationError::ValueInvalid, value: $value, expected: $expected); | |
| 17 | } | |
| 18 | ||
| 19 | public static function workerIndexOutOfRange(AppId $appId, int $worker, int $workers): self | |
| 20 | { | |
| 21 | return self::createForReason( | |
| 22 | ConfigurationError::WorkerIndexOutOfRange, | |
| 23 | appId: $appId->value, | |
| 24 | worker: $worker, | |
| 25 | workers: $workers, | |
| 26 | highestIndex: $workers - 1, | |
| 27 | ); | |
| 28 | } | |
| 29 | ||
| 30 | public static function appUnknown(AppId $appId, AppIdCollection $knownAppIds): self | |
| 31 | { | |
| 32 | return self::createForReasonWithAppendedText( | |
| 33 | ConfigurationError::AppUnknown, | |
| 34 | ['appId' => $appId->value, 'knownAppIds' => $knownAppIds->toStrings()], | |
| 35 | self::describeKnownApps($knownAppIds), | |
| 36 | ); | |
| 37 | } | |
| 38 | ||
| 39 | public static function appSelectionUnknown(AppId $appId, AppIdCollection $knownAppIds): self | |
| 40 | { | |
| 41 | return self::createForReasonWithAppendedText( | |
| 42 | ConfigurationError::AppSelectionUnknown, | |
| 43 | ['appId' => $appId->value, 'knownAppIds' => $knownAppIds->toStrings()], | |
| 44 | self::describeKnownApps($knownAppIds), | |
| 45 | ); | |
| 46 | } | |
| 47 | ||
| 48 | public static function environmentVariableUnknown(string $variable, ?string $suggestion): self | |
| 49 | { | |
| 50 | return self::createForReasonWithAppendedText( | |
| 51 | ConfigurationError::EnvironmentVariableUnknown, | |
| 52 | ['variable' => $variable, 'suggestion' => $suggestion], | |
| 53 | $suggestion === null ? null : \sprintf('Did you mean %s?', $suggestion), | |
| 54 | ); | |
| 55 | } | |
| 56 | ||
| 57 | private static function describeKnownApps(AppIdCollection $knownAppIds): string | |
| 58 | { | |
| 59 | return $knownAppIds->isEmpty() | |
| 60 | ? 'No automations were found; check the #[Automation] attribute.' | |
| 61 | : 'Known automations: ' . implode(', ', $knownAppIds->toStrings()) . '.'; | |
| 62 | } | |
| 63 | } |