Passed
Push — master ( de351b...604f37 )
by Pol
02:29
created

Filesystem   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 93.33%

Importance

Changes 0
Metric Value
eloc 11
c 0
b 0
f 0
dl 0
loc 55
ccs 14
cts 15
cp 0.9333
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A pwd() 0 3 1
A getCwd() 0 3 1
A setCwd() 0 5 1
A root() 0 9 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace drupol\phpvfs\Filesystem;
6
7
use drupol\phpvfs\Node\DirectoryInterface;
8
9
/**
10
 * Class Filesystem.
11
 */
12
class Filesystem implements FilesystemInterface
13
{
14
    /**
15
     * @var \drupol\phpvfs\Node\DirectoryInterface
16
     */
17
    private $cwd;
18
19
    /**
20
     * Filesystem constructor.
21
     *
22
     * @param \drupol\phpvfs\Node\DirectoryInterface $directory
23
     */
24 16
    public function __construct(DirectoryInterface $directory)
25
    {
26 16
        $this->cwd = $directory;
27 16
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 14
    public function getCwd(): DirectoryInterface
33
    {
34 14
        return $this->cwd;
35
    }
36
37
    /**
38
     * @return string
39
     */
40 4
    public function pwd(): string
41
    {
42 4
        return (string) $this->getCwd()->getPath();
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 2
    public function root(): DirectoryInterface
49
    {
50 2
        $root = $this->getCwd()->root();
51
52 2
        if ($root instanceof DirectoryInterface) {
53 2
            return $root;
54
        }
55
56
        throw new \Exception('Unable to get root directory.');
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62 2
    public function setCwd(DirectoryInterface $dir)
63
    {
64 2
        $this->cwd = $dir;
65
66 2
        return $this;
67
    }
68
}
69