File::getValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace CompoLab\Domain\ValueObject;
4
5
final class File
6
{
7
    /** @var string */
8
    private $value;
9
10 7
    public function __construct(string $value)
11
    {
12 7
        if (!is_file($value)) {
13 2
            throw new \InvalidArgumentException(sprintf('Path "%s" is not a valid file', $value));
14
        }
15
16 5
        if (!is_readable($value)) {
17
            throw new \InvalidArgumentException(sprintf('File "%s" is not readable', $value));
18
        }
19
20 5
        if (!is_writable($value)) {
21
            throw new \InvalidArgumentException(sprintf('File "%s" is not writable', $value));
22
        }
23
24 5
        $this->value = realpath($value);
25 5
    }
26
27
    public function getValue(): string
28
    {
29
        return $this->value;
30
    }
31
32 4
    public function __toString()
33
    {
34 4
        return $this->value;
35
    }
36
}
37