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,19 +1,21 @@
<?php
declare(strict_types=1);
require_once __DIR__ . '/BaseModel.php';
class Settings extends BaseModel {
protected $table = 'settings';
public function __construct($pdo) {
protected string $table = 'settings';
public function __construct(PDO $pdo) {
parent::__construct($pdo);
}
public function getSettings() {
public function getSettings(): ?array {
$stmt = $this->pdo->prepare("SELECT * FROM {$this->table} WHERE id = 1");
$stmt->execute();
$settings = $stmt->fetch();
if ($settings) {
// Decode enabled_categories from JSON
$settings['enabled_categories'] = $settings['enabled_categories'] ? json_decode($settings['enabled_categories'], true) : [];
@@ -21,11 +23,11 @@ class Settings extends BaseModel {
$settings['show_adult_content'] = (bool)$settings['show_adult_content'];
$settings['auto_play_trailers'] = (bool)$settings['auto_play_trailers'];
}
return $settings;
}
public function updateSettings($data) {
public function updateSettings(array $data): ?array {
$updateData = [];
if (isset($data['enabled_categories']) && is_array($data['enabled_categories'])) {