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

Inspect   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 28
ccs 10
cts 10
cp 1
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A exec() 0 18 4
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