Test Failed
Push — master ( 2a8a67...5ddd1f )
by Alexey
04:25
created

ParamsList::editor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Parser Object ParamsList
5
 *
6
 * @author Alexey Krupskiy <[email protected]>
7
 * @link http://inji.ru/
8
 * @copyright 2015 Alexey Krupskiy
9
 * @license https://github.com/injitools/cms-Inji/blob/master/LICENSE
10
 */
11
12
namespace Migrations\Parser\Object;
13
14
class ParamsList extends \Migrations\Parser {
15
16
    public function parse() {
17
        $walked = [];
18
        $params = $this->param->childs;
19
        foreach ($params as $param) {
20
            if ($this->model) {
21
                if ($param->type == 'custom') {
22
                    $parserName = $param->value;
23
                } else {
24
                    $parserName = '\Migrations\Parser\Object\\' . ucfirst($param->type);
25
                }
26
                if (is_array($this->data) && !\Tools::isAssoc($this->data)) {
27
                    foreach ($this->data as $data) {
28
                        $parser = new $parserName;
29
                        $parser->data = &$data;
30
                        $parser->param = $param;
31
                        $parser->model = $this->model;
32
                        $parser->object = $this->object;
33
                        $parser->parse();
34
                    }
35
                } else {
36
                    $parser = new $parserName;
37
                    $parser->data = &$this->data[$param->code];
38
                    $parser->param = $param;
39
                    $parser->model = $this->model;
40
                    $parser->object = $this->object;
41
                    $parser->parse();
42
                }
43
            }
44
            $walked[$param->code] = true;
45
        }
46
        //check unparsed params
47 View Code Duplication
        foreach ($this->data as $key => $data) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
            //skip parsed and attribtes
49
            if ($key == '@attributes' || !empty($walked[$key])) {
50
                continue;
51
            }
52
            $param = new \Migrations\Migration\Object\Param();
53
            $param->parent_id = $this->param->id;
54
            $param->object_id = $this->object->object->id;
55
            $param->code = $key;
56
            $param->type = 'param';
57
            $param->save();
58
        }
59
    }
60
61
    public function editor() {
62
        return [
63
            '' => 'Выберите',
64
            'param' => 'Параметр',
65
        ];
66
    }
67
68
}
69