Passed
Push — master ( 79d87e...9ca7ac )
by Alexey
05:33
created

Date   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 28
loc 28
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B draw() 25 25 4

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 date
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 Date extends \Ui\ActiveForm\Input {
15
16
    public function draw() {
17
        $inputName = $this->colName();
18
        $inputLabel = $this->colLabel();
19
20
        $inputOptions = $this->options;
21
        if (!empty($inputOptions['minDate'])) {
22
            if (strpos($inputOptions['minDate'], 'col:') === 0) {
23
                $colName = substr($inputOptions['minDate'], 4);
24
                $inputOptions['minDate'] = $this->activeForm->model->{$colName};
25
            }
26
        }
27
        $inputOptions['value'] = $this->value();
28
        $inputOptions['disabled'] = $this->readOnly();
29
30
        $preset = $this->preset();
31
        if ($preset !== null) {
32
            $inputOptions['disabled'] = true;
33
            $this->form->input('hidden', $inputName, '', $inputOptions);
34
            return true;
35
        }
36
        $classPath = explode('\\', get_called_class());
37
        $inputType = lcfirst(array_pop($classPath));
38
        $this->form->input($inputType, $inputName, $inputLabel, $inputOptions);
39
        return true;
40
    }
41
}