26 lines
513 B
PHP
26 lines
513 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;
|
||
|
|
}
|
||
|
|
}
|