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

Cd   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

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