ensureAuthor($userId); if ($body->value === $this->body->value) { return; } $this->body = $body; $this->editedAt = $at; } /** * @throws NotTaskCommentAuthor */ public function ensureRemovableBy(int $userId, bool $mayRemoveOthers): void { if (! $mayRemoveOthers) { $this->ensureAuthor($userId); } } public function isWrittenBy(int $userId): bool { return $this->authorId === $userId; } public function id(): ?int { return $this->id; } public function taskId(): int { return $this->taskId; } public function authorId(): ?int { return $this->authorId; } public function body(): TaskCommentBody { return $this->body; } public function createdAt(): DateTimeImmutable { return $this->createdAt; } public function editedAt(): ?DateTimeImmutable { return $this->editedAt; } /** * @throws NotTaskCommentAuthor */ private function ensureAuthor(int $userId): void { if (! $this->isWrittenBy($userId)) { throw new NotTaskCommentAuthor((int) $this->id, $userId); } } }