Environment   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 39
rs 10
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A setParent() 0 3 1
A getBaseUrl() 0 3 1
A getUrlPath() 0 3 1
A getPath() 0 3 1
A getParent() 0 3 1
A joinPath() 0 3 1
1
<?php
2
3
namespace Ipag\Sdk\Core;
4
5
use Ipag\Sdk\Path\CompositePathInterface;
6
use Ipag\Sdk\Util\PathUtil;
7
use UnexpectedValueException;
8
9
abstract class Environment implements CompositePathInterface
10
{
11
    protected string $url;
12
13
    protected function __construct(string $url)
14
    {
15
        $this->url = rtrim($url, PathUtil::PATH_SEPARATOR);
16
    }
17
18
    protected function getBaseUrl(): string
19
    {
20
        return $this->url;
21
    }
22
23
    protected function getUrlPath(string $path): string
24
    {
25
        return implode(PathUtil::PATH_SEPARATOR, [$this->getBaseUrl(), ltrim($path, PathUtil::PATH_SEPARATOR)]);
26
    }
27
28
    //
29
30
    public function setParent(?CompositePathInterface $parent): void
31
    {
32
        throw new UnexpectedValueException("An environment is not supposed to have a parent path");
33
    }
34
35
    public function getParent(): ?CompositePathInterface
36
    {
37
        return null;
38
    }
39
40
    public function joinPath(string $relative): string
41
    {
42
        return $this->getUrlPath($relative);
43
    }
44
45
    public function getPath(): string
46
    {
47
        return $this->getUrlPath('');
48
    }
49
}
50