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

Get   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 32
ccs 11
cts 12
cp 0.9167
rs 10
c 0
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\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