fedi-feed-router/app/Dashboard/Stats/BreakdownResult.php

30 lines
599 B
PHP

<?php
namespace App\Dashboard\Stats;
class BreakdownResult
{
/**
* @param array<int, Breakdown> $rows
*/
public function __construct(
public readonly array $rows,
) {}
public function total(): int
{
return array_sum(array_map(fn (Breakdown $row): int => $row->count, $this->rows));
}
public function shareOf(Breakdown $row): float
{
$total = $this->total();
return $total > 0 ? round(($row->count / $total) * 100, 1) : 0.0;
}
public function isEmpty(): bool
{
return $this->total() === 0;
}
}