Directory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 26
rs 10
ccs 7
cts 7
cp 1
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isSubDirectoryOf() 0 3 1
A create() 0 7 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