$steps */ public function __construct( private ?int $id, private QuickSaleLine $sale, private array $steps, private ?int $currentStep, private ?DateTimeImmutable $madeAt, ) {} /** * @param list $steps */ public static function ordered(QuickSaleLine $sale, array $steps, DateTimeImmutable $at): self { return new self(null, $sale, $steps, $steps === [] ? null : 0, $steps === [] ? $at : null); } /** * Completes the current step; the line moves to its next step or is made. * * @return OrderStep|null The next step, null when the line is made. * * @throws OrderStepNotCurrent */ public function completeStep(int $position, DateTimeImmutable $at): ?OrderStep { if ($this->currentStep !== $position) { throw new OrderStepNotCurrent; } $next = $position + 1; if (isset($this->steps[$next])) { $this->currentStep = $next; return $this->steps[$next]; } $this->currentStep = null; $this->madeAt = $at; return null; } public function currentStep(): ?OrderStep { return $this->currentStep === null ? null : $this->steps[$this->currentStep]; } public function currentStepPosition(): ?int { return $this->currentStep; } public function isMade(): bool { return $this->madeAt !== null; } public function isInProduction(): bool { return $this->steps !== [] && $this->currentStep !== null; } public function hasStarted(): bool { return $this->steps !== [] && ($this->currentStep === null || $this->currentStep > 0); } public function id(): ?int { return $this->id; } public function sale(): QuickSaleLine { return $this->sale; } /** * @return list */ public function steps(): array { return $this->steps; } public function madeAt(): ?DateTimeImmutable { return $this->madeAt; } }