Lines
0.00%
0 / 4
Functions and Methods
0.00%
0 / 2
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| RenamedSettings | 0.00% | 0 / 4 | 0.00% | 0 / 2 | 20 | 0.00% | 0 / 1 | |||
| findNewName | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| refuseRenamedKeys | 0.00% | 0 / 3 | 0.00% | 0 / 1 | 12 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Runtime\Config; | |
| 6 | ||
| 7 | use Stewart\Runtime\Exception\ConfigurationError; | |
| 8 | use Stewart\Runtime\Exception\ConfigurationException; | |
| 9 | ||
| 10 | final readonly class RenamedSettings | |
| 11 | { | |
| 12 | private const array NEW_NAMES_BY_OLD_NAME = ['service_calls' => 'ha_calls']; | |
| 13 | ||
| 14 | public function findNewName(string $topLevelKey): ?string | |
| 15 | { | |
| 16 | return self::NEW_NAMES_BY_OLD_NAME[$topLevelKey] ?? null; | |
| 17 | } | |
| 18 | ||
| 19 | /** | |
| 20 | * @param array<array-key, mixed> $fileConfig | |
| 21 | * @throws ConfigurationException | |
| 22 | */ | |
| 23 | public function refuseRenamedKeys(array $fileConfig): void | |
| 24 | { | |
| 25 | foreach (self::NEW_NAMES_BY_OLD_NAME as $oldName => $newName) { | |
| 26 | if (\array_key_exists($oldName, $fileConfig)) { | |
| 27 | throw ConfigurationException::createForReason(ConfigurationError::KeyRenamed, setting: $oldName, renamedTo: $newName); | |
| 28 | } | |
| 29 | } | |
| 30 | } | |
| 31 | } |