Completed
Push — master ( b56cdf...6bc14a )
by Pol
02:20
created

Inspect::exec()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 10
c 1
b 0
f 0
nc 6
nop 2
dl 0
loc 18
ccs 10
cts 10
cp 1
crap 4
rs 9.9332
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 2
    public static function exec(FilesystemInterface $vfs, string $id)
21
    {
22 2
        $path = Path::fromString($id);
23
24
        /** @var \drupol\phpvfs\Node\DirectoryInterface $cwd */
25 2
        $cwd = $path->isAbsolute() ?
26 2
            $vfs->getCwd()->root() :
27 2
            $vfs->getCwd();
28
29 2
        foreach ($path->getIterator() as $pathPart) {
30 2
            if (null !== $child = $cwd->containsAttributeId($pathPart)) {
31 2
                $cwd = $child;
32
            } else {
33 1
                throw new \Exception('Unknown path.');
34
            }
35
        }
36
37 2
        return \get_class($cwd);
38
    }
39
}
40