Add PHP 7.4+ type hints to helpers, models, and middleware
Added strict typing with parameter types, return types, and property types across all core classes: - helpers: Database, ErrorHandler, CacheHelper - models: TicketModel, UserModel, WorkflowModel, TemplateModel, UserPreferencesModel - middleware: RateLimitMiddleware, CsrfMiddleware, SecurityHeadersMiddleware Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
* Provides a singleton connection for the request lifecycle.
|
||||
*/
|
||||
class Database {
|
||||
private static $connection = null;
|
||||
private static ?mysqli $connection = null;
|
||||
|
||||
/**
|
||||
* Get database connection (singleton pattern)
|
||||
@@ -14,7 +14,7 @@ class Database {
|
||||
* @return mysqli Database connection
|
||||
* @throws Exception If connection fails
|
||||
*/
|
||||
public static function getConnection() {
|
||||
public static function getConnection(): mysqli {
|
||||
if (self::$connection === null) {
|
||||
self::$connection = self::createConnection();
|
||||
}
|
||||
@@ -33,7 +33,7 @@ class Database {
|
||||
* @return mysqli Database connection
|
||||
* @throws Exception If connection fails
|
||||
*/
|
||||
private static function createConnection() {
|
||||
private static function createConnection(): mysqli {
|
||||
// Ensure config is loaded
|
||||
if (!isset($GLOBALS['config'])) {
|
||||
require_once dirname(__DIR__) . '/config/config.php';
|
||||
@@ -59,7 +59,7 @@ class Database {
|
||||
/**
|
||||
* Close the database connection
|
||||
*/
|
||||
public static function close() {
|
||||
public static function close(): void {
|
||||
if (self::$connection !== null) {
|
||||
self::$connection->close();
|
||||
self::$connection = null;
|
||||
@@ -71,7 +71,7 @@ class Database {
|
||||
*
|
||||
* @return bool Success
|
||||
*/
|
||||
public static function beginTransaction() {
|
||||
public static function beginTransaction(): bool {
|
||||
return self::getConnection()->begin_transaction();
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ class Database {
|
||||
*
|
||||
* @return bool Success
|
||||
*/
|
||||
public static function commit() {
|
||||
public static function commit(): bool {
|
||||
return self::getConnection()->commit();
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ class Database {
|
||||
*
|
||||
* @return bool Success
|
||||
*/
|
||||
public static function rollback() {
|
||||
public static function rollback(): bool {
|
||||
return self::getConnection()->rollback();
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ class Database {
|
||||
* @param array $params Parameters to bind
|
||||
* @return mysqli_result|bool Query result
|
||||
*/
|
||||
public static function query($sql, $types = '', $params = []) {
|
||||
public static function query(string $sql, string $types = '', array $params = []) {
|
||||
$conn = self::getConnection();
|
||||
|
||||
if (empty($types) || empty($params)) {
|
||||
@@ -130,7 +130,7 @@ class Database {
|
||||
* @param array $params Parameters to bind
|
||||
* @return int Affected rows (-1 on failure)
|
||||
*/
|
||||
public static function execute($sql, $types = '', $params = []) {
|
||||
public static function execute(string $sql, string $types = '', array $params = []): int {
|
||||
$conn = self::getConnection();
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
@@ -158,7 +158,7 @@ class Database {
|
||||
*
|
||||
* @return int Last insert ID
|
||||
*/
|
||||
public static function lastInsertId() {
|
||||
public static function lastInsertId(): int {
|
||||
return self::getConnection()->insert_id;
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ class Database {
|
||||
* @param string $string String to escape
|
||||
* @return string Escaped string
|
||||
*/
|
||||
public static function escape($string) {
|
||||
public static function escape(string $string): string {
|
||||
return self::getConnection()->real_escape_string($string);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user