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

Exist   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B exec() 0 30 8
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