Conditions | 13 |
Paths | 11 |
Total Lines | 14 |
Code Lines | 8 |
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 |
||
7 | public function replaceDates($obj, $reset = true) { |
||
8 | //prevent infinite recursion, only process each object once |
||
9 | if ($this->checkCache($obj, $reset) == false) return $obj; |
||
10 | |||
11 | if (is_array($obj) || (is_object($obj) && ($obj instanceof \Iterator))) foreach ($obj as &$o) $o = $this->replaceDates($o, false); |
||
12 | if (is_string($obj) && isset($obj[0]) && is_numeric($obj[0]) && strlen($obj) <= 20) { |
||
13 | try { |
||
14 | $date = new \DateTime($obj); |
||
15 | if ($date->format('Y-m-d H:i:s') == substr($obj, 0, 20) || $date->format('Y-m-d') == substr($obj, 0, 10)) $obj = $date; |
||
16 | } |
||
17 | catch (\Exception $e) { //Doesn't need to do anything as the try/catch is working out whether $obj is a date |
||
18 | } |
||
19 | } |
||
20 | return $obj; |
||
21 | } |
||
32 |