Completed
Push — master ( 2ef162...4c389f )
by Pol
02:28
created

Filesystem::inspect()   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 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace drupol\phpvfs\Filesystem;
6
7
use drupol\phpvfs\Command\Cd;
8
use drupol\phpvfs\Command\Exist;
9
use drupol\phpvfs\Command\Get;
10
use drupol\phpvfs\Command\Touch;
11
use drupol\phpvfs\Node\Directory;
12
use drupol\phpvfs\Node\DirectoryInterface;
13
use drupol\phpvfs\Node\FilesystemNodeInterface;
14
15
class Filesystem implements FilesystemInterface
16
{
17
    /**
18
     * @var \drupol\phpvfs\Node\DirectoryInterface
19
     */
20
    private $cwd;
21
22
    /**
23
     * Filesystem constructor.
24
     *
25
     * @param string $id
26
     * @param array $attributes
27
     *
28
     * @throws \Exception
29
     */
30 15
    public function __construct(
31
        string $id,
32
        array $attributes = []
33
    ) {
34
        $attributes = [
35 15
            'id' => $id,
36 15
            'vfs' => $this,
37 15
        ] + $attributes;
38
39 15
        $this->cwd = Directory::create($id, $attributes);
40 15
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 1
    public function cd(string $id)
46
    {
47 1
        Cd::exec($this, $id);
48
49 1
        return $this;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 1
    public static function create(string $id, array $attributes = [])
56
    {
57 1
        return new self($id, $attributes);
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63 3
    public function exist(string $id): bool
64
    {
65 3
        return Exist::exec($this, $id);
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71 8
    public function get(string $id): ?FilesystemNodeInterface
72
    {
73 8
        return Get::exec($this, $id);
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79 13
    public function getCwd(): DirectoryInterface
80
    {
81 13
        return $this->cwd;
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     */
87 2
    public function root(): FilesystemNodeInterface
88
    {
89 2
        return $this->cwd->root();
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95 3
    public function setCwd(DirectoryInterface $dir)
96
    {
97 3
        $this->cwd = $dir;
98
99 3
        return $this;
100
    }
101
102
    /**
103
     * {@inheritdoc}
104
     */
105 1
    public function touch(string $id)
106
    {
107 1
        Touch::exec($this, $id);
108
109 1
        return $this;
110
    }
111
}
112