Paths::buildPathFromArray()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 6
nop 2
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace VueGenerators;
4
5
use Illuminate\Filesystem\Filesystem;
6
7
trait Paths
8
{
9
    /**
10
     * Build directory tree from array of paths.
11
     *
12
     * @param string          $path
13
     * @param Filesystem|null $filesystem
14
     */
15
    protected function buildPathFromArray($path, Filesystem $filesystem = null)
16
    {
17
        $pathArray = collect(explode('/', $path))->prepend('resources');
18
19
        if (is_null($filesystem)) {
20
            $filesystem = new Filesystem();
21
        }
22
23
        $base = base_path();
24
25
        foreach ($pathArray as $path) {
26
            $base = $base.'/'.$path;
27
28
            if (!$filesystem->exists($base)) {
29
                $filesystem->makeDirectory($base);
30
            }
31
        }
32
    }
33
}
34