Completed
Push — master ( b2aa64...db9a1b )
by Alexey
05:01
created

ParamsList   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 60
Duplicated Lines 20 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 10
c 2
b 1
f 0
lcom 1
cbo 3
dl 12
loc 60
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
C parse() 12 48 9
A editor() 0 7 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
    {
18
        $walked = [];
19
        $params = \Migrations\Migration\Object\Param::getList(['where'=>[
20
                    ['parent_id', $this->param->id],
21
                    ['object_id', $this->object->object->id],
22
        ]]);
23
        foreach ($params as $param) {
24
            if ($this->model) {
25
                if ($param->type == 'custom') {
26
                    $parserName = $param->value;
27
                } else {
28
                    $parserName = '\Migrations\Parser\Object\\' . ucfirst($param->type);
29
                }
30
                if (!\Tools::isAssoc($this->data)) {
31
                    foreach ($this->data as $data) {
32
                        $parser = new $parserName;
33
                        $parser->data = &$data;
34
                        $parser->param = $param;
35
                        $parser->model = $this->model;
36
                        $parser->object = $this->object;
37
                        $parser->parse();
38
                    }
39
                } else {
40
                    $parser = new $parserName;
41
                    $parser->data = &$this->data[$param->code];
42
                    $parser->param = $param;
43
                    $parser->model = $this->model;
44
                    $parser->object = $this->object;
45
                    $parser->parse();
46
                }
47
            }
48
            $walked[$param->code] = true;
49
        }
50
        //check unparsed params
51 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...
52
            //skip parsed and attribtes
53
            if ($key == '@attributes' || !empty($walked[$key])) {
54
                continue;
55
            }
56
            $param = new \Migrations\Migration\Object\Param();
57
            $param->parent_id = $this->param->id;
58
            $param->object_id = $this->object->object->id;
59
            $param->code = $key;
60
            $param->type = 'param';
61
            $param->save();
62
        }
63
    }
64
65
    public function editor()
66
    {
67
        return [
68
            '' => 'Выберите',
69
            'param' => 'Параметр',
70
        ];
71
    }
72
73
}
74