Completed
Push — master ( e6850e...e5139b )
by Pol
02:35 queued 21s
created

Get::exec()   A

Complexity

Conditions 5
Paths 10

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 5.0144

Importance

Changes 0
Metric Value
cc 5
eloc 12
nc 10
nop 2
dl 0
loc 22
ccs 11
cts 12
cp 0.9167
crap 5.0144
rs 9.5555
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace drupol\phpvfs\Command;
6
7
use drupol\phpvfs\Filesystem\FilesystemInterface;
8
use drupol\phpvfs\Node\FilesystemNodeInterface;
9
use drupol\phpvfs\Utils\Path;
10
11
class Get
12
{
13
    /**
14
     * @param \drupol\phpvfs\Filesystem\FilesystemInterface $vfs
15
     * @param string $id
16
     *
17
     *@throws \Exception
18
     *
19
     * @return \drupol\phpvfs\Node\FilesystemNodeInterface
20
     */
21 8
    public static function exec(FilesystemInterface $vfs, string $id): FilesystemNodeInterface
22
    {
23 8
        $path = Path::fromString($id);
24
25
        /** @var \drupol\phpvfs\Node\DirectoryInterface $cwd */
26 8
        $cwd = $path->isAbsolute() ?
27 7
            $vfs->getCwd()->root() :
28 8
            $vfs->getCwd();
29
30 8
        foreach ($path->getIterator() as $pathPart) {
31 8
            if (null !== $child = $cwd->containsAttributeId($pathPart)) {
32 8
                $cwd = $child;
33
            } else {
34 1
                throw new \Exception('Unknown path.');
35
            }
36
        }
37
38 8
        if (null === $cwd) {
0 ignored issues
show
introduced by
The condition null === $cwd is always false.
Loading history...
39
            throw new \Exception('TODO');
40
        }
41
42 8
        return $cwd;
43
    }
44
}
45