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

ParamsList   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 55
Duplicated Lines 21.82 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 12
loc 55
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
D parse() 12 44 10
A editor() 0 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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