Completed
Pull Request — develop (#591)
by Alejandro
04:24
created

DeprecatedConfigParser   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 30
ccs 14
cts 14
cp 1
rs 10
c 1
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A parseNotFoundRedirect() 0 16 3
A __invoke() 0 3 1
A removeSecretKey() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shlinkio\Shlink\Core\Config;
6
7
use function Functional\compose;
8
9
class DeprecatedConfigParser
10
{
11 5
    public function __invoke(array $config): array
12
    {
13 5
        return compose([$this, 'parseNotFoundRedirect'], [$this, 'removeSecretKey'])($config);
14
    }
15
16 5
    public function parseNotFoundRedirect(array $config): array
17
    {
18
        // If the new config value is already set, keep it
19 5
        if (isset($config['not_found_redirects']['invalid_short_url'])) {
20 1
            return $config;
21
        }
22
23 4
        $oldRedirectEnabled = $config['url_shortener']['not_found_short_url']['enable_redirection'] ?? false;
24 4
        if (! $oldRedirectEnabled) {
25 2
            return $config;
26
        }
27
28 2
        $oldRedirectValue = $config['url_shortener']['not_found_short_url']['redirect_to'] ?? null;
29 2
        $config['not_found_redirects']['invalid_short_url'] = $oldRedirectValue;
30
31 2
        return $config;
32
    }
33
34 5
    public function removeSecretKey(array $config): array
35
    {
36
        // Removing secret_key from any generated config will prevent the AppOptions object from crashing
37 5
        unset($config['app_options']['secret_key']);
38 5
        return $config;
39
    }
40
}
41