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

Exist::exec()   B

Complexity

Conditions 7
Paths 17

Size

Total Lines 28
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 7

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 17
nc 17
nop 2
dl 0
loc 28
ccs 17
cts 17
cp 1
crap 7
rs 8.8333
c 1
b 0
f 0
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