Passed
Push — master ( a3920c...49b830 )
by Sebastian
01:58
created

Directory::create()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 2
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
ccs 0
cts 5
cp 0
crap 12
1
<?php
2
/**
3
 * This file is part of Camino.
4
 *
5
 * (c) Sebastian Feldmann <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace SebastianFeldmann\Camino\Path;
11
12
use RuntimeException;
13
14
/**
15
 * Class Directory
16
 *
17
 * @package SebastianFeldmann\Camino
18
 */
19
final class Directory extends Base
20
{
21
    /**
22
     * Checks if the directory is a sub directory of a given directory
23
     *
24
     * @param  \SebastianFeldmann\Camino\Path\Directory $parent
25
     * @return bool
26
     */
27 2
    public function isSubDirectoryOf(Directory $parent): bool
28
    {
29 2
        return $this->isChildOf($parent);
30
    }
31
32
    /**
33
     * Factory method to create directories that actually exist
34
     *
35
     * @param  string $path
36
     * @return \SebastianFeldmann\Camino\Path\Directory
37
     */
38
    public static function create(string $path): Directory
39
    {
40
        $realPath = realpath($path);
41
        if (empty($realPath) || is_file($realPath)) {
42
            throw new RuntimeException('directory does not exist: ' . $path);
43
        }
44
        return new self($realPath);
45
    }
46
}
47