ChatResponse.php
- Pfad:
src/UseCases/Chat/ChatResponse.php - Namespace: UseCases\Chat
- Zeilen: 125 | Größe: 2,996 Bytes
- Geändert: 2025-12-23 07:57:10 | Gescannt: 2025-12-31 10:22:15
Code Hygiene Score: 94
- Dependencies: 100 (25%)
- LOC: 100 (20%)
- Methods: 70 (20%)
- Secrets: 100 (15%)
- Classes: 100 (10%)
- Magic Numbers: 100 (10%)
Keine Issues gefunden.
Klassen 1
-
ChatResponseclass Zeile 9
Funktionen 13
-
__construct()public Zeile 11 -
getQualityValidation()public Zeile 22 -
withQualityValidation()public Zeile 27 -
getAnswer()public Zeile 40 -
getSources()public Zeile 45 -
getTokensInput()public Zeile 50 -
getTokensOutput()public Zeile 55 -
getDurationSeconds()public Zeile 60 -
getError()public Zeile 65 -
hasError()public Zeile 70 -
fromServiceResponse()public Zeile 78 -
error()public Zeile 99 -
toArray()public Zeile 110
Versionen 3
-
v3
2025-12-23 07:57 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v2
2025-12-23 03:34 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v1
2025-12-23 03:34 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
Code
<?php
declare(strict_types=1);
namespace UseCases\Chat;
// @responsibility: Ergebnisobjekt für Chat-Nachrichten mit Metadaten
final class ChatResponse
{
public function __construct(
private string $answer,
private array $sources = [],
private ?int $tokensInput = null,
private ?int $tokensOutput = null,
private ?float $durationSeconds = null,
private ?string $error = null,
private ?array $qualityValidation = null,
) {
}
public function getQualityValidation(): ?array
{
return $this->qualityValidation;
}
public function withQualityValidation(array $validation): self
{
return new self(
answer: $this->answer,
sources: $this->sources,
tokensInput: $this->tokensInput,
tokensOutput: $this->tokensOutput,
durationSeconds: $this->durationSeconds,
error: $this->error,
qualityValidation: $validation,
);
}
public function getAnswer(): string
{
return $this->answer;
}
public function getSources(): array
{
return $this->sources;
}
public function getTokensInput(): ?int
{
return $this->tokensInput;
}
public function getTokensOutput(): ?int
{
return $this->tokensOutput;
}
public function getDurationSeconds(): ?float
{
return $this->durationSeconds;
}
public function getError(): ?string
{
return $this->error;
}
public function hasError(): bool
{
return $this->error !== null;
}
/**
* Create from AI service response array
*/
public static function fromServiceResponse(array $result, ?float $duration = null): self
{
if (isset($result['error'])) {
return new self(
answer: '',
error: $result['error'],
);
}
return new self(
answer: $result['answer'] ?? '',
sources: $result['sources'] ?? [],
tokensInput: $result['usage']['input_tokens'] ?? null,
tokensOutput: $result['usage']['output_tokens'] ?? null,
durationSeconds: $duration,
);
}
/**
* Create error response
*/
public static function error(string $message): self
{
return new self(
answer: '',
error: $message,
);
}
/**
* Convert to array for view rendering
*/
public function toArray(): array
{
return [
'answer' => $this->answer,
'sources' => $this->sources,
'usage' => [
'input_tokens' => $this->tokensInput,
'output_tokens' => $this->tokensOutput,
],
'duration_seconds' => $this->durationSeconds,
'error' => $this->error,
'quality_validation' => $this->qualityValidation,
];
}
}