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,15 +1,17 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
class DocumentationService {
|
||||
private $controllersPath;
|
||||
private $modelsPath;
|
||||
|
||||
public function __construct($controllersPath = __DIR__ . '/../controllers/', $modelsPath = __DIR__ . '/../models/') {
|
||||
private string $controllersPath;
|
||||
private string $modelsPath;
|
||||
|
||||
public function __construct(string $controllersPath = __DIR__ . '/../controllers/', string $modelsPath = __DIR__ . '/../models/') {
|
||||
$this->controllersPath = $controllersPath;
|
||||
$this->modelsPath = $modelsPath;
|
||||
}
|
||||
|
||||
public function generateDocumentation() {
|
||||
|
||||
public function generateDocumentation(): array {
|
||||
$docs = [
|
||||
'title' => 'Media API Documentation',
|
||||
'version' => '1.0.0',
|
||||
@@ -27,7 +29,7 @@ class DocumentationService {
|
||||
return $docs;
|
||||
}
|
||||
|
||||
private function scanControllers() {
|
||||
private function scanControllers(): array {
|
||||
$endpoints = [];
|
||||
|
||||
$controllerFiles = glob($this->controllersPath . '*Controller.php');
|
||||
@@ -56,7 +58,7 @@ class DocumentationService {
|
||||
return $endpoints;
|
||||
}
|
||||
|
||||
private function parseMethodDoc($docComment, $methodName, $className) {
|
||||
private function parseMethodDoc(?string $docComment, string $methodName, string $className): ?array {
|
||||
if (!$docComment) {
|
||||
return null;
|
||||
}
|
||||
@@ -106,7 +108,7 @@ class DocumentationService {
|
||||
return $info;
|
||||
}
|
||||
|
||||
private function inferHttpMethods($methodName) {
|
||||
private function inferHttpMethods(string $methodName): array {
|
||||
$methods = [];
|
||||
|
||||
if (strpos($methodName, 'get') === 0) {
|
||||
@@ -129,7 +131,7 @@ class DocumentationService {
|
||||
return $methods;
|
||||
}
|
||||
|
||||
private function inferPath($className, $methodName) {
|
||||
private function inferPath(string $className, string $methodName): string {
|
||||
$resource = strtolower(str_replace('Controller', '', $className));
|
||||
$path = "/{$resource}";
|
||||
|
||||
@@ -156,7 +158,7 @@ class DocumentationService {
|
||||
return $path;
|
||||
}
|
||||
|
||||
private function scanModels() {
|
||||
private function scanModels(): array {
|
||||
$models = [];
|
||||
|
||||
$modelFiles = glob($this->modelsPath . '*.php');
|
||||
|
||||
Reference in New Issue
Block a user