Completed
Push — master ( d6f21c...ed26ae )
by Pol
02:31
created

Get   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 10
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\Node\FilesystemNodeInterface;
9
use drupol\phpvfs\Utils\Path;
10
11
class Get
12
{
13
    /**
14
     * @param \drupol\phpvfs\Filesystem\FilesystemInterface $vfs
15
     * @param string $id
16
     *
17
     *@throws \Exception
18
     *
19
     * @return \drupol\phpvfs\Node\FilesystemNodeInterface
20
     */
21 9
    public static function exec(FilesystemInterface $vfs, string $id): FilesystemNodeInterface
22
    {
23 9
        if (!Exist::exec($vfs, $id)) {
24 1
            throw new \Exception(\sprintf('Unknown path %s.', $id));
25
        }
26
27 9
        $path = Path::fromString($id);
28
29
        /** @var \drupol\phpvfs\Node\DirectoryInterface $cwd */
30 9
        $child = $path->isAbsolute() ?
31 8
            $vfs->getCwd()->root() :
32 9
            $vfs->getCwd();
33
34 9
        foreach ($path->getIterator() as $pathPart) {
35 9
            $child = $child->containsAttributeId($pathPart);
0 ignored issues
show
Bug introduced by
The method containsAttributeId() does not exist on drupol\phpvfs\Node\FilesystemNodeInterface. It seems like you code against a sub-type of drupol\phpvfs\Node\FilesystemNodeInterface such as drupol\phpvfs\Node\DirectoryInterface or drupol\phpvfs\Node\Directory. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

35
            /** @scrutinizer ignore-call */ 
36
            $child = $child->containsAttributeId($pathPart);
Loading history...
36
        }
37
38 9
        return $child;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $child could return the type null which is incompatible with the type-hinted return drupol\phpvfs\Node\FilesystemNodeInterface. Consider adding an additional type-check to rule them out.
Loading history...
39
    }
40
}
41