Skip to content

Commit c58d795

Browse files
committed
Fixes
1 parent f2f7340 commit c58d795

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

src/Dashboards/Memcached/MemcachedTrait.php

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ private function commandsStats(): string {
401401
private function slabs(): string {
402402
$slabs_stats = $this->memcached->getSlabsStats();
403403

404-
$slabs = array_map(function (array $slab): array {
404+
$slabs = array_map(static function (array $slab): array {
405405
$fields = [
406406
'chunk_size' => ['Chunk Size', 'bytes'],
407407
'chunks_per_page' => ['Chunks per Page', 'number'],
@@ -420,7 +420,7 @@ private function slabs(): string {
420420
'touch_hits' => ['TOUCH Hits', 'number'],
421421
];
422422

423-
return $this->formatField($fields, $slab);
423+
return Helpers::formatFields($fields, $slab);
424424
}, $slabs_stats['slabs']);
425425

426426
return $this->template->render('dashboards/memcached', [
@@ -435,7 +435,7 @@ private function slabs(): string {
435435
private function items(): string {
436436
$stats = $this->memcached->getItemsStats();
437437

438-
$items = array_map(function (array $item): array {
438+
$items = array_map(static function (array $item): array {
439439
$fields = [
440440
'number' => ['Items', 'number'],
441441
'number_hot' => ['HOT LRU', 'number'],
@@ -468,29 +468,12 @@ private function items(): string {
468468
'hits_to_temp' => ['Hits to TEMP', 'number'],
469469
];
470470

471-
return $this->formatField($fields, $item);
471+
return Helpers::formatFields($fields, $item);
472472
}, $stats);
473473

474474
return $this->template->render('dashboards/memcached', ['items' => $items]);
475475
}
476476

477-
/**
478-
* @param array<string, mixed> $fields
479-
* @param array<string, mixed> $item
480-
*
481-
* @return array<string, mixed>
482-
*/
483-
private function formatField(array $fields, array $item): array {
484-
$formatted = [];
485-
486-
foreach ($fields as $key => [$label, $type]) {
487-
$value = $item[$key] ?? 0;
488-
$formatted[$label] = Format::{$type}($value);
489-
}
490-
491-
return $formatted;
492-
}
493-
494477
/**
495478
* @throws MemcachedException
496479
*/

src/Helpers.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,4 +241,22 @@ public static function countChildren(array &$tree): int {
241241

242242
return $count;
243243
}
244+
245+
/**
246+
* @param array<string, mixed> $fields
247+
* @param array<string, mixed> $item
248+
*
249+
* @return array<string, mixed>
250+
*/
251+
public static function formatFields(array $fields, array $item): array {
252+
$formatted = [];
253+
254+
// key_name => [label, formatting (number, bytes, seconds, time)]
255+
foreach ($fields as $key => [$label, $type]) {
256+
$value = $item[$key] ?? 0;
257+
$formatted[$label] = $type !== '' ? Format::{$type}($value) : $value;
258+
}
259+
260+
return $formatted;
261+
}
244262
}

0 commit comments

Comments
 (0)