File   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 36
rs 10
c 1
b 0
f 0
ccs 9
cts 9
cp 1
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDirectory() 0 3 1
A isInDirectory() 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 File
16
 *
17
 * @package SebastianFeldmann\Camino
18
 */
19
final class File extends Base
20
{
21
    /**
22
     * Returns a directory instance of its location
23
     *
24
     * @return \SebastianFeldmann\Camino\Path\Directory
25
     */
26 1
    public function getDirectory(): Directory
27
    {
28 1
        return new Directory(dirname($this->raw));
29
    }
30
31
    /**
32
     * Is the file located in a given directory
33
     *
34
     * @param  \SebastianFeldmann\Camino\Path\Directory $directory
35
     * @return bool
36
     */
37 2
    public function isInDirectory(Directory $directory): bool
38
    {
39 2
        return $this->isChildOf($directory);
40
    }
41
42
    /**
43
     * Factory method to create files that actually exist
44
     *
45
     * @param  string $path
46
     * @return \SebastianFeldmann\Camino\Path\File
47
     */
48 3
    public static function create(string $path): File
49
    {
50 3
        $realPath = realpath($path);
51 3
        if (empty($realPath) || is_dir($realPath)) {
52 2
            throw new RuntimeException('file does not exist: ' . $path);
53
        }
54 1
        return new self($realPath);
55
    }
56
}
57