| Conditions | 5 |
| Paths | 16 |
| Total Lines | 55 |
| Code Lines | 46 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 94 | function drush_opcache_status() { |
||
| 95 | $opcache = new OPCache(); |
||
| 96 | $table = array(); |
||
| 97 | $status = json_decode($opcache->drushStatus()); |
||
| 98 | |||
| 99 | drush_print('Summary:'); |
||
| 100 | $table[] = array('ENABLED', 'CACHE FULL', 'RESTART PENDING', 'RESTART IN PROGRESS'); |
||
| 101 | $table[] = array( |
||
| 102 | ($status->opcache_enabled) ? 'YES' : 'NO', |
||
| 103 | ($status->cache_full) ? 'YES' : 'NO', |
||
| 104 | ($status->restart_pending) ? 'YES' : 'NO', |
||
| 105 | ($status->restart_in_progress) ? 'YES' : 'NO', |
||
| 106 | ); |
||
| 107 | drush_print_table($table, TRUE); |
||
| 108 | |||
| 109 | $table = array(); |
||
| 110 | drush_print('Memory Usage:'); |
||
| 111 | $table[] = array('USED', 'FREE', 'WASTED', 'WASTED %'); |
||
| 112 | $table[] = array( |
||
| 113 | drush_format_size($status->memory_usage->used_memory), |
||
| 114 | drush_format_size($status->memory_usage->free_memory), |
||
| 115 | drush_format_size($status->memory_usage->wasted_memory), |
||
| 116 | round($status->memory_usage->current_wasted_percentage) . '%', |
||
| 117 | ); |
||
| 118 | drush_print_table($table, TRUE); |
||
| 119 | |||
| 120 | $table = array(); |
||
| 121 | drush_print('Interned Strings Usage:'); |
||
| 122 | $table[] = array('BUFFER SIZE', 'USED MEMORY', 'FREE MEMORY', 'NUMBER OF STRINGS'); |
||
| 123 | $table[] = array( |
||
| 124 | drush_format_size($status->interned_strings_usage->buffer_size), |
||
| 125 | drush_format_size($status->interned_strings_usage->used_memory), |
||
| 126 | drush_format_size($status->interned_strings_usage->free_memory), |
||
| 127 | $status->interned_strings_usage->number_of_strings, |
||
| 128 | ); |
||
| 129 | drush_print_table($table, TRUE); |
||
| 130 | |||
| 131 | $table = array(); |
||
| 132 | drush_print('Statistics:'); |
||
| 133 | $table[] = array('Number of Cached Scripts', $status->opcache_statistics->num_cached_scripts); |
||
| 134 | $table[] = array('Number of Cached Keys', $status->opcache_statistics->num_cached_keys); |
||
| 135 | $table[] = array('Maximum Cached Keys', $status->opcache_statistics->max_cached_keys); |
||
| 136 | $table[] = array('Hits', $status->opcache_statistics->hits); |
||
| 137 | $table[] = array('Start Time', $status->opcache_statistics->start_time); |
||
| 138 | $table[] = array('Last Restart Time', $status->opcache_statistics->last_restart_time); |
||
| 139 | $table[] = array('OOM Restarts', $status->opcache_statistics->oom_restarts); |
||
| 140 | $table[] = array('Hash Restarts', $status->opcache_statistics->hash_restarts); |
||
| 141 | $table[] = array('Manual Restarts', $status->opcache_statistics->manual_restarts); |
||
| 142 | $table[] = array('Misses', $status->opcache_statistics->misses); |
||
| 143 | $table[] = array('Blacklist Misses', $status->opcache_statistics->blacklist_misses); |
||
| 144 | $table[] = array('Blacklist Miss Ratio', $status->opcache_statistics->blacklist_miss_ratio); |
||
| 145 | $table[] = array('Hit Rate', round($status->opcache_statistics->opcache_hit_rate, 3) . '%'); |
||
| 146 | drush_print_table($table, TRUE); |
||
| 147 | |||
| 148 | } |
||
| 149 | |||
| 150 |