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 |
||
134 | private function calculateStatistics() |
||
135 | { |
||
136 | $statistics = []; |
||
137 | foreach ($this->data['instances']['calls'] as $name => $calls) { |
||
138 | $statistics[$name] = [ |
||
139 | 'calls' => 0, |
||
140 | 'time' => 0, |
||
141 | 'reads' => 0, |
||
142 | 'writes' => 0, |
||
143 | 'deletes' => 0, |
||
144 | 'hits' => 0, |
||
145 | 'misses' => 0, |
||
146 | ]; |
||
147 | /** @type TraceableAdapterEvent $call */ |
||
148 | foreach ($calls as $call) { |
||
149 | $statistics[$name]['calls'] += 1; |
||
150 | $statistics[$name]['time'] += $call->end - $call->start; |
||
151 | if ('getItem' === $call->name) { |
||
152 | $statistics[$name]['reads'] += 1; |
||
153 | View Code Duplication | if ($call->hits) { |
|
154 | $statistics[$name]['hits'] += 1; |
||
155 | } else { |
||
156 | $statistics[$name]['misses'] += 1; |
||
157 | } |
||
158 | } elseif ('getItems' === $call->name) { |
||
159 | $count = $call->hits + $call->misses; |
||
160 | $statistics[$name]['reads'] += $count; |
||
161 | $statistics[$name]['hits'] += $call->hits; |
||
162 | $statistics[$name]['misses'] += $count - $call->misses; |
||
163 | } elseif ('hasItem' === $call->name) { |
||
164 | $statistics[$name]['reads'] += 1; |
||
165 | View Code Duplication | if (false === $call->result) { |
|
166 | $statistics[$name]['misses'] += 1; |
||
167 | } else { |
||
168 | $statistics[$name]['hits'] += 1; |
||
169 | } |
||
170 | } elseif ('save' === $call->name) { |
||
171 | $statistics[$name]['writes'] += 1; |
||
172 | } elseif ('deleteItem' === $call->name) { |
||
173 | $statistics[$name]['deletes'] += 1; |
||
174 | } |
||
175 | } |
||
176 | if ($statistics[$name]['reads']) { |
||
177 | $statistics[$name]['hit_read_ratio'] = round(100 * $statistics[$name]['hits'] / $statistics[$name]['reads'], 2); |
||
178 | } else { |
||
179 | $statistics[$name]['hit_read_ratio'] = null; |
||
180 | } |
||
181 | } |
||
182 | |||
183 | return $statistics; |
||
184 | } |
||
185 | |||
235 |