PipelineStepRepository.php
- Pfad:
src/Infrastructure/Persistence/PipelineStepRepository.php - Namespace: Infrastructure\Persistence
- Zeilen: 111 | Größe: 3,069 Bytes
- Geändert: 2025-12-25 16:58:13 | 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 3
- implements Domain\Repository\PipelineStepRepositoryInterface
- constructor PDO
- use Domain\Repository\PipelineStepRepositoryInterface
Klassen 1
-
PipelineStepRepositoryclass Zeile 11
Funktionen 6
-
__construct()public Zeile 15 -
findSteps()public Zeile 20 -
addStep()public Zeile 35 -
updateStep()public Zeile 56 -
deleteStep()public Zeile 91 -
reorderSteps()public Zeile 100
Verwendet von 1
Code
<?php
declare(strict_types=1);
namespace Infrastructure\Persistence;
// @responsibility: Persistenz für Pipeline-Steps
use Domain\Repository\PipelineStepRepositoryInterface;
class PipelineStepRepository implements PipelineStepRepositoryInterface
{
private \PDO $pdo;
public function __construct(\PDO $pdo)
{
$this->pdo = $pdo;
}
public function findSteps(int $pipelineId): array
{
$stmt = $this->pdo->prepare(
'SELECT * FROM pipeline_steps WHERE pipeline_id = ? ORDER BY sort_order ASC'
);
$stmt->execute([$pipelineId]);
$results = $stmt->fetchAll(\PDO::FETCH_ASSOC);
foreach ($results as &$row) {
$row['config'] = json_decode($row['config'] ?? '{}', true);
}
return $results;
}
public function addStep(int $pipelineId, array $stepData): int
{
$config = is_array($stepData['config'] ?? null)
? json_encode($stepData['config'])
: ($stepData['config'] ?? '{}');
$stmt = $this->pdo->prepare(
'INSERT INTO pipeline_steps (pipeline_id, step_type, config, sort_order, enabled)
VALUES (?, ?, ?, ?, ?)'
);
$stmt->execute([
$pipelineId,
$stepData['step_type'],
$config,
$stepData['sort_order'] ?? 0,
$stepData['enabled'] ?? 1,
]);
return (int) $this->pdo->lastInsertId();
}
public function updateStep(int $stepId, array $stepData): void
{
$sets = [];
$params = [];
if (isset($stepData['step_type'])) {
$sets[] = 'step_type = ?';
$params[] = $stepData['step_type'];
}
if (isset($stepData['config'])) {
$sets[] = 'config = ?';
$params[] = is_array($stepData['config'])
? json_encode($stepData['config'])
: $stepData['config'];
}
if (isset($stepData['sort_order'])) {
$sets[] = 'sort_order = ?';
$params[] = $stepData['sort_order'];
}
if (isset($stepData['enabled'])) {
$sets[] = 'enabled = ?';
$params[] = $stepData['enabled'];
}
if ($sets === []) {
return;
}
$params[] = $stepId;
$stmt = $this->pdo->prepare(
'UPDATE pipeline_steps SET ' . implode(', ', $sets) . ' WHERE id = ?'
);
$stmt->execute($params);
}
public function deleteStep(int $stepId): void
{
$stmt = $this->pdo->prepare('DELETE FROM pipeline_steps WHERE id = ?');
$stmt->execute([$stepId]);
}
/**
* @param array<int> $stepIds
*/
public function reorderSteps(int $pipelineId, array $stepIds): void
{
$stmt = $this->pdo->prepare(
'UPDATE pipeline_steps SET sort_order = ? WHERE id = ? AND pipeline_id = ?'
);
foreach ($stepIds as $order => $stepId) {
$stmt->execute([$order + 1, $stepId, $pipelineId]);
}
}
}