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

DeprecatedConfigParser::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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