Conditions | 11 |
Paths | 40 |
Total Lines | 28 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
99 | public function setValue($value) |
||
100 | { |
||
101 | $startValue = $this->startValue; |
||
102 | $endValue = $this->endValue; |
||
103 | |||
104 | if (is_array($value)) { |
||
105 | if (isset($value[0])) { |
||
106 | $startValue = $value[0]; |
||
107 | } |
||
108 | if (isset($value[1])) { |
||
109 | $endValue = $value[1]; |
||
110 | } |
||
111 | } else { |
||
112 | $startValue = $value; |
||
113 | } |
||
114 | |||
115 | if (!empty($startValue) && !($startValue instanceof \DateTime)) { |
||
116 | $startValue = new \DateTime($startValue); |
||
117 | } |
||
118 | if (!empty($endValue) && !($endValue instanceof \DateTime)) { |
||
119 | $endValue = new \DateTime($endValue); |
||
120 | } |
||
121 | |||
122 | $this->startValue = $startValue; |
||
123 | $this->endValue = $endValue; |
||
124 | if ($this->started) { |
||
125 | $this->start->addAttributes(['value' => (!empty($startValue) ? $startValue->format($this->inputFormat) : null)]); |
||
126 | $this->end->addAttributes(['value' => (!empty($endValue) ? $endValue->format($this->inputFormat) : null)]); |
||
127 | } |
||
144 |