Completed
Push — master ( 8f1f64...1ececc )
by Alexey
04:31
created

Select   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 52
Duplicated Lines 11.54 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 6
loc 52
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
C draw() 6 48 11

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
 * Active form input select
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 Ui\ActiveForm\Input;
13
14
class Select extends \Ui\ActiveForm\Input {
15
16
  public function draw() {
17
    $inputName = $this->colName();
18
    $inputLabel = $this->colLabel();
19
    $inputParams = $this->colParams;
20
21
    $inputOptions = [
22
        'value' => $this->value(),
23
        'disabled' => $this->readOnly(),
24
        'values' => \Ui\ActiveForm::getOptionsList($this->colParams, $this->activeFormParams, $this->activeForm->modelName, $inputName)
25
    ];
26
    $modelName = '';
27
    switch ($inputParams['source']) {
28
      case 'model':
29
        $modelName = $inputParams['model'];
30
        break;
31
      case 'relation':
32
        if ($this->activeForm->modelName) {
33
          $itemModelName = $this->activeForm->modelName;
34
          $relation = $itemModelName::getRelation($inputParams['relation']);
35
          if ($relation['model'] && class_exists($relation['model'])) {
36
            $modelName = $relation['model'];
37
          }
38
        }
39
    }
40
    if (!empty($modelName)) {
41
      $inputOptions['createBtn'] = [
42
          'text' => 'Создать элемент',
43
          'onclick' => 'inji.Ui.forms.popUp(\'' . addslashes($modelName) . '\',{},function(elem){'
44
          . 'return function(data,modal){inji.Ui.forms.submitAjax($(elem).closest(\'form\')[0], {notSave: true});}}(this))'
45
      ];
46
    }
47 View Code Duplication
    if (!empty($inputOptions['values'][$this->activeForm->model->{$this->colName}]) &&
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
            is_array($inputOptions['values'][$this->activeForm->model->{$this->colName}]) &&
49
            !empty($inputOptions['values'][$this->activeForm->model->{$this->colName}]['input'])) {
50
      $aditionalCol = $inputOptions['values'][$this->activeForm->model->{$this->colName}]['input']['name'];
51
      $inputOptions['aditionalValue'] = $this->activeForm->model->$aditionalCol;
52
    }
53
54
    $preset = $this->preset();
55
56
    if ($preset !== null) {
57
      $inputOptions['disabled'] = true;
58
      $this->form->input('hidden', $inputName, '', $inputOptions);
59
      return true;
60
    }
61
    $this->form->input('select', $inputName, $inputLabel, $inputOptions);
62
    return true;
63
  }
64
65
}
66