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

DeprecatedConfigParser::removeSecretKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
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