Completed
Push — master ( 2f7f6c...a88bdd )
by Alexey
05:49
created

Option   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 85
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A relations() 18 18 1
A beforeSave() 6 6 2

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
 * Item option
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 Ecommerce\Item\Offer;
13
14 View Code Duplication
class Option extends \Model
15
{
16
    public static $objectName = 'Свойство предложения';
17
    public static $cols = [
18
        //Основные параметры
19
        'name' => ['type' => 'text'],
20
        'filter_name' => ['type' => 'text'],
21
        'image_file_id' => ['type' => 'image'],
22
        'code' => ['type' => 'text'],
23
        'type' => ['type' => 'text'],
24
        'postfix' => ['type' => 'text'],
25
        'default_val' => ['type' => 'text'],
26
        'view' => ['type' => 'bool'],
27
        'searchable' => ['type' => 'bool'],
28
        //Системные
29
        'weight' => ['type' => 'number'],
30
        'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'],
31
        'advance' => ['type' => 'text'],
32
        'date_create' => ['type' => 'dateTime'],
33
        //Менеджеры
34
        'item' => ['type' => 'dataManager', 'relation' => 'items'],
35
    ];
36
    public static $labels = [
37
        'name' => 'Название',
38
        'filter_name' => 'Название в фильтре',
39
        'image_file_id' => 'Иконка',
40
        'code' => 'Код',
41
        'type' => 'Тип',
42
        'postfix' => 'Постфикс',
43
        'default_val' => 'Значение по умолчанию',
44
        'view' => 'Отображается',
45
        'searchable' => 'Используется при поиске',
46
        'weight' => 'Вес сортировки',
47
        'advance' => 'Дополнительные параметры',
48
        'user_id' => 'Создатель',
49
        'date_create' => 'Дата создания',
50
        'item' => 'Значения для списка'
51
    ];
52
    public static $dataManagers = [
53
        'manager' => [
54
            'name' => 'Свойства предложения',
55
            'cols' => [
56
                'name', 'code', 'type', 'item', 'view', 'searchable', 'user_id', 'date_create'
57
            ]
58
        ]
59
    ];
60
    public static $forms = [
61
        'manager' => [
62
            'map' => [
63
                ['name', 'filter_name'],
64
                ['code', 'type', 'image_file_id'],
65
                ['default_val', 'postfix'],
66
                ['view', 'searchable'],
67
                ['item']
68
            ]
69
        ]
70
    ];
71
72
    public static function relations()
73
    {
74
        return [
75
            'user' => [
76
                'model' => 'Users\User',
77
                'col' => 'user_id'
78
            ],
79
            'items' => [
80
                'type' => 'many',
81
                'model' => 'Ecommerce\Item\Offer\Option\Item',
82
                'col' => 'item_offer_option_id'
83
            ],
84
            'image' => [
85
                'model' => 'Files\File',
86
                'col' => 'image_file_id'
87
            ],
88
        ];
89
    }
90
91
    public function beforeSave()
92
    {
93
        if (!isset($this->id)) {
94
            $this->user_id = \Users\User::$cur->id;
95
        }
96
    }
97
98
}
99