GenerateContentCommand.php

Code Hygiene Score: 100

Keine Issues gefunden.

Klassen 1

Funktionen 4

Verwendet von 1

Versionen 1

Code

<?php

declare(strict_types=1);

namespace UseCases\Command;

// @responsibility: Command-Objekt für Content-Generierung

final class GenerateContentCommand
{
    public function __construct(
        public readonly int $orderId,
        public readonly string $model,
        public readonly string $collection,
        public readonly int $contextLimit,
    ) {
    }

    /**
     * @param array<string, mixed> $data
     */
    public static function fromRequest(int $orderId, array $data): self
    {
        return new self(
            orderId: $orderId,
            model: (string) ($data['model'] ?? 'claude-opus-4-5-20251101'),
            collection: (string) ($data['collection'] ?? 'documents'),
            contextLimit: (int) ($data['context_limit'] ?? 5),
        );
    }

    /**
     * @return array<string>
     */
    public function validate(): array
    {
        $errors = [];

        if ($this->orderId < 1) {
            $errors[] = 'Ungültige Order-ID.';
        }

        if ($this->model === '') {
            $errors[] = 'Modell ist erforderlich.';
        }

        if ($this->collection === '') {
            $errors[] = 'Collection ist erforderlich.';
        }

        if ($this->contextLimit < 1 || $this->contextLimit > 20) {
            $errors[] = 'Context-Limit muss zwischen 1 und 20 liegen.';
        }

        return $errors;
    }

    public function isValid(): bool
    {
        return $this->validate() === [];
    }
}
← Übersicht Graph