| Conditions | 5 |
| Paths | 8 |
| Total Lines | 26 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 14 |
| CRAP Score | 5 |
| Changes | 0 | ||
| 1 | <?php |
||
| 21 | 2 | public static function exec(FilesystemInterface $vfs, string $id): DirectoryInterface |
|
| 22 | { |
||
| 23 | 2 | $path = Path::fromString($id); |
|
| 24 | |||
| 25 | /** @var \drupol\phpvfs\Node\DirectoryInterface $cwd */ |
||
| 26 | 2 | $cwd = $path->isAbsolute() ? |
|
| 27 | 2 | $vfs->getCwd()->root() : |
|
| 28 | 2 | $vfs->getCwd(); |
|
| 29 | |||
| 30 | 2 | if ($path->isRoot()) { |
|
| 31 | 1 | $vfs->setCwd($cwd); |
|
| 32 | |||
| 33 | 1 | return $cwd; |
|
| 34 | } |
||
| 35 | |||
| 36 | 2 | foreach ($path->getIterator() as $pathPart) { |
|
| 37 | 2 | if (null !== $child = $cwd->containsAttributeId($pathPart)) { |
|
| 38 | 1 | $cwd = $child; |
|
| 39 | } else { |
||
| 40 | 1 | throw new \Exception('Unknown directory.'); |
|
| 41 | } |
||
| 42 | } |
||
| 43 | |||
| 44 | 1 | $vfs->setCwd($cwd); |
|
| 45 | |||
| 46 | 1 | return $cwd; |
|
|
|
|||
| 47 | } |
||
| 49 |