Add strict types and type hints across API

Apply strict_types and extensive type declarations throughout the API and models, improving type safety and error handling. Key changes: add declare(strict_types=1) to many files; convert properties, method parameters and return values to typed signatures (PDO, arrays, ints, strings, bools, nullables); switch exception handling to Throwable in index and Router; improve Router, controllers and model method signatures and nullability handling; refine file/image serving security checks and headers in ImageController; strengthen Database typing and initialization methods; return explicit types from BaseModel CRUD helpers and counting; update Media/Cast/Adult/Game/Console/Settings controllers and models to use typed methods, better validation, and clearer update/create return types. Also add AGENTS.md (agent skills index), update README with Swagger/OpenAPI usage instructions, and add /.windsurf to .gitignore. These changes aim to harden runtime correctness, make intended contracts explicit, and prepare the codebase for easier maintenance and static analysis.
This commit is contained in:
Lars Behrends
2026-04-16 16:40:31 +02:00
parent 728ca893b1
commit e38a6e1f7b
26 changed files with 545 additions and 419 deletions

View File

@@ -1,41 +1,43 @@
<?php
declare(strict_types=1);
require_once __DIR__ . '/Cast.php';
require_once __DIR__ . '/../services/ApiLogger.php';
class AdultCast extends Cast {
public function getWithAdultSpecifics($id) {
public function getWithAdultSpecifics(?int $id): ?array {
$cast = $this->getWithFilmography($id);
if (!$cast) {
return null;
}
$cast['adult_specifics'] = $this->getAdultSpecifics($id);
return $cast;
}
public function getAdultSpecifics($castId) {
public function getAdultSpecifics(?int $castId): array|false {
$stmt = $this->pdo->prepare("SELECT * FROM adult_cast_specifics WHERE cast_id = ?");
$stmt->execute([$castId]);
return $stmt->fetch();
}
public function createWithAdultSpecifics($data) {
public function createWithAdultSpecifics(array $data): int {
ApiLogger::getInstance()->logDebug("AdultCast createWithAdultSpecifics called with data: " . json_encode($data));
$name = $data['name'] ?? null;
if (!$name) {
throw new Exception('Name is required');
}
// cleanname generieren
$cleanname = generateCleanName($name);
// Process photo field (base64 to file path)
$data = $this->processPhotoField($data);
// Zuerst Basis-Cast erstellen
$castData = [
'name' => $name,
@@ -45,16 +47,16 @@ class AdultCast extends Cast {
'birthDate' => $data['birthDate'] ?? null,
'birthPlace' => $data['birthPlace'] ?? null
];
$castId = $this->create($castData);
$castId = (int)$this->create($castData);
ApiLogger::getInstance()->logDebug("AdultCast createWithAdultSpecifics: Base cast created with id: $castId");
// Occupations speichern
if (isset($data['occupations']) && is_array($data['occupations'])) {
ApiLogger::getInstance()->logDebug("AdultCast createWithAdultSpecifics: Saving occupations: " . json_encode($data['occupations']));
$this->saveRelatedItems('occupations', $castId, $data['occupations'], 'cast_id');
}
// Adult-spezifische Daten speichern
if (isset($data['adult_specifics']) && is_array($data['adult_specifics'])) {
ApiLogger::getInstance()->logDebug("AdultCast createWithAdultSpecifics: Saving adult_specifics");
@@ -62,20 +64,20 @@ class AdultCast extends Cast {
} else {
ApiLogger::getInstance()->logDebug("AdultCast createWithAdultSpecifics: No adult_specifics found in data");
}
return $castId;
}
public function updateWithAdultSpecifics($id, $data) {
public function updateWithAdultSpecifics(int $id, array $data): bool {
ApiLogger::getInstance()->logDebug("AdultCast updateWithAdultSpecifics called with id: $id, data: " . json_encode($data));
// Set update flag for image replacement
$this->isUpdate = true;
$this->castId = $id;
// Process photo field (base64 to file path)
$data = $this->processPhotoField($data);
// Basis-Cast aktualisieren
$castData = [];
foreach (['name', 'photo', 'bio', 'birthDate', 'birthPlace'] as $field) {
@@ -83,19 +85,19 @@ class AdultCast extends Cast {
$castData[$field] = $data[$field];
}
}
if (!empty($castData)) {
ApiLogger::getInstance()->logDebug("AdultCast updateWithAdultSpecifics: Updating base cast data: " . json_encode($castData));
$this->update($id, $castData);
}
// Occupations aktualisieren
if (isset($data['occupations']) && is_array($data['occupations'])) {
ApiLogger::getInstance()->logDebug("AdultCast updateWithAdultSpecifics: Updating occupations: " . json_encode($data['occupations']));
$this->pdo->prepare("DELETE FROM occupations WHERE cast_id = ?")->execute([$id]);
$this->saveRelatedItems('occupations', $id, $data['occupations'], 'cast_id');
}
// Adult-spezifische Daten aktualisieren
if (isset($data['adult_specifics']) && is_array($data['adult_specifics'])) {
ApiLogger::getInstance()->logDebug("AdultCast updateWithAdultSpecifics: Saving adult_specifics");
@@ -104,11 +106,11 @@ class AdultCast extends Cast {
} else {
ApiLogger::getInstance()->logDebug("AdultCast updateWithAdultSpecifics: No adult_specifics found in data");
}
return true;
}
protected function saveAdultSpecifics($castId, $specifics) {
protected function saveAdultSpecifics(int $castId, array $specifics): void {
ApiLogger::getInstance()->logDebug("AdultCast saveAdultSpecifics called for cast_id: $castId");
ApiLogger::getInstance()->logDebug("Specifics data: " . json_encode($specifics));
@@ -200,13 +202,13 @@ class AdultCast extends Cast {
}
}
public function deleteAdultSpecifics($castId) {
public function deleteAdultSpecifics(?int $castId): bool {
$stmt = $this->pdo->prepare("DELETE FROM adult_cast_specifics WHERE cast_id = ?");
$stmt->execute([$castId]);
return $stmt->rowCount() > 0;
}
public function searchAdultActors($filters = [], $page = 1, $limit = 2000000000) {
public function searchAdultActors(array $filters = [], int $page = 1, int $limit = 2000000000): array {
// Adult Actors mit Specifics suchen
$query = "
SELECT cs.*,