Passed
Push — master ( 81e780...d41685 )
by Mariano
03:19 queued 27s
created

Directory::ensureIsDirectory()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Mcustiel\Phiremock\Server\Utils\Config;
4
5
class Directory
6
{
7
    /** @var string */
8
    private $directory;
9
10
    public function __construct(string $directory)
11
    {
12
        $this->ensureIsDirectory($directory);
13
        $this->directory = rtrim($directory, \DIRECTORY_SEPARATOR);
14
    }
15
16
    public function asString(): string
17
    {
18
        return $this->directory;
19
    }
20
21
    public function getFullSubpathAsString(string $subPath): string
22
    {
23
        return $this->directory . \DIRECTORY_SEPARATOR . $subPath;
24
    }
25
26
    private function ensureIsDirectory(string $directory): void
27
    {
28
        if (!is_dir($directory)) {
29
            throw new \InvalidArgumentException(sprintf('"%s" is not a directory or is not accessible.', $directory));
30
        }
31
    }
32
}
33