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

ParamsList::parse()   D

Complexity

Conditions 10
Paths 18

Size

Total Lines 44
Code Lines 34

Duplication

Lines 12
Ratio 27.27 %

Importance

Changes 0
Metric Value
cc 10
eloc 34
nc 18
nop 0
dl 12
loc 44
rs 4.8196
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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