PathResolver   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A obtainPath() 0 8 2
A setRelativePath() 0 3 1
A getRelativePath() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
namespace EaselDrawing\Templates;
4
5
class PathResolver
6
{
7
    /** @var string */
8
    private $relativePath;
9
10
    public function __construct(string $relativePath = '')
11
    {
12
        $this->relativePath = $relativePath;
13
    }
14
15
    public function getRelativePath(): string
16
    {
17
        return $this->relativePath;
18
    }
19
20
    public function setRelativePath(string $relativePath)
21
    {
22
        $this->relativePath = '/' . trim($relativePath, '/');
23
    }
24
25
    public function obtainPath($location): string
26
    {
27
        if (substr($location, 0, 1) === '/') {
28
            // this is an absolute path
29
            return $location;
30
        }
31
        // complete relative path
32
        return $this->getRelativePath() . '/' . $location;
33
    }
34
}
35