SendChatMessageCommand.php
- Pfad:
src/UseCases/Command/SendChatMessageCommand.php - Namespace: UseCases\Command
- Zeilen: 87 | Größe: 2,462 Bytes
- Geändert: 2025-12-27 23:19:23 | 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
- use Domain\Constants
Klassen 1
-
SendChatMessageCommandclass Zeile 11
Funktionen 4
-
__construct()public Zeile 16 -
fromRequest()public Zeile 32 -
validate()public Zeile 55 -
isValid()public Zeile 82
Versionen 3
-
v3
2025-12-27 23:19 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v2
2025-12-27 23:19 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v1
2025-12-23 07:57 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
Code
<?php
declare(strict_types=1);
namespace UseCases\Command;
// @responsibility: Command-Objekt für Chat-Nachrichten
use Domain\Constants;
final class SendChatMessageCommand
{
/**
* @param array<string> $collections
*/
public function __construct(
public readonly string $sessionUuid,
public readonly string $message,
public readonly string $model,
public readonly array $collections,
public readonly int $contextLimit,
public readonly int $authorProfileId,
public readonly int $systemPromptId,
public readonly float $temperature,
public readonly int $maxTokens,
) {
}
/**
* @param array<string, mixed> $data
*/
public static function fromRequest(string $sessionUuid, array $data): self
{
$collections = $data['collections'] ?? ['documents'];
if (!is_array($collections)) {
$collections = [$collections];
}
return new self(
sessionUuid: $sessionUuid,
message: trim((string) ($data['message'] ?? '')),
model: (string) ($data['model'] ?? 'mistral'),
collections: $collections,
contextLimit: (int) ($data['context_limit'] ?? 5),
authorProfileId: (int) ($data['author_profile_id'] ?? 0),
systemPromptId: (int) ($data['system_prompt_id'] ?? 1),
temperature: (float) ($data['temperature'] ?? 0.7),
maxTokens: (int) ($data['max_tokens'] ?? 4096),
);
}
/**
* @return array<string>
*/
public function validate(): array
{
$errors = [];
if ($this->sessionUuid === '') {
$errors[] = 'Session-ID ist erforderlich.';
}
if ($this->message === '') {
$errors[] = 'Nachricht ist erforderlich.';
}
if ($this->model === '') {
$errors[] = 'Modell ist erforderlich.';
}
if ($this->temperature < 0.0 || $this->temperature > 2.0) {
$errors[] = 'Temperature muss zwischen 0 und 2 liegen.';
}
if ($this->maxTokens < Constants::MIN_TOKENS || $this->maxTokens > Constants::MAX_TOKENS) {
$errors[] = 'Max-Tokens muss zwischen ' . Constants::MIN_TOKENS . ' und ' . Constants::MAX_TOKENS . ' liegen.';
}
return $errors;
}
public function isValid(): bool
{
return $this->validate() === [];
}
}