Commit 59a5628b authored by bdragon's avatar bdragon Committed by bdragon
Browse files

Issue #2877947 by idebr, bdragon, sathish.redcrackle, bonus, guilopes, tcmug,...

Issue #2877947 by idebr, bdragon, sathish.redcrackle, bonus, guilopes, tcmug, damiankloip: Apply Drupal coding standards (part 2)
parent 7a58420c
......@@ -9,7 +9,7 @@ memcache_admin.settings:
memcache_admin.reports:
path: /admin/reports/memcache
defaults:
_controller: Drupal\memcache_admin\Controller\MemcacheStatisticsController::stats_table
_controller: Drupal\memcache_admin\Controller\MemcacheStatisticsController::statsTable
_title: Memcache Statistics
requirements:
_permission: access memcache statistics
......@@ -17,7 +17,7 @@ memcache_admin.reports:
memcache_admin.reports_cluster:
path: '/admin/reports/memcache/{cluster}'
defaults:
_controller: Drupal\memcache_admin\Controller\MemcacheStatisticsController::stats_table
_controller: Drupal\memcache_admin\Controller\MemcacheStatisticsController::statsTable
_title: Memcache Statistics - Bin
requirements:
_permission: access memcache statistics
......@@ -25,7 +25,7 @@ memcache_admin.reports_cluster:
memcache_admin.reports_server:
path: '/admin/reports/memcache/{cluster}/{server}'
defaults:
_controller: Drupal\memcache_admin\Controller\MemcacheStatisticsController::stats_table_raw
_controller: Drupal\memcache_admin\Controller\MemcacheStatisticsController::statsTableRaw
_title: Memcache Statistics - Server
requirements:
_permission: access memcache statistics
......@@ -33,7 +33,7 @@ memcache_admin.reports_server:
memcache_admin.reports_type:
path: '/admin/reports/memcache/{cluster}/{server}/{type}'
defaults:
_controller: Drupal\memcache_admin\Controller\MemcacheStatisticsController::stats_table_raw
_controller: Drupal\memcache_admin\Controller\MemcacheStatisticsController::statsTableRaw
_title: Memcache Statistics - Type
requirements:
_permission: access memcache statistics
......@@ -21,12 +21,12 @@ class MemcacheStatisticsController extends ControllerBase {
* @return string
* The page output.
*/
public function stats_table($bin = 'default') {
$output = [];
public function statsTable($bin = 'default') {
$output = [];
$servers = [];
// Get the statistics.
$bin = $this->bin_mapping($bin);
$bin = $this->binMapping($bin);
$memcache = \Drupal::service('memcache.factory')->get($bin, TRUE);
$stats = $memcache->stats($bin, 'default', TRUE);
......@@ -87,13 +87,13 @@ class MemcacheStatisticsController extends ControllerBase {
$data['server_overview'][$server] = t('v@version running @uptime', ['@version' => $statistics['version'], '@uptime' => \Drupal::service('date.formatter')->formatInterval($statistics['uptime'])]);
$data['server_pecl'][$server] = t('n/a');
$data['server_time'][$server] = format_date($statistics['time']);
$data['server_connections'][$server] = $this->stats_connections($statistics);
$data['cache_sets'][$server] = $this->stats_sets($statistics);
$data['cache_gets'][$server] = $this->stats_gets($statistics);
$data['cache_counters'][$server] = $this->stats_counters($statistics);
$data['cache_transfer'][$server] = $this->stats_transfer($statistics);
$data['cache_average'][$server] = $this->stats_average($statistics);
$data['memory_available'][$server] = $this->stats_memory($statistics);
$data['server_connections'][$server] = $this->statsConnections($statistics);
$data['cache_sets'][$server] = $this->statsSets($statistics);
$data['cache_gets'][$server] = $this->statsGets($statistics);
$data['cache_counters'][$server] = $this->statsCounters($statistics);
$data['cache_transfer'][$server] = $this->statsTransfer($statistics);
$data['cache_average'][$server] = $this->statsAverage($statistics);
$data['memory_available'][$server] = $this->statsMemory($statistics);
$data['memory_evictions'][$server] = number_format($statistics['evictions']);
}
}
......@@ -138,8 +138,8 @@ class MemcacheStatisticsController extends ControllerBase {
$report['uptime']['extension']['servers'] = $data['server_pecl'];
$report['uptime']['extension']['total'] = $version;
$report['uptime']['time']['total'] = t('n/a');
$report['uptime']['connections']['total'] = $this->stats_connections($aggregate);
$report['memory']['memory']['total'] = $this->stats_memory($aggregate);
$report['uptime']['connections']['total'] = $this->statsConnections($aggregate);
$report['memory']['memory']['total'] = $this->statsMemory($aggregate);
$report['memory']['evictions']['total'] = number_format($aggregate['evictions']);
}
......@@ -159,12 +159,12 @@ class MemcacheStatisticsController extends ControllerBase {
];
if (count($servers) > 1) {
$func = "stats_{$type}";
$report['stats'][$type]['total'] = $this->$func($aggregate);
$func = 'stats' . ucfirst($type);
$report['stats'][$type]['total'] = $this->{$func}($aggregate);
}
}
$output = $this->stats_tables_output($bin, $servers, $report);
$output = $this->statsTablesOutput($bin, $servers, $report);
}
return $output;
......@@ -183,9 +183,9 @@ class MemcacheStatisticsController extends ControllerBase {
* @return string
* The page output.
*/
public function stats_table_raw($cluster, $server, $type = 'default') {
$cluster = $this->bin_mapping($cluster);
$server = str_replace('!', '/', $server);
public function statsTableRaw($cluster, $server, $type = 'default') {
$cluster = $this->binMapping($cluster);
$server = str_replace('!', '/', $server);
// @todo - pull slab stats for Memcache
// $slab = (int) arg(7);
......@@ -211,13 +211,13 @@ class MemcacheStatisticsController extends ControllerBase {
// }
// drupal_set_breadcrumb($breadcrumbs);
if (isset($stats[$cluster][$server]) && is_array($stats[$cluster][$server]) && count($stats[$cluster][$server])) {
$output = $this->stats_tables_raw_output($cluster, $server, $stats[$cluster][$server], $type);
$output = $this->statsTablesRawOutput($cluster, $server, $stats[$cluster][$server], $type);
}
elseif ($type == 'slabs' && is_array($stats[$cluster]) && count($stats[$cluster])) {
$output = $this->stats_tables_raw_output($cluster, $server, $stats[$cluster], $type);
$output = $this->statsTablesRawOutput($cluster, $server, $stats[$cluster], $type);
}
else {
$output = $this->stats_tables_raw_output($cluster, $server, [], $type);
$output = $this->statsTablesRawOutput($cluster, $server, [], $type);
drupal_set_message(t('No @type statistics for this bin.', ['@type' => $type]));
}
......@@ -227,23 +227,23 @@ class MemcacheStatisticsController extends ControllerBase {
/**
* Helper function, reverse map the memcache_bins variable.
*/
private function bin_mapping($bin = 'cache') {
private function binMapping($bin = 'cache') {
$memcache = \Drupal::service('memcache.factory')->get(NULL, TRUE);
$memcache_bins = $memcache->get_bins();
$memcache_bins = $memcache->getBins();
$bins = array_flip($memcache_bins);
if (isset($bins[$bin])) {
return $bins[$bin];
}
else {
return $this->default_bin($bin);
return $this->defaultBin($bin);
}
}
/**
* Helper function. Returns the bin name.
*/
private function default_bin($bin) {
private function defaultBin($bin) {
if ($bin == 'default') {
return 'cache';
}
......@@ -254,7 +254,7 @@ class MemcacheStatisticsController extends ControllerBase {
/**
* Statistics report: format total and open connections.
*/
private function stats_connections($stats) {
private function statsConnections($stats) {
return $this->t(
'@current open of @total total',
[
......@@ -267,7 +267,7 @@ class MemcacheStatisticsController extends ControllerBase {
/**
* Statistics report: calculate # of set cmds and total cmds.
*/
private function stats_sets($stats) {
private function statsSets($stats) {
if (($stats['cmd_set'] + $stats['cmd_get']) == 0) {
$sets = 0;
}
......@@ -294,7 +294,7 @@ class MemcacheStatisticsController extends ControllerBase {
/**
* Statistics report: calculate # of get cmds, broken down by hits and misses.
*/
private function stats_gets($stats) {
private function statsGets($stats) {
if (($stats['cmd_set'] + $stats['cmd_get']) == 0) {
$gets = 0;
}
......@@ -324,7 +324,7 @@ class MemcacheStatisticsController extends ControllerBase {
/**
* Statistics report: calculate # of increments and decrements.
*/
private function stats_counters($stats) {
private function statsCounters($stats) {
if (!is_array($stats)) {
$stats = [];
}
......@@ -348,7 +348,7 @@ class MemcacheStatisticsController extends ControllerBase {
/**
* Statistics report: calculate bytes transferred.
*/
private function stats_transfer($stats) {
private function statsTransfer($stats) {
if ($stats['bytes_written'] == 0) {
$written = 0;
}
......@@ -368,7 +368,7 @@ class MemcacheStatisticsController extends ControllerBase {
/**
* Statistics report: calculate per-connection averages.
*/
private function stats_average($stats) {
private function statsAverage($stats) {
if ($stats['total_connections'] == 0) {
$get = 0;
$set = 0;
......@@ -395,7 +395,7 @@ class MemcacheStatisticsController extends ControllerBase {
/**
* Statistics report: calculate available memory.
*/
private function stats_memory($stats) {
private function statsMemory($stats) {
if ($stats['limit_maxbytes'] == 0) {
$percent = 0;
}
......@@ -415,9 +415,9 @@ class MemcacheStatisticsController extends ControllerBase {
/**
* Generates render array for output.
*/
private function stats_tables_output($bin, $servers, $stats) {
private function statsTablesOutput($bin, $servers, $stats) {
$memcache = \Drupal::service('memcache.factory')->get(NULL, TRUE);
$memcache_bins = $memcache->get_bins();
$memcache_bins = $memcache->getBins();
$links = [];
foreach ($servers as $server) {
......@@ -462,18 +462,18 @@ class MemcacheStatisticsController extends ControllerBase {
/**
* Generates render array for output.
*/
private function stats_tables_raw_output($cluster, $server, $stats, $type) {
private function statsTablesRawOutput($cluster, $server, $stats, $type) {
$user = \Drupal::currentUser();
$current_type = isset($type) ? $type : 'default';
$memcache = \Drupal::service('memcache.factory')->get(NULL, TRUE);
$memcache_bins = $memcache->get_bins();
$memcache_bins = $memcache->getBins();
$bin = isset($memcache_bins[$cluster]) ? $memcache_bins[$cluster] : 'default';
// Provide navigation for the various memcache stats types.
$links = [];
if (count($memcache->stats_types())) {
foreach ($memcache->stats_types() as $type) {
$link = Link::fromTextandUrl($this->t($type), Url::fromUri('base:/admin/reports/memcache/' . $bin . '/' . str_replace('/', '!', $server) . '/' . ($type == 'default' ? '' : $type)))->toString();
if (count($memcache->statsTypes())) {
foreach ($memcache->statsTypes() as $type) {
$link = Link::fromTextandUrl($type, Url::fromUri('base:/admin/reports/memcache/' . $bin . '/' . str_replace('/', '!', $server) . '/' . ($type == 'default' ? '' : $type)))->toString();
if ($current_type == $type) {
$links[] = '<strong>' . $link . '</strong>';
}
......@@ -502,7 +502,7 @@ class MemcacheStatisticsController extends ControllerBase {
// Add navigation for getting a cachedump of individual slabs.
// @todo - verify if this works correctly with Memcache
if (($current_type == 'slabs' || $current_type == 'items') && is_int($key) && $user->hasPermission('access slab cachedump')) {
$key = Link::fromTextandUrl($this->t($type), Url::fromUri('base:/admin/reports/memcache/' . $bin . '/' . str_replace('/', '!', $server) . '/slabs/cachedump/' . $key))->toString();
$key = Link::fromTextandUrl($type, Url::fromUri('base:/admin/reports/memcache/' . $bin . '/' . str_replace('/', '!', $server) . '/slabs/cachedump/' . $key))->toString();
}
if (is_array($value)) {
$rs = [];
......
......@@ -16,15 +16,15 @@ class MemcacheAdminSubscriber implements EventSubscriberInterface {
/**
* {@inheritdoc}
*/
static function getSubscribedEvents() {
$events[KernelEvents::RESPONSE][] = ['display_statistics'];
public static function getSubscribedEvents() {
$events[KernelEvents::RESPONSE][] = ['displayStatistics'];
return $events;
}
/**
* Display statistics on page.
*/
public function display_statistics(FilterResponseEvent $event) {
public function displayStatistics(FilterResponseEvent $event) {
$user = \Drupal::currentUser();
// Removed exclusion criteria, untested. Will likely need to add some of
......@@ -69,8 +69,8 @@ class MemcacheAdminSubscriber implements EventSubscriberInterface {
foreach ($memcache_stats['ops'] as $row => $stats) {
$memcache_stats['ops'][$row][0] = new HtmlEscapedText($stats[0]);
$memcache_stats['ops'][$row][1] = number_format($stats[1], 2);
$hits = number_format($this->stats_percent($stats[2], $stats[3]), 1);
$misses = number_format($this->stats_percent($stats[3], $stats[2]), 1);
$hits = number_format($this->statsPercent($stats[2], $stats[3]), 1);
$misses = number_format($this->statsPercent($stats[3], $stats[2]), 1);
$memcache_stats['ops'][$row][2] = number_format($stats[2]) . " ($hits%)";
$memcache_stats['ops'][$row][3] = number_format($stats[3]) . " ($misses%)";
}
......@@ -121,7 +121,7 @@ class MemcacheAdminSubscriber implements EventSubscriberInterface {
/**
* Helper function. Calculate a percentage.
*/
private function stats_percent($a, $b) {
private function statsPercent($a, $b) {
if ($a == 0) {
return 0;
}
......
......@@ -80,13 +80,13 @@ abstract class DriverBase implements DrupalMemcacheInterface {
* {@inheritdoc}
*/
public function get($key) {
$collect_stats = $this->stats_init();
$collect_stats = $this->statsInit();
$full_key = $this->key($key);
$result = $this->memcache->get($full_key);
if ($collect_stats) {
$this->stats_write('get', 'cache', [$full_key => (bool)$result]);
$this->statsWrite('get', 'cache', [$full_key => (bool) $result]);
}
return $result;
......@@ -114,13 +114,13 @@ abstract class DriverBase implements DrupalMemcacheInterface {
* {@inheritdoc}
*/
public function delete($key) {
$collect_stats = $this->stats_init();
$collect_stats = $this->statsInit();
$full_key = $this->key($key);
$result = $this->memcache->delete($full_key, 0);
if ($collect_stats) {
$this->stats_write('delete', 'cache', [$full_key => $result]);
$this->statsWrite('delete', 'cache', [$full_key => $result]);
}
return $result;
......@@ -130,12 +130,12 @@ abstract class DriverBase implements DrupalMemcacheInterface {
* {@inheritdoc}
*/
public function flush() {
$collect_stats = $this->stats_init();
$collect_stats = $this->statsInit();
$result = $this->memcache->flush();
if ($collect_stats) {
$this->stats_write('flush', 'cache', ['' => $result]);
$this->statsWrite('flush', 'cache', ['' => $result]);
}
}
......@@ -156,7 +156,7 @@ abstract class DriverBase implements DrupalMemcacheInterface {
$slab = (int) $stats_type;
$stats = [];
foreach ($this->get_bins() as $bin => $target) {
foreach ($this->getBins() as $bin => $target) {
if ($stats_bin == $bin) {
if (isset($this->memcache)) {
if ($this->memcache instanceof \Memcached) {
......@@ -224,7 +224,7 @@ abstract class DriverBase implements DrupalMemcacheInterface {
/**
* Helper function to get the bins.
*/
public function get_bins() {
public function getBins() {
$memcache_bins = \Drupal::configFactory()->getEditable('memcache.settings')->get('memcache_bins');
if (!isset($memcache_bins)) {
$memcache_bins = ['cache' => 'default'];
......@@ -236,7 +236,7 @@ abstract class DriverBase implements DrupalMemcacheInterface {
/**
* Helper function to get the servers.
*/
public function get_servers() {
public function getServers() {
$memcache_servers = \Drupal::configFactory()->getEditable('memcache.settings')->get('memcache_servers');
if (!isset($memcache_servers)) {
$memcache_servers = ['127.0.0.1:11211' => 'default'];
......@@ -255,14 +255,14 @@ abstract class DriverBase implements DrupalMemcacheInterface {
/**
* Helper function to get request stats.
*/
public function request_stats() {
public function requestStats() {
return self::$stats;
}
/**
* Returns an array of available statistics types.
*/
public function stats_types() {
public function statsTypes() {
if ($this->memcache instanceof \Memcache) {
// TODO: Determine which versions of the PECL memcache extension have
// these other stats types: 'malloc', 'maps', optionally detect this
......@@ -279,7 +279,7 @@ abstract class DriverBase implements DrupalMemcacheInterface {
/**
* Helper function to initialize the stats for a memcache operation.
*/
protected function stats_init() {
protected function statsInit() {
static $drupal_static_fast;
if (!isset($drupal_static_fast)) {
......@@ -325,7 +325,7 @@ abstract class DriverBase implements DrupalMemcacheInterface {
* Keyed array in the form (string)$cid => (bool)$success. The keys the
* action is being performed on, and whether or not it was a success.
*/
protected function stats_write($action, $bin, $keys) {
protected function statsWrite($action, $bin, array $keys) {
// Determine how much time elapsed to execute this action.
$time = Timer::read('dmemcache');
......
......@@ -11,13 +11,13 @@ class MemcacheDriver extends DriverBase {
* {@inheritdoc}
*/
public function set($key, $value, $exp = 0, $flag = FALSE) {
$collect_stats = $this->stats_init();
$collect_stats = $this->statsInit();
$full_key = $this->key($key);
$result = $this->memcache->set($full_key, $value, $flag, $exp);
if ($collect_stats) {
$this->stats_write('set', 'cache', [$full_key => (int)$result]);
$this->statsWrite('set', 'cache', [$full_key => (int) $result]);
}
return $result;
......@@ -27,13 +27,13 @@ class MemcacheDriver extends DriverBase {
* {@inheritdoc}
*/
public function add($key, $value, $expire = 0) {
$collect_stats = $this->stats_init();
$collect_stats = $this->statsInit();
$full_key = $this->key($key);
$result = $this->memcache->add($full_key, $value,false, $expire);
$result = $this->memcache->add($full_key, $value, FALSE, $expire);
if ($collect_stats) {
$this->stats_write('add', 'cache', [$full_key => (int)$result]);
$this->statsWrite('add', 'cache', [$full_key => (int) $result]);
}
return $result;
......@@ -43,7 +43,7 @@ class MemcacheDriver extends DriverBase {
* {@inheritdoc}
*/
public function getMulti(array $keys) {
$collect_stats = $this->stats_init();
$collect_stats = $this->statsInit();
$multi_stats = [];
$full_keys = [];
......@@ -81,7 +81,7 @@ class MemcacheDriver extends DriverBase {
}
if ($collect_stats) {
$this->stats_write('getMulti', 'cache', $multi_stats);
$this->statsWrite('getMulti', 'cache', $multi_stats);
}
return $cid_results;
......
......@@ -11,13 +11,13 @@ class MemcachedDriver extends DriverBase {
* {@inheritdoc}
*/
public function set($key, $value, $exp = 0, $flag = FALSE) {
$collect_stats = $this->stats_init();
$collect_stats = $this->statsInit();
$full_key = $this->key($key);
$result = $this->memcache->set($full_key, $value, $exp);
if ($collect_stats) {
$this->stats_write('set', 'cache', [$full_key => (int)$result]);
$this->statsWrite('set', 'cache', [$full_key => (int) $result]);
}
return $result;
......@@ -27,13 +27,13 @@ class MemcachedDriver extends DriverBase {
* {@inheritdoc}
*/
public function add($key, $value, $expire = 0) {
$collect_stats = $this->stats_init();
$collect_stats = $this->statsInit();
$full_key = $this->key($key);
$result = $this->memcache->add($full_key, $value, $expire);
if ($collect_stats) {
$this->stats_write('add', 'cache', [$full_key => (int)$result]);
$this->statsWrite('add', 'cache', [$full_key => (int) $result]);
}
return $result;
......@@ -43,7 +43,7 @@ class MemcachedDriver extends DriverBase {
* {@inheritdoc}
*/
public function getMulti(array $keys) {
$collect_stats = $this->stats_init();
$collect_stats = $this->statsInit();
$multi_stats = [];
$full_keys = [];
......@@ -85,7 +85,7 @@ class MemcachedDriver extends DriverBase {
}
if ($collect_stats) {
$this->stats_write('getMulti', 'cache', $multi_stats);
$this->statsWrite('getMulti', 'cache', $multi_stats);
}
return $cid_results;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment