Dir   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 37
ccs 12
cts 16
cp 0.75
rs 10
c 0
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 3 1
A __construct() 0 15 4
A getValue() 0 3 1
A getPath() 0 4 1
1
<?php
2
3
namespace CompoLab\Domain\ValueObject;
4
5
final class Dir
6
{
7
    /** @var string */
8
    private $value;
9
10 6
    public function __construct(string $value)
11
    {
12 6
        if (!is_dir($value)) {
13 2
            throw new \InvalidArgumentException(sprintf('Path "%s" is not a valid directory', $value));
14
        }
15
16 4
        if (!is_readable($value)) {
17
            throw new \InvalidArgumentException(sprintf('Dir "%s" is not readable', $value));
18
        }
19
20 4
        if (!is_writable($value)) {
21
            throw new \InvalidArgumentException(sprintf('Dir "%s" is not writable', $value));
22
        }
23
24 4
        $this->value = realpath($value);
25 4
    }
26
27
    public function getValue(): string
28
    {
29
        return $this->value;
30
    }
31
32 1
    public function getPath(string $path): string
33
    {
34 1
        return realpath(
35 1
            sprintf('%s/%s', $this->value, ltrim($path, '/'))
36
        );
37
    }
38
39 4
    public function __toString()
40
    {
41 4
        return $this->value;
42
    }
43
}
44