StopwordController.php
- Pfad:
src/Controller/StopwordController.php - Namespace: Controller
- Zeilen: 203 | Größe: 6,033 Bytes
- Geändert: 2025-12-27 12:41:24 | 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 4
- extends Framework\Controller
- constructor Domain\Repository\StopwordRepositoryInterface
- use Domain\Repository\StopwordRepositoryInterface
- use Framework\Controller
Klassen 1
-
StopwordControllerclass Zeile 12
Funktionen 8
-
__construct()public Zeile 16 -
index()public Zeile 21 -
create()public Zeile 35 -
store()public Zeile 42 -
show()Zeile 92 -
update()Zeile 105 -
delete()Zeile 160 -
toggle()Zeile 181
Versionen 14
-
v14
2025-12-27 12:41 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v13
2025-12-27 12:41 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v12
2025-12-27 12:40 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v11
2025-12-27 12:39 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v10
2025-12-27 12:37 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v9
2025-12-27 12:37 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v8
2025-12-27 12:37 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v7
2025-12-27 00:28 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v6
2025-12-27 00:28 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v5
2025-12-27 00:28 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v4
2025-12-27 00:28 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v3
2025-12-27 00:28 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v2
2025-12-27 00:28 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v1
2025-12-27 00:25 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Write-Operation
Code
<?php
declare(strict_types=1);
namespace Controller;
// @responsibility: HTTP-Endpunkte für Stopword-Verwaltung (Entity-Extraction Filter)
use Domain\Repository\StopwordRepositoryInterface;
use Framework\Controller;
class StopwordController extends Controller
{
private StopwordRepositoryInterface $repo;
public function __construct(StopwordRepositoryInterface $repo)
{
$this->repo = $repo;
}
public function index(): void
{
$category = $this->getString('category');
$showAll = $this->getString('all') === '1';
$this->view('semantic-explorer.stopwords.index', [
'title' => 'Stopwords - Semantic Explorer',
'stopwords' => $this->repo->findAll(!$showAll, $category ?: null),
'stats' => $this->repo->getStats(),
'currentCategory' => $category,
'showAll' => $showAll,
]);
}
public function create(): void
{
$this->view('semantic-explorer.stopwords.new', [
'title' => 'Neues Stopword - Semantic Explorer',
]);
}
public function store(): void
{
$this->requireCsrf();
$isHtmx = $this->isHtmxRequest();
$word = trim($this->getString('word'));
if ($word === '') {
if ($isHtmx) {
$this->htmxError('Wort darf nicht leer sein.');
return;
}
$_SESSION['error'] = 'Wort darf nicht leer sein.';
$this->redirect('/semantic-explorer/stopwords/new');
}
try {
$id = $this->repo->create([
'word' => $word,
'category' => $this->getString('category') ?: 'generic',
'reason' => $this->getString('reason') ?: null,
'is_active' => isset($_POST['is_active']) ? 1 : 0,
]);
if ($isHtmx) {
$this->htmxRedirect('/semantic-explorer/stopwords/' . $id);
return;
}
$_SESSION['success'] = "Stopword '{$word}' wurde erstellt.";
$this->redirect('/semantic-explorer/stopwords/' . $id);
} catch (\PDOException $e) {
$errorMsg = str_contains($e->getMessage(), 'Duplicate')
? "Stopword '{$word}' existiert bereits."
: 'Fehler beim Speichern: ' . $e->getMessage();
// @phpstan-ignore if.alwaysFalse (Exception thrown before success-path check)
if ($isHtmx) {
$this->htmxError($errorMsg);
return;
}
$_SESSION['error'] = $errorMsg;
$this->redirect('/semantic-explorer/stopwords/new');
}
}
public function show(string $id): void
{
$stopword = $this->repo->find((int) $id);
if ($stopword === null) {
$this->notFound('Stopword nicht gefunden');
}
$this->view('semantic-explorer.stopwords.edit', [
'title' => 'Stopword: ' . $stopword['word'],
'stopword' => $stopword,
]);
}
public function update(string $id): void
{
$this->requireCsrf();
$isHtmx = $this->isHtmxRequest();
$stopword = $this->repo->find((int) $id);
if ($stopword === null) {
$this->notFound('Stopword nicht gefunden');
}
$word = trim($this->getString('word'));
if ($word === '') {
if ($isHtmx) {
$this->htmxError('Wort darf nicht leer sein.');
return;
}
$_SESSION['error'] = 'Wort darf nicht leer sein.';
$this->redirect('/semantic-explorer/stopwords/' . $id);
}
try {
$this->repo->update((int) $id, [
'word' => $word,
'category' => $this->getString('category') ?: 'generic',
'reason' => $this->getString('reason') ?: null,
'is_active' => isset($_POST['is_active']) ? 1 : 0,
]);
if ($isHtmx) {
$this->htmxRedirect('/semantic-explorer/stopwords/' . $id);
return;
}
$_SESSION['success'] = 'Stopword wurde aktualisiert.';
$this->redirect('/semantic-explorer/stopwords/' . $id);
} catch (\PDOException $e) {
$errorMsg = str_contains($e->getMessage(), 'Duplicate')
? "Stopword '{$word}' existiert bereits."
: 'Fehler beim Speichern: ' . $e->getMessage();
// @phpstan-ignore if.alwaysFalse (Exception thrown before success-path check)
if ($isHtmx) {
$this->htmxError($errorMsg);
return;
}
$_SESSION['error'] = $errorMsg;
$this->redirect('/semantic-explorer/stopwords/' . $id);
}
}
public function delete(string $id): void
{
$this->requireCsrf();
$stopword = $this->repo->find((int) $id);
if ($stopword === null) {
$this->notFound('Stopword nicht gefunden');
}
$this->repo->delete((int) $id);
if ($this->isHtmxRequest()) {
$this->htmxRedirect('/semantic-explorer/stopwords');
return;
}
$_SESSION['success'] = "Stopword '{$stopword['word']}' wurde geloescht.";
$this->redirect('/semantic-explorer/stopwords');
}
public function toggle(string $id): void
{
$this->requireCsrf();
$stopword = $this->repo->find((int) $id);
if ($stopword === null) {
$this->notFound('Stopword nicht gefunden');
}
$this->repo->toggleActive((int) $id);
if ($this->isHtmxRequest()) {
$this->htmxRedirect('/semantic-explorer/stopwords');
return;
}
$newState = $stopword['is_active'] ? 'deaktiviert' : 'aktiviert';
$_SESSION['success'] = "Stopword '{$stopword['word']}' wurde {$newState}.";
$this->redirect('/semantic-explorer/stopwords');
}
}