Directory::save()   A
last analyzed

Complexity

Conditions 6
Paths 4

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 14
c 1
b 0
f 0
nc 4
nop 0
dl 0
loc 21
ccs 0
cts 18
cp 0
crap 42
rs 9.2222
1
<?php
2
/**
3
 * Automation tool mixed with code generator for easier continuous development
4
 *
5
 * @link      https://github.com/hiqdev/hidev
6
 * @package   hidev
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2018, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hidev\components;
12
13
use hidev\helpers\FileHelper;
14
use Yii;
15
16
/**
17
 * Directory manipulation component.
18
 */
19
class Directory extends File
20
{
21
    public function save()
22
    {
23
        FileHelper::mkdir($this->_path);
24
25
       foreach ($this->getItems() as $id => $config) {
26
            $type = 'Directory';
27
            if (isset($config['template']) || isset($config['copy'])) {
28
                $type = 'File';
29
            } elseif (isset($config['symlink'])) {
30
                $type = 'Symlink';
31
            }
32
            $defaults = [
33
                'class' => "hidev\\components\\$type",
34
                'path' => $this->_path . '/' . $id,
35
            ];
36
            $config = array_merge($defaults, $config ?: []);
37
            $object = Yii::createObject($config);
38
            $object->save();
39
        }
40
41
        $this->modifyFile();
42
    }
43
44
    public function load()
45
    {
46
    }
47
}
48