Completed
Push — master ( 385f57...dd4a08 )
by wen
03:01
created

DateRange   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 49
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 7 7 1
A getName() 4 4 1
A getStartName() 4 4 1
A getEndName() 4 4 1
A getDefaultValue() 4 4 1
A getValue() 12 12 3

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
namespace Sco\Admin\Form\Elements;
4
5 View Code Duplication
class DateRange extends Date
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
6
{
7
    protected $type = 'daterange';
8
9
    protected $startName;
10
11
    protected $endName;
12
13
    public function __construct($startName, $endName, $title)
14
    {
15
        $this->startName = $startName;
16
        $this->endName   = $endName;
17
18
        parent::__construct('', $title);
19
    }
20
21
    public function getName()
22
    {
23
        return '';
24
    }
25
26
    public function getStartName()
27
    {
28
        return $this->startName;
29
    }
30
31
    public function getEndName()
32
    {
33
        return $this->endName;
34
    }
35
36
    public function getDefaultValue()
37
    {
38
        return [];
39
    }
40
41
    public function getValue()
42
    {
43
        $model = $this->getModel();
44
        $value = $this->getDefaultValue();
45
        if (is_null($model) || !$model->exists) {
46
            return $value;
47
        }
48
        return [
49
            $model->getAttribute($this->getStartName()),
50
            $model->getAttribute($this->getEndName()),
51
        ];
52
    }
53
}
54