Directory::create()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 4
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 7
rs 10
ccs 5
cts 5
cp 1
crap 3
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 3
    public static function create(string $path): Directory
39
    {
40 3
        $realPath = realpath($path);
41 3
        if (empty($realPath) || is_file($realPath)) {
42 2
            throw new RuntimeException('directory does not exist: ' . $path);
43
        }
44 1
        return new self($realPath);
45
    }
46
}
47