| Conditions | 11 |
| Paths | 19 |
| Total Lines | 51 |
| Code Lines | 40 |
| Lines | 10 |
| Ratio | 19.61 % |
| 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 |
||
| 143 | private function calculateStatistics() |
||
| 144 | { |
||
| 145 | $statistics = []; |
||
| 146 | foreach ($this->data['instances']['calls'] as $name => $calls) { |
||
| 147 | $statistics[$name] = [ |
||
| 148 | 'calls' => 0, |
||
| 149 | 'time' => 0, |
||
| 150 | 'reads' => 0, |
||
| 151 | 'writes' => 0, |
||
| 152 | 'deletes' => 0, |
||
| 153 | 'hits' => 0, |
||
| 154 | 'misses' => 0, |
||
| 155 | ]; |
||
| 156 | /** @type TraceableAdapterEvent $call */ |
||
| 157 | foreach ($calls as $call) { |
||
| 158 | $statistics[$name]['calls'] += 1; |
||
| 159 | $statistics[$name]['time'] += $call->end - $call->start; |
||
| 160 | if ('getItem' === $call->name) { |
||
| 161 | $statistics[$name]['reads'] += 1; |
||
| 162 | View Code Duplication | if ($call->hits) { |
|
| 163 | $statistics[$name]['hits'] += 1; |
||
| 164 | } else { |
||
| 165 | $statistics[$name]['misses'] += 1; |
||
| 166 | } |
||
| 167 | } elseif ('getItems' === $call->name) { |
||
| 168 | $count = $call->hits + $call->misses; |
||
| 169 | $statistics[$name]['reads'] += $count; |
||
| 170 | $statistics[$name]['hits'] += $call->hits; |
||
| 171 | $statistics[$name]['misses'] += $count - $call->misses; |
||
| 172 | } elseif ('hasItem' === $call->name) { |
||
| 173 | $statistics[$name]['reads'] += 1; |
||
| 174 | View Code Duplication | if (false === $call->result) { |
|
| 175 | $statistics[$name]['misses'] += 1; |
||
| 176 | } else { |
||
| 177 | $statistics[$name]['hits'] += 1; |
||
| 178 | } |
||
| 179 | } elseif ('save' === $call->name) { |
||
| 180 | $statistics[$name]['writes'] += 1; |
||
| 181 | } elseif ('deleteItem' === $call->name) { |
||
| 182 | $statistics[$name]['deletes'] += 1; |
||
| 183 | } |
||
| 184 | } |
||
| 185 | if ($statistics[$name]['reads']) { |
||
| 186 | $statistics[$name]['hit_read_ratio'] = round(100 * $statistics[$name]['hits'] / $statistics[$name]['reads'], 2); |
||
| 187 | } else { |
||
| 188 | $statistics[$name]['hit_read_ratio'] = null; |
||
| 189 | } |
||
| 190 | } |
||
| 191 | |||
| 192 | return $statistics; |
||
| 193 | } |
||
| 194 | |||
| 244 |