Passed
Push — master ( 5a4455...a3a054 )
by Pol
02:30
created

Get   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 91.67%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 32
ccs 11
cts 12
cp 0.9167
rs 10
c 1
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A exec() 0 22 5
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace drupol\phpvfs\Commands;
6
7
use drupol\phpvfs\Filesystem\FilesystemInterface;
8
use drupol\phpvfs\Node\VfsInterface;
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\VfsInterface
20
     */
21 7
    public static function exec(FilesystemInterface $vfs, string $id): VfsInterface
22
    {
23 7
        $path = Path::fromString($id);
24
25
        /** @var \drupol\phpvfs\Node\DirectoryInterface $cwd */
26 7
        $cwd = $path->isAbsolute() ?
27 6
            $vfs->getCwd()->root() :
28 7
            $vfs->getCwd();
29
30 7
        foreach ($path->getIterator() as $pathPart) {
31 7
            if (null !== $child = $cwd->containsAttributeId($pathPart)) {
32 7
                $cwd = $child;
33
            } else {
34 1
                throw new \Exception('Unknown path.');
35
            }
36
        }
37
38 7
        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 7
        return $cwd;
43
    }
44
}
45