BasePathPrefixer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 11
dl 0
loc 25
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A prefixPathsWithBasePath() 0 9 2
A __invoke() 0 10 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shlinkio\Shlink\Core\Config;
6
7
use function Functional\map;
8
9
class BasePathPrefixer
10
{
11
    private const ELEMENTS_WITH_PATH = ['routes', 'middleware_pipeline'];
12
13 3
    public function __invoke(array $config): array
14
    {
15 3
        $basePath = $config['router']['base_path'] ?? '';
16 3
        $config['url_shortener']['domain']['hostname'] .= $basePath;
17
18 3
        foreach (self::ELEMENTS_WITH_PATH as $configKey) {
19 3
            $config[$configKey] = $this->prefixPathsWithBasePath($configKey, $config, $basePath);
20
        }
21
22 3
        return $config;
23
    }
24
25 3
    private function prefixPathsWithBasePath(string $configKey, array $config, string $basePath): array
26
    {
27
        return map($config[$configKey] ?? [], function (array $element) use ($basePath) {
28 1
            if (! isset($element['path'])) {
29 1
                return $element;
30
            }
31
32 1
            $element['path'] = $basePath . $element['path'];
33 1
            return $element;
34 3
        });
35
    }
36
}
37