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:
@@ -1,9 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/config.php';
|
||||
|
||||
class Database {
|
||||
private $pdo;
|
||||
|
||||
private ?PDO $pdo;
|
||||
|
||||
public function __construct() {
|
||||
try {
|
||||
$dsn = 'mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=utf8mb4';
|
||||
@@ -17,8 +20,8 @@ class Database {
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
private function initializeTables() {
|
||||
|
||||
private function initializeTables(): void {
|
||||
// Media-Tabelle
|
||||
$this->pdo->exec("
|
||||
CREATE TABLE IF NOT EXISTS media (
|
||||
@@ -366,8 +369,8 @@ class Database {
|
||||
// Bestehende Einträge mit cleanname aktualisieren
|
||||
$this->updateExistingCleanNames();
|
||||
}
|
||||
|
||||
private function updateExistingCleanNames() {
|
||||
|
||||
private function updateExistingCleanNames(): void {
|
||||
// Media cleanname aktualisieren
|
||||
$this->pdo->exec("
|
||||
UPDATE media
|
||||
@@ -382,8 +385,8 @@ class Database {
|
||||
WHERE cleanname IS NULL OR cleanname = ''
|
||||
");
|
||||
}
|
||||
|
||||
public function getConnection() {
|
||||
|
||||
public function getConnection(): PDO {
|
||||
return $this->pdo;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user