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

Directory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 25
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getFullSubpathAsString() 0 3 1
A asString() 0 3 1
A __construct() 0 4 1
A ensureIsDirectory() 0 4 2
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