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

Inspect::exec()   A

Complexity

Conditions 5
Paths 10

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 5.1158

Importance

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