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

Select::draw()   C

Complexity

Conditions 11
Paths 40

Size

Total Lines 48
Code Lines 36

Duplication

Lines 6
Ratio 12.5 %

Importance

Changes 0
Metric Value
cc 11
eloc 36
nc 40
nop 0
dl 6
loc 48
rs 5.2653
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
 * 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