46 lines
993 B
PHP
46 lines
993 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Dashboard\Stats;
|
||
|
|
|
||
|
|
use InvalidArgumentException;
|
||
|
|
|
||
|
|
class SeriesResult
|
||
|
|
{
|
||
|
|
private bool $tooWide = false;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @param array<int, string> $labels
|
||
|
|
* @param array<int, Series> $series
|
||
|
|
*/
|
||
|
|
public function __construct(
|
||
|
|
public readonly array $labels,
|
||
|
|
public readonly array $series,
|
||
|
|
) {
|
||
|
|
foreach ($series as $one) {
|
||
|
|
if (count($one->values) !== count($labels)) {
|
||
|
|
throw new InvalidArgumentException(
|
||
|
|
"Series [{$one->name}] has ".count($one->values).' values for '.count($labels).' labels.'
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function tooWide(): self
|
||
|
|
{
|
||
|
|
$result = new self([], []);
|
||
|
|
$result->tooWide = true;
|
||
|
|
|
||
|
|
return $result;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function isTooWide(): bool
|
||
|
|
{
|
||
|
|
return $this->tooWide;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function isEmpty(): bool
|
||
|
|
{
|
||
|
|
return ! $this->tooWide && $this->labels === [];
|
||
|
|
}
|
||
|
|
}
|