Completed
Push — master ( 20e2c2...b48497 )
by Pol
02:23
created

Filesystem::get()   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\Node\Directory;
8
use drupol\phpvfs\Node\DirectoryInterface;
9
use drupol\phpvfs\Node\FilesystemNodeInterface;
10
11
/**
12
 * Class Filesystem.
13
 */
14
class Filesystem implements FilesystemInterface
15
{
16
    /**
17
     * @var \drupol\phpvfs\Node\DirectoryInterface
18
     */
19
    private $cwd;
20
21
    /**
22
     * Filesystem constructor.
23
     *
24
     * @param string $id
25
     * @param array $attributes
26
     *
27
     * @throws \Exception
28
     */
29 11
    public function __construct(
30
        string $id,
31
        array $attributes = []
32
    ) {
33
        $attributes = [
34 11
            'id' => $id,
35 11
            'vfs' => $this,
36 11
        ] + $attributes;
37
38 11
        $this->cwd = Directory::create($id, $attributes);
39 11
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 1
    public static function create(string $id, array $attributes = [])
45
    {
46 1
        return new self($id, $attributes);
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 9
    public function getCwd(): DirectoryInterface
53
    {
54 9
        return $this->cwd;
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60 2
    public function root(): FilesystemNodeInterface
61
    {
62 2
        return $this->cwd->root();
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68 1
    public function setCwd(DirectoryInterface $dir)
69
    {
70 1
        $this->cwd = $dir;
71
72 1
        return $this;
73
    }
74
}
75