Passed
Push — master ( 5a4455...a3a054 )
by Pol
02:30
created

Exist   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
dl 0
loc 36
ccs 17
cts 17
cp 1
rs 10
c 1
b 0
f 0
wmc 7

1 Method

Rating   Name   Duplication   Size   Complexity  
B exec() 0 28 7
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 Exist
11
{
12
    /**
13
     * @param \drupol\phpvfs\Filesystem\FilesystemInterface $vfs
14
     * @param string ...$ids
15
     *
16
     * @return bool
17
     */
18 7
    public static function exec(FilesystemInterface $vfs, string ...$ids): bool
19
    {
20 7
        $exist = true;
21
22 7
        foreach ($ids as $id) {
23 7
            $existId = true;
24 7
            $path = Path::fromString($id);
25
26
            /** @var \drupol\phpvfs\Node\DirectoryInterface $cwd */
27 7
            $cwd = $path->isAbsolute() ?
28 7
                $vfs->getCwd()->root() :
29 7
                $vfs->getCwd();
30
31 7
            foreach ($path->getIterator() as $pathPart) {
32 7
                if (\DIRECTORY_SEPARATOR === $pathPart) {
33 1
                    $existId = true;
34 7
                } elseif (null !== $child = $cwd->containsAttributeId($pathPart)) {
35 5
                    $existId = true;
36 5
                    $cwd = $child;
37
                } else {
38 7
                    $existId = false;
39
                }
40
            }
41
42 7
            $exist = $exist && $existId;
0 ignored issues
show
introduced by
The condition $existId is always true.
Loading history...
43
        }
44
45 7
        return $exist;
46
    }
47
}
48