priceAt($ratePerKilometer); return new self( ExpenseCategory::Mileage, $paidBy, $spentOn, self::text($description), $cost, $kilometers, $destination, $purpose, self::billing($billable, $cost, $markup, $billedAmount), ); } /** * Rebuilds stored details without re-checking them. Used only by repositories. */ public static function reconstitute( ExpenseCategory $category, ExpensePayer $paidBy, DateTimeImmutable $spentOn, ?string $description, Money $cost, ?Kilometers $kilometers, ?string $destination, ?string $purpose, ?ExpenseBilling $billing, ): self { return new self($category, $paidBy, $spentOn, $description, $cost, $kilometers, $destination, $purpose, $billing); } public function isBillable(): bool { return $this->billing !== null; } private static function billing(bool $billable, Money $cost, ?MarkupPercentage $markup, ?Money $billedAmount): ?ExpenseBilling { return $billable ? ExpenseBilling::for($cost, $markup, $billedAmount) : null; } private static function text(?string $value): ?string { $value = trim((string) $value); return $value === '' ? null : $value; } }