Test Failed
Push — master ( e9a009...455e4b )
by Alexey
04:25
created

Autocomplete   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 37
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 37
loc 37
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
C draw() 33 33 8

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 search
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 View Code Duplication
class Autocomplete extends \Ui\ActiveForm\Input {
15
16
    public function draw() {
17
        $inputName = $this->colName();
18
        $inputLabel = $this->colLabel();
19
        $modelName = $this->activeForm->modelName;
20
21
        $inputOptions = [
22
            'value' => $this->value(),
23
            'disabled' => $this->readOnly(),
24
            'values' => []
25
        ];
26
        $relation = $modelName::getRelation($this->colParams['relation']);
27
        if ($relation && class_exists($relation['model']) && $inputOptions['value']) {
28
            $inputOptions['values'][$this->value()] = $relation['model']::get($inputOptions['value']);
29
        }
30
31
        if (!empty($inputOptions['values'][$this->activeForm->model->{$this->colName}]) &&
32
                is_array($inputOptions['values'][$this->activeForm->model->{$this->colName}]) &&
33
                !empty($inputOptions['values'][$this->activeForm->model->{$this->colName}]['input'])) {
34
            $aditionalCol = $inputOptions['values'][$this->activeForm->model->{$this->colName}]['input']['name'];
35
            $inputOptions['aditionalValue'] = $this->activeForm->model->$aditionalCol;
36
        }
37
38
        $preset = $this->preset();
39
40
        if ($preset !== null) {
41
            $inputOptions['disabled'] = true;
42
            $this->form->input('hidden', $inputName, '', $inputOptions);
43
            return true;
44
        }
45
        $inputOptions['inputObject'] = $this;
46
        $this->form->input('search', $inputName, $inputLabel, $inputOptions);
47
        return true;
48
    }
49
50
}
51