Passed
Push — master ( 72f8f4...a05bce )
by Jesús
07:47 queued 11s
created

WithSuffixAbsolutePathStrategy   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 19
c 0
b 0
f 0
dl 0
loc 36
ccs 18
cts 18
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A generateAbsolutePath() 0 22 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Framework\Config\PathNormalizer;
6
7
final class WithSuffixAbsolutePathStrategy implements AbsolutePathStrategyInterface
8
{
9
    private string $appRootDir;
10
11
    private string $configFileNameSuffix;
12
13 28
    public function __construct(
14
        string $appRootDir,
15
        string $configFileNameSuffix = ''
16
    ) {
17 28
        $this->appRootDir = $appRootDir;
18 28
        $this->configFileNameSuffix = $configFileNameSuffix;
19 28
    }
20
21 28
    public function generateAbsolutePath(string $relativePath): string
22
    {
23 28
        $suffix = $this->configFileNameSuffix;
24 28
        if ($suffix === '') {
25 24
            return '';
26
        }
27
28
        // place the file suffix right before the file extension
29 4
        $dotPos = strpos($relativePath, '.');
30
31 4
        if ($dotPos !== false) {
32 3
            $relativePathWithFileSuffix = substr($relativePath, 0, $dotPos)
33 3
                . '-' . $suffix
34 3
                . substr($relativePath, $dotPos);
35
        } else {
36 1
            $relativePathWithFileSuffix = $relativePath . '-' . $suffix;
37
        }
38
39 4
        return sprintf(
40 4
            '%s/%s',
41 4
            rtrim($this->appRootDir, '/'),
42 4
            ltrim($relativePathWithFileSuffix, '/')
43
        );
44
    }
45
}
46