ChunkDataRepository.php
- Pfad:
src/Infrastructure/Docs/ChunkDataRepository.php - Namespace: Infrastructure\Docs
- Zeilen: 147 | Größe: 4,687 Bytes
- Geändert: 2025-12-25 17:00:08 | 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 2
- constructor PDO
- use PDO
Klassen 1
-
ChunkDataRepositoryclass Zeile 11
Funktionen 7
-
__construct()public Zeile 13 -
findById()public Zeile 23 -
findPending()public Zeile 37 -
getDocumentContext()public Zeile 56 -
updateStatus()public Zeile 71 -
storeAnalysisResults()public Zeile 85 -
getStats()public Zeile 117
Verwendet von 2
- ChunkAnalysisService.php constructor
- InfrastructureServiceProvider.php use
Versionen 1
-
v1
2025-12-25 17:00 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
Code
<?php
declare(strict_types=1);
namespace Infrastructure\Docs;
// @responsibility: Datenbank-Operationen für dokumentation_chunks
use PDO;
final class ChunkDataRepository
{
public function __construct(
private PDO $pdo
) {
}
/**
* Gets a chunk by ID.
*
* @return array<string, mixed>|null
*/
public function findById(int $id): ?array
{
$stmt = $this->pdo->prepare('SELECT * FROM dokumentation_chunks WHERE id = :id');
$stmt->execute(['id' => $id]);
$result = $stmt->fetch(PDO::FETCH_ASSOC);
return $result !== false ? $result : null;
}
/**
* Gets pending chunks for analysis.
*
* @return array<array<string, mixed>>
*/
public function findPending(int $limit): array
{
$stmt = $this->pdo->prepare("
SELECT * FROM dokumentation_chunks
WHERE analysis_status = 'pending'
ORDER BY dokumentation_id, chunk_index
LIMIT :limit
");
$stmt->bindValue('limit', $limit, PDO::PARAM_INT);
$stmt->execute();
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
/**
* Gets document context by ID.
*
* @return array{title: string, path: string}
*/
public function getDocumentContext(int $docId): array
{
$stmt = $this->pdo->prepare('SELECT title, path FROM dokumentation WHERE id = :id');
$stmt->execute(['id' => $docId]);
$result = $stmt->fetch(PDO::FETCH_ASSOC);
return [
'title' => $result['title'] ?? 'Unbekannt',
'path' => $result['path'] ?? '/',
];
}
/**
* Updates chunk analysis status.
*/
public function updateStatus(int $chunkId, string $status, ?string $error = null): void
{
$sql = 'UPDATE dokumentation_chunks
SET analysis_status = :status, analysis_error = :error
WHERE id = :id';
$stmt = $this->pdo->prepare($sql);
$stmt->execute(['id' => $chunkId, 'status' => $status, 'error' => $error]);
}
/**
* Stores analysis results.
*
* @param array{taxonomy: array<string>, entities: array<array{name: string, type: string}>, keywords: array<string>} $analysis
*/
public function storeAnalysisResults(int $chunkId, array $analysis, string $model): void
{
$taxonomyPath = $analysis['taxonomy'];
$taxonomyCategory = !empty($taxonomyPath) ? $taxonomyPath[0] : null;
$sql = "UPDATE dokumentation_chunks SET
taxonomy_category = :category,
taxonomy_path = :taxonomy,
entities = :entities,
keywords = :keywords,
analysis_model = :model,
analysis_status = 'completed',
analysis_error = NULL,
analyzed_at = NOW()
WHERE id = :id";
$stmt = $this->pdo->prepare($sql);
$stmt->execute([
'id' => $chunkId,
'category' => $taxonomyCategory,
'taxonomy' => json_encode($taxonomyPath),
'entities' => json_encode($analysis['entities']),
'keywords' => json_encode($analysis['keywords']),
'model' => $model,
]);
}
/**
* Gets analysis statistics.
*
* @return array{pending: int, processing: int, completed: int, failed: int, by_category: array<array{category: string, count: int}>}
*/
public function getStats(): array
{
$stmt = $this->pdo->query("
SELECT
SUM(CASE WHEN analysis_status = 'pending' THEN 1 ELSE 0 END) as pending,
SUM(CASE WHEN analysis_status = 'processing' THEN 1 ELSE 0 END) as processing,
SUM(CASE WHEN analysis_status = 'completed' THEN 1 ELSE 0 END) as completed,
SUM(CASE WHEN analysis_status = 'failed' THEN 1 ELSE 0 END) as failed
FROM dokumentation_chunks
");
$counts = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt = $this->pdo->query('
SELECT taxonomy_category as category, COUNT(*) as count
FROM dokumentation_chunks
WHERE taxonomy_category IS NOT NULL
GROUP BY taxonomy_category
ORDER BY count DESC
');
$byCategory = $stmt->fetchAll(PDO::FETCH_ASSOC);
return [
'pending' => (int) ($counts['pending'] ?? 0),
'processing' => (int) ($counts['processing'] ?? 0),
'completed' => (int) ($counts['completed'] ?? 0),
'failed' => (int) ($counts['failed'] ?? 0),
'by_category' => $byCategory,
];
}
}