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

Directory::isSubDirectoryOf()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
ccs 2
cts 2
cp 1
crap 1
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