ContentVersionDTO.php
- Pfad:
src/Domain/DTO/ContentVersionDTO.php - Namespace: Domain\DTO
- Zeilen: 80 | Größe: 2,485 Bytes
- Geändert: 2025-12-25 11:17:31 | Gescannt: 2025-12-31 10:22:15
Code Hygiene Score: 100
- Dependencies: 100 (25%)
- LOC: 100 (20%)
- Methods: 100 (20%)
- Secrets: 100 (15%)
- Classes: 100 (10%)
- Magic Numbers: 100 (10%)
Keine Issues gefunden.
Dependencies 1
- constructor DateTimeImmutable
Klassen 1
-
ContentVersionDTOclass Zeile 9
Funktionen 4
-
__construct()public Zeile 11 -
fromDatabaseRow()public Zeile 31 -
totalTokens()public Zeile 63 -
preview()public Zeile 71
Versionen 1
-
v1
2025-12-25 10:49 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Write-Operation
Code
<?php
declare(strict_types=1);
namespace Domain\DTO;
// @responsibility: DTO für Content-Version-Daten aus Repository
final readonly class ContentVersionDTO
{
public function __construct(
public int $id,
public int $orderId,
public int $versionNumber,
public string $content,
public string $model,
public int $tokensInput,
public int $tokensOutput,
public float $costUsd,
public int $durationMs,
public \DateTimeImmutable $createdAt,
public ?string $title = null,
) {
}
/**
* Create from database row.
*
* @param array<string, mixed> $row
*/
public static function fromDatabaseRow(array $row): self
{
$id = isset($row['id']) ? (int) $row['id'] : 0;
$orderId = isset($row['order_id']) ? (int) $row['order_id'] : 0;
$versionNumber = isset($row['version_number']) ? (int) $row['version_number'] : 1;
$content = isset($row['content']) ? (string) $row['content'] : '';
$model = isset($row['model']) ? (string) $row['model'] : 'unknown';
$tokensInput = isset($row['tokens_input']) ? (int) $row['tokens_input'] : 0;
$tokensOutput = isset($row['tokens_output']) ? (int) $row['tokens_output'] : 0;
$costUsd = isset($row['cost_usd']) ? (float) $row['cost_usd'] : 0.0;
$durationMs = isset($row['duration_ms']) ? (int) $row['duration_ms'] : 0;
$createdAtStr = isset($row['created_at']) ? (string) $row['created_at'] : 'now';
$title = isset($row['title']) ? (string) $row['title'] : null;
return new self(
id: $id,
orderId: $orderId,
versionNumber: $versionNumber,
content: $content,
model: $model,
tokensInput: $tokensInput,
tokensOutput: $tokensOutput,
costUsd: $costUsd,
durationMs: $durationMs,
createdAt: new \DateTimeImmutable($createdAtStr),
title: $title,
);
}
/**
* Get total tokens used.
*/
public function totalTokens(): int
{
return $this->tokensInput + $this->tokensOutput;
}
/**
* Get content preview (first N characters).
*/
public function preview(int $length = 200): string
{
if (mb_strlen($this->content) <= $length) {
return $this->content;
}
return mb_substr($this->content, 0, $length) . '...';
}
}