Conditions | 16 |
Paths | 1462 |
Total Lines | 29 |
Lines | 6 |
Ratio | 20.69 % |
Changes | 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 |
||
89 | protected function convertDateInterval(DateInterval $dateInterval) |
||
90 | { |
||
91 | $sign = $dateInterval->invert? '-' : '+'; |
||
92 | View Code Duplication | if ($dateInterval->days) { |
|
93 | return $sign . $dateInterval->days . 'DAY' . (($dateInterval->y > 1)? 'S' : ''); |
||
94 | } |
||
95 | |||
96 | $syntax = ''; |
||
97 | View Code Duplication | if ($dateInterval->y) { |
|
98 | $syntax .= $sign . $dateInterval->y . 'YEAR' . (($dateInterval->y > 1)? 'S' : ''); |
||
99 | } |
||
100 | if ($dateInterval->m) { |
||
101 | $syntax .= $sign . $dateInterval->m . 'MONTH' . (($dateInterval->m > 1)? 'S' : ''); |
||
102 | } |
||
103 | if ($dateInterval->d) { |
||
104 | $syntax .= $sign . $dateInterval->d . 'DAY' . (($dateInterval->d > 1)? 'S' : ''); |
||
105 | } |
||
106 | if ($dateInterval->h) { |
||
107 | $syntax .= $sign . $dateInterval->h . 'HOUR' . (($dateInterval->h > 1)? 'S' : ''); |
||
108 | } |
||
109 | if ($dateInterval->i) { |
||
110 | $syntax .= $sign . $dateInterval->i . 'MINUTE' . (($dateInterval->i > 1)? 'S' : ''); |
||
111 | } |
||
112 | if ($dateInterval->s) { |
||
113 | $syntax .= $sign . $dateInterval->s . 'SECOND' . (($dateInterval->s > 1)? 'S' : ''); |
||
114 | } |
||
115 | |||
116 | return $syntax; |
||
117 | } |
||
118 | } |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
integer
values, zero is a special case, in particular the following results might be unexpected: