Completed
Push — master ( e6850e...e5139b )
by Pol
02:35 queued 21s
created

Exist::exec()   B

Complexity

Conditions 8
Paths 29

Size

Total Lines 30
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 8

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 8
eloc 17
nc 29
nop 2
dl 0
loc 30
ccs 18
cts 18
cp 1
crap 8
rs 8.4444
c 1
b 0
f 0
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\Utils\Path;
9
10
class Exist implements CommandInterface
11
{
12
    /**
13
     * @param \drupol\phpvfs\Filesystem\FilesystemInterface $vfs
14
     * @param string ...$ids
15
     *
16
     * @return bool
17
     */
18 8
    public static function exec(FilesystemInterface $vfs, string ...$ids): bool
19
    {
20 8
        $exist = true;
21 8
        $existId = true;
22
23 8
        foreach ($ids as $id) {
24 8
            $path = Path::fromString($id);
25
26
            /** @var \drupol\phpvfs\Node\DirectoryInterface $cwd */
27 8
            $cwd = $path->isAbsolute() ?
28 8
                $vfs->getCwd()->root() :
29 8
                $vfs->getCwd();
30
31 8
            foreach ($path->getIterator() as $pathPart) {
32 8
                $pathPartExist = false;
33
34 8
                if (\DIRECTORY_SEPARATOR === $pathPart) {
35 2
                    $pathPartExist = true;
36 8
                } elseif (null !== $child = $cwd->containsAttributeId($pathPart)) {
37 8
                    $pathPartExist = true;
38 8
                    $cwd = $child;
39
                }
40
41 8
                $existId = $existId && $pathPartExist;
0 ignored issues
show
introduced by
The condition $pathPartExist is always true.
Loading history...
42
            }
43
44 8
            $exist = $exist && $existId;
45
        }
46
47 8
        return $exist;
48
    }
49
}
50