Passed
Push — master ( 84c32b...3332dd )
by Pol
02:08
created

Cd::exec()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 8
c 1
b 0
f 0
nc 6
nop 2
dl 0
loc 16
ccs 9
cts 9
cp 1
crap 4
rs 10
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\Utils\Path;
9
10
class Cd
11
{
12
    /**
13
     * @param \drupol\phpvfs\Filesystem\FilesystemInterface $vfs
14
     * @param string $id
15
     */
16 1
    public static function exec(FilesystemInterface $vfs, string $id)
17
    {
18 1
        $path = Path::fromString($id);
19
20
        /** @var \drupol\phpvfs\Node\DirectoryInterface $cwd */
21 1
        $cwd = $path->isAbsolute() ?
22 1
            $vfs->getCwd()->root() :
23 1
            $vfs->getCwd();
24
25 1
        foreach ($path->getIterator() as $pathPart) {
26 1
            if (null !== $child = $cwd->containsAttributeId($pathPart)) {
27 1
                $cwd = $child;
28
            }
29
        }
30
31 1
        $vfs->setCwd($cwd);
32 1
    }
33
}
34