type = $type; } /** * Create a numeric range grouping (buckets of $interval width). */ public static function numeric(float $interval, ?float $startNum = null, ?float $endNum = null): self { $group = new self(self::TYPE_NUMERIC); $group->interval = $interval; $group->startNum = $startNum; $group->endNum = $endNum; return $group; } /** * Create a date grouping by one or more calendar units. * * @param string|string[] $groupBy one or more GROUP_BY_* constants */ public static function date($groupBy, ?string $startDate = null, ?string $endDate = null): self { $group = new self(self::TYPE_DATE); $group->groupBy = is_array($groupBy) ? array_values($groupBy) : [$groupBy]; $group->startDate = $startDate; $group->endDate = $endDate; return $group; } public function getType(): string { return $this->type; } public function isNumeric(): bool { return $this->type === self::TYPE_NUMERIC; } public function isDate(): bool { return $this->type === self::TYPE_DATE; } public function getInterval(): float { return $this->interval; } public function getStartNum(): ?float { return $this->startNum; } public function getEndNum(): ?float { return $this->endNum; } /** * @return string[] */ public function getGroupBy(): array { return $this->groupBy; } public function getStartDate(): ?string { return $this->startDate; } public function getEndDate(): ?string { return $this->endDate; } }