Conditions | 16 |
Paths | 210 |
Total Lines | 49 |
Code Lines | 24 |
Lines | 22 |
Ratio | 44.9 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
80 | public function getEventData(\DateTime $start_date, \DateTime $end_date, $unit_ids) { |
||
81 | |||
82 | $dayfile = (array)json_decode(file_get_contents($this->day_file)); |
||
83 | $hourfile = (array)json_decode(file_get_contents($this->hour_file)); |
||
84 | $minutefile = (array)json_decode(file_get_contents($this->minute_file)); |
||
85 | |||
86 | $events = array(); |
||
87 | |||
88 | // Cycle through day results and setup an event array |
||
89 | foreach ($dayfile as $unit_id => $row) { |
||
90 | foreach ($row as $year => $row2) { |
||
91 | foreach ($row2 as $month => $row3) { |
||
92 | foreach ($row3 as $day => $value) { |
||
93 | $events[$unit_id][Event::BAT_DAY][$year][$month][$day] = $value; |
||
94 | } |
||
95 | } |
||
96 | } |
||
97 | } |
||
98 | |||
99 | // With the day events taken care off let's cycle through hours |
||
100 | View Code Duplication | foreach ($hourfile as $unit_id => $row) { |
|
101 | foreach ($row as $year => $row2) { |
||
102 | foreach ($row2 as $month => $row3) { |
||
103 | foreach ($row3 as $day => $row4) { |
||
104 | foreach ($row4 as $hour => $value) { |
||
105 | $events[$unit_id][Event::BAT_HOUR][$year][$month][$day][$hour] = $value; |
||
106 | } |
||
107 | } |
||
108 | } |
||
109 | } |
||
110 | } |
||
111 | |||
112 | // With the hour events taken care off let's cycle through minutes |
||
113 | foreach ($hourfile as $unit_id => $row) { |
||
114 | View Code Duplication | foreach ($row as $year => $row2) { |
|
115 | foreach ($row2 as $month => $row3) { |
||
116 | foreach ($row3 as $day => $row4) { |
||
117 | foreach ($row4 as $hour => $row5) { |
||
118 | foreach ((array)$row5 as $min => $value) { |
||
119 | $events[$unit_id][Event::BAT_MINUTE][$year][$month][$day][$hour][$min] = $value; |
||
120 | } |
||
121 | } |
||
122 | } |
||
123 | } |
||
124 | } |
||
125 | } |
||
126 | |||
127 | return $events; |
||
128 | } |
||
129 | |||
178 |
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.