Lines 0.00% 0 / 4
Methods 0.00% 0 / 2
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 findNewName 0.00% 0 / 1 0.00% 0 / 1 2
 refuseRenamedKeys 0.00% 0 / 3 0.00% 0 / 1 12
10final 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}