Conditions | 14 |
Paths | 342 |
Total Lines | 128 |
Code Lines | 59 |
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 |
||
178 | public function stats() |
||
179 | { |
||
180 | $info = []; |
||
181 | // Retrieve APC Version |
||
182 | $info['version'] = phpversion('apc'); |
||
183 | $info['phpversion'] = phpversion(); |
||
184 | |||
185 | /* |
||
186 | * ======================================================== |
||
187 | * Retrieves APC's Shared Memory Allocation information |
||
188 | * ======================================================== |
||
189 | */ |
||
190 | $info['sma_info'] = []; |
||
191 | |||
192 | if (true === function_exists('apc_sma_info')) { |
||
193 | $info['sma_info'] = apc_sma_info(true); |
||
194 | |||
195 | // Calculate "APC Memory Size" (Number of Segments * Size of Segment) |
||
196 | $memsize = $info['sma_info']['num_seg'] * $info['sma_info']['seg_size']; |
||
197 | $info['sma_info']['mem_size'] = $memsize; |
||
198 | |||
199 | // Calculate "APC Memory Usage" ( mem_size - avail_mem ) |
||
200 | $memusage = $info['sma_info']['mem_size'] - $info['sma_info']['avail_mem']; |
||
201 | $info['sma_info']['mem_used'] = $memusage; |
||
202 | |||
203 | // Calculate "APC Free Memory Percentage" ( mem_size*100/mem_used ) |
||
204 | $memsize_total = $info['sma_info']['avail_mem'] * 100; |
||
205 | $avail_mem_percent = sprintf('(%.1f%%)', $memsize_total / $info['sma_info']['mem_size']); |
||
206 | $info['sma_info']['mem_avail_percentage'] = $avail_mem_percent; |
||
207 | } |
||
208 | |||
209 | if (true === function_exists('apc_cache_info')) { |
||
210 | |||
211 | // Retrieves cached information and meta-data from APC's data store |
||
212 | $info['cache_info'] = apc_cache_info(); |
||
213 | |||
214 | #\Koch\Debug\Debug::printR(apc_cache_info()); |
||
215 | $info['cache_info']['cached_files'] = count($info['cache_info']['cache_list']); |
||
216 | $info['cache_info']['deleted_files'] = count($info['cache_info']['deleted_list']); |
||
217 | |||
218 | /* |
||
219 | * ======================================================== |
||
220 | * System Cache Informations |
||
221 | * ======================================================== |
||
222 | */ |
||
223 | $info['system_cache_info'] = apc_cache_info('system', false); // set "false" for details |
||
224 | // Calculate "APC Hit Rate Percentage" |
||
225 | $hits = ($info['system_cache_info']['num_hits'] + $info['system_cache_info']['num_misses']); |
||
226 | |||
227 | // div by zero fix |
||
228 | if ($hits === 0) { |
||
229 | $hits = 1; |
||
230 | } |
||
231 | |||
232 | $hit_rate_percentage = $info['system_cache_info']['num_hits'] * 100 / $hits; |
||
233 | $info['system_cache_info']['hit_rate_percentage'] = sprintf('(%.1f%%)', $hit_rate_percentage); |
||
234 | |||
235 | // Calculate "APC Miss Rate Percentage" |
||
236 | $miss_percentage = $info['system_cache_info']['num_misses'] * 100 / $hits; |
||
237 | $info['system_cache_info']['miss_rate_percentage'] = sprintf('(%.1f%%)', $miss_percentage); |
||
238 | $info['system_cache_info']['files_cached'] = count($info['system_cache_info']['cache_list']); |
||
239 | $info['system_cache_info']['files_deleted'] = count($info['system_cache_info']['deleted_list']); |
||
240 | |||
241 | // Request Rate (hits, misses) / cache requests/second |
||
242 | $start_time = (time() - $info['system_cache_info']['start_time']); |
||
243 | |||
244 | // div by zero fix |
||
245 | if ($start_time === 0) { |
||
246 | $start_time = 1; |
||
247 | } |
||
248 | |||
249 | $rate = (($info['system_cache_info']['num_hits'] + $info['system_cache_info']['num_misses']) / $start_time); |
||
250 | $info['system_cache_info']['req_rate'] = sprintf('%.2f', $rate); |
||
251 | |||
252 | $hit_rate = ($info['system_cache_info']['num_hits']) / $start_time; |
||
253 | $info['system_cache_info']['hit_rate'] = sprintf('%.2f', $hit_rate); |
||
254 | |||
255 | $miss_rate = ($info['system_cache_info']['num_misses'] / $start_time); |
||
256 | $info['system_cache_info']['miss_rate'] = sprintf('%.2f', $miss_rate); |
||
257 | |||
258 | $insert_rate = (($info['system_cache_info']['num_inserts']) / $start_time); |
||
259 | $info['system_cache_info']['insert_rate'] = sprintf('%.2f', $insert_rate); |
||
260 | |||
261 | // size |
||
262 | if (isset($info['system_cache_info']['mem_size']) and $info['system_cache_info']['mem_size'] > 0) { |
||
263 | $info['system_cache_info']['size_files'] = Functions::getSize($info['system_cache_info']['mem_size']); |
||
264 | } else { |
||
265 | $info['system_cache_info']['size_files'] = 0; |
||
266 | } |
||
267 | } |
||
268 | |||
269 | $info['settings'] = ini_get_all('apc'); |
||
270 | |||
271 | /* |
||
272 | * ini_get_all array mod: for each accessvalue |
||
273 | * add the name of the PHP ACCESS CONSTANTS as 'accessname' |
||
274 | * @todo: cleanup? |
||
275 | */ |
||
276 | foreach ($info['settings'] as $key => $value) { |
||
277 | foreach ($value as $key2 => $value2) { |
||
278 | if ($key2 === 'access') { |
||
279 | $name = ''; |
||
280 | |||
281 | // accessvalue => constantname |
||
282 | if ($value2 === '1') { |
||
283 | $name = 'PHP_INI_USER'; |
||
284 | } |
||
285 | if ($value2 === '2') { |
||
286 | $name = 'PHP_INI_PERDIR'; |
||
287 | } |
||
288 | if ($value2 === '4') { |
||
289 | $name = 'PHP_INI_SYSTEM'; |
||
290 | } |
||
291 | if ($value2 === '7') { |
||
292 | $name = 'PHP_INI_ALL'; |
||
293 | } |
||
294 | |||
295 | // add accessname to the original array |
||
296 | $info['settings'][$key]['accessname'] = $name; |
||
297 | unset($name); |
||
298 | } |
||
299 | } |
||
300 | } |
||
301 | |||
302 | #$info['sma_info']['size_vars'] = Functions::getsize($cache_user['mem_size']); |
||
303 | |||
304 | return $info; |
||
305 | } |
||
306 | } |
||
307 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.