Task.php
- Pfad:
src/Domain/Entity/Task.php
- Namespace: Domain\Entity
- Zeilen: 304 | Größe: 7,999 Bytes
- Geändert: 2025-12-30 03:15:34 | Gescannt: 2025-12-31 10:22:15
Code Hygiene Score: 60
- Dependencies: 100 (25%)
- LOC: 0 (20%)
- Methods: 0 (20%)
- Secrets: 100 (15%)
- Classes: 100 (10%)
- Magic Numbers: 100 (10%)
Issues 1
| Zeile |
Typ |
Beschreibung |
| - |
complexity |
Datei hat 304 Zeilen (max: 300) |
Dependencies 4
- trait Domain\Traits\TimestampsTrait
- use Domain\Traits\TimestampsTrait
- use Domain\ValueObject\TaskStatus
- use Domain\ValueObject\TaskType
Klassen 1
Funktionen 30
-
__construct()
private
Zeile 29
-
create()
public
Zeile 38
-
generateUuid()
private
Zeile 66
-
getId()
public
Zeile 81
-
getUuid()
public
Zeile 86
-
getTitle()
public
Zeile 91
-
getDescription()
public
Zeile 96
-
getType()
public
Zeile 101
-
getStatus()
public
Zeile 106
-
getCreatedBy()
public
Zeile 111
-
getCreatedByType()
public
Zeile 116
-
getParentTaskId()
public
Zeile 121
-
getDueDate()
public
Zeile 126
-
getMetadata()
public
Zeile 132
-
updateDetails()
public
Zeile 137
-
changeType()
public
Zeile 146
-
assignParent()
public
Zeile 154
-
setDueDate()
public
Zeile 162
-
updateMetadata()
public
Zeile 171
-
isOverdue()
public
Zeile 179
-
start()
public
Zeile 184
-
complete()
public
Zeile 191
-
fail()
public
Zeile 198
-
cancel()
public
Zeile 205
-
retry()
public
Zeile 212
-
transitionTo()
private
Zeile 223
-
setId()
public
Zeile 235
-
hydrate()
public
Zeile 243
-
toArray()
public
Zeile 278
-
fromArray()
public
Zeile 294
Verwendet von 6
Versionen 28
-
v28
2025-12-28 14:21 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v27
2025-12-28 14:20 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v26
2025-12-28 14:19 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v25
2025-12-28 14:19 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v24
2025-12-28 14:18 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v23
2025-12-28 14:18 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v22
2025-12-28 14:18 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v21
2025-12-28 02:25 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v20
2025-12-28 02:24 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v19
2025-12-25 17:02 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v18
2025-12-25 17:02 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v17
2025-12-25 17:02 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v16
2025-12-25 17:02 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v15
2025-12-25 17:02 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v14
2025-12-25 17:02 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v13
2025-12-25 17:00 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v12
2025-12-25 16:59 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v11
2025-12-25 16:59 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v10
2025-12-25 16:59 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v9
2025-12-25 16:58 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v8
2025-12-25 16:58 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v7
2025-12-25 16:58 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v6
2025-12-25 16:58 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v5
2025-12-25 16:57 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v4
2025-12-25 16:57 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v3
2025-12-25 16:56 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v2
2025-12-25 16:56 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v1
2025-12-23 08:07 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
Code
<?php
declare(strict_types=1);
namespace Domain\Entity;
// @responsibility: Task-Entität - Rich Domain Model mit Business-Logik
use Domain\Traits\TimestampsTrait;
use Domain\ValueObject\TaskStatus;
use Domain\ValueObject\TaskType;
class Task
{
use TimestampsTrait;
private ?int $id = null;
private string $uuid;
private string $title;
private ?string $description = null;
private TaskType $type;
private TaskStatus $status;
private string $createdBy;
private string $createdByType = 'human';
private ?int $parentTaskId = null;
private ?\DateTimeImmutable $dueDate = null;
/** @var array<string, mixed> */
private array $metadata = [];
private function __construct()
{
$this->uuid = $this->generateUuid();
$this->status = TaskStatus::PENDING;
$this->type = TaskType::HUMAN_TASK;
$this->createdAt = new \DateTimeImmutable();
$this->updatedAt = new \DateTimeImmutable();
}
public static function create(
string $title,
string $createdBy,
?string $description = null,
?TaskType $type = null,
?int $parentTaskId = null,
?\DateTimeImmutable $dueDate = null
): self {
$task = new self();
$task->title = $title;
$task->createdBy = $createdBy;
$task->description = $description;
if ($type !== null) {
$task->type = $type;
}
if ($parentTaskId !== null) {
$task->parentTaskId = $parentTaskId;
}
if ($dueDate !== null) {
$task->dueDate = $dueDate;
}
return $task;
}
private function generateUuid(): string
{
return sprintf(
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
mt_rand(0, 0xffff),
mt_rand(0, 0xffff),
mt_rand(0, 0xffff),
mt_rand(0, 0x0fff) | 0x4000,
mt_rand(0, 0x3fff) | 0x8000,
mt_rand(0, 0xffff),
mt_rand(0, 0xffff),
mt_rand(0, 0xffff)
);
}
public function getId(): ?int
{
return $this->id;
}
public function getUuid(): string
{
return $this->uuid;
}
public function getTitle(): string
{
return $this->title;
}
public function getDescription(): ?string
{
return $this->description;
}
public function getType(): TaskType
{
return $this->type;
}
public function getStatus(): TaskStatus
{
return $this->status;
}
public function getCreatedBy(): string
{
return $this->createdBy;
}
public function getCreatedByType(): string
{
return $this->createdByType;
}
public function getParentTaskId(): ?int
{
return $this->parentTaskId;
}
public function getDueDate(): ?\DateTimeImmutable
{
return $this->dueDate;
}
/** @return array<string, mixed> */
public function getMetadata(): array
{
return $this->metadata;
}
public function updateDetails(string $title, ?string $description = null): self
{
$this->title = $title;
$this->description = $description;
$this->touch();
return $this;
}
public function changeType(TaskType $type): self
{
$this->type = $type;
$this->touch();
return $this;
}
public function assignParent(int $parentTaskId): self
{
$this->parentTaskId = $parentTaskId;
$this->touch();
return $this;
}
public function setDueDate(?\DateTimeImmutable $dueDate): self
{
$this->dueDate = $dueDate;
$this->touch();
return $this;
}
/** @param array<string, mixed> $metadata */
public function updateMetadata(array $metadata): self
{
$this->metadata = $metadata;
$this->touch();
return $this;
}
public function isOverdue(): bool
{
return $this->dueDate !== null && !$this->status->isTerminal() && $this->dueDate < new \DateTimeImmutable();
}
public function start(): self
{
$this->transitionTo(TaskStatus::IN_PROGRESS);
return $this;
}
public function complete(): self
{
$this->transitionTo(TaskStatus::COMPLETED);
return $this;
}
public function fail(): self
{
$this->transitionTo(TaskStatus::FAILED);
return $this;
}
public function cancel(): self
{
$this->transitionTo(TaskStatus::CANCELLED);
return $this;
}
public function retry(): self
{
if ($this->status !== TaskStatus::FAILED) {
throw new \DomainException('Can only retry failed tasks');
}
$this->transitionTo(TaskStatus::PENDING);
$this->completedAt = null;
return $this;
}
private function transitionTo(TaskStatus $newStatus): void
{
if (!$this->status->canTransitionTo($newStatus)) {
throw new \DomainException(sprintf('Cannot transition from %s to %s', $this->status->value, $newStatus->value));
}
$this->status = $newStatus;
$this->touch();
if ($newStatus->isTerminal()) {
$this->completedAt = new \DateTimeImmutable();
}
}
public function setId(int $id): self
{
$this->id = $id;
return $this;
}
/** @param array<string, mixed> $data */
public function hydrate(array $data): self
{
$this->uuid = $data['uuid'] ?? $this->uuid;
$this->title = $data['title'] ?? $this->title;
$this->description = $data['description'] ?? null;
$this->createdBy = $data['created_by'] ?? $this->createdBy;
$this->createdByType = $data['created_by_type'] ?? 'human';
$this->parentTaskId = isset($data['parent_task_id']) ? (int) $data['parent_task_id'] : null;
if (isset($data['type'])) {
$this->type = is_string($data['type']) ? TaskType::from($data['type']) : $data['type'];
}
if (isset($data['status'])) {
$this->status = is_string($data['status']) ? TaskStatus::from($data['status']) : $data['status'];
}
if (isset($data['due_date'])) {
$this->dueDate = $this->toDateTime($data['due_date']);
}
if (isset($data['created_at'])) {
$this->createdAt = $this->toDateTime($data['created_at']);
}
if (isset($data['updated_at'])) {
$this->updatedAt = $this->toDateTime($data['updated_at']);
}
if (isset($data['completed_at'])) {
$this->completedAt = $this->toDateTime($data['completed_at']);
}
if (isset($data['metadata'])) {
$this->metadata = is_string($data['metadata']) ? json_decode($data['metadata'], true) ?? [] : $data['metadata'];
}
return $this;
}
/** @return array<string, mixed> */
public function toArray(): array
{
return [
'id' => $this->id, 'uuid' => $this->uuid, 'title' => $this->title,
'description' => $this->description, 'type' => $this->type->value,
'status' => $this->status->value, 'created_by' => $this->createdBy,
'created_by_type' => $this->createdByType, 'parent_task_id' => $this->parentTaskId,
'due_date' => $this->dueDate?->format('Y-m-d H:i:s'),
'created_at' => $this->createdAt->format('Y-m-d H:i:s.u'),
'updated_at' => $this->updatedAt->format('Y-m-d H:i:s.u'),
'completed_at' => $this->completedAt?->format('Y-m-d H:i:s.u'),
'metadata' => $this->metadata,
];
}
/** @param array<string, mixed> $data */
public static function fromArray(array $data): self
{
$task = new self();
if (isset($data['id'])) {
$task->setId((int) $data['id']);
}
return $task->hydrate($data);
}
}