Passed
Pull Request — master (#526)
by Alejandro
06:41
created

DeprecatedConfigParser   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 23
ccs 11
cts 11
cp 1
rs 10
c 1
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parseNotFoundRedirect() 0 16 3
A __invoke() 0 3 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 4
    public function __invoke(array $config): array
12
    {
13 4
        return compose([$this, 'parseNotFoundRedirect'])($config);
14
    }
15
16 4
    public function parseNotFoundRedirect(array $config): array
17
    {
18
        // If the new config value is already set, keep it
19 4
        if (isset($config['not_found_redirects']['invalid_short_url'])) {
20 1
            return $config;
21
        }
22
23 3
        $oldRedirectEnabled = $config['url_shortener']['not_found_short_url']['enable_redirection'] ?? false;
24 3
        if (! $oldRedirectEnabled) {
25 1
            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