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:
@@ -1,12 +1,12 @@
|
||||
<?php
|
||||
class TicketModel {
|
||||
private $conn;
|
||||
|
||||
public function __construct($conn) {
|
||||
private mysqli $conn;
|
||||
|
||||
public function __construct(mysqli $conn) {
|
||||
$this->conn = $conn;
|
||||
}
|
||||
|
||||
public function getTicketById($id) {
|
||||
|
||||
public function getTicketById(int $id): ?array {
|
||||
$sql = "SELECT t.*,
|
||||
u_created.username as creator_username,
|
||||
u_created.display_name as creator_display_name,
|
||||
@@ -31,7 +31,7 @@ class TicketModel {
|
||||
return $result->fetch_assoc();
|
||||
}
|
||||
|
||||
public function getTicketComments($ticketId) {
|
||||
public function getTicketComments(int $ticketId): array {
|
||||
$sql = "SELECT * FROM ticket_comments WHERE ticket_id = ? ORDER BY created_at DESC";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bind_param("i", $ticketId);
|
||||
@@ -46,7 +46,7 @@ class TicketModel {
|
||||
return $comments;
|
||||
}
|
||||
|
||||
public function getAllTickets($page = 1, $limit = 15, $status = 'Open', $sortColumn = 'ticket_id', $sortDirection = 'desc', $category = null, $type = null, $search = null, $filters = []) {
|
||||
public function getAllTickets(int $page = 1, int $limit = 15, ?string $status = 'Open', string $sortColumn = 'ticket_id', string $sortDirection = 'desc', ?string $category = null, ?string $type = null, ?string $search = null, array $filters = []): array {
|
||||
// Calculate offset
|
||||
$offset = ($page - 1) * $limit;
|
||||
|
||||
@@ -222,7 +222,7 @@ class TicketModel {
|
||||
];
|
||||
}
|
||||
|
||||
public function updateTicket($ticketData, $updatedBy = null) {
|
||||
public function updateTicket(array $ticketData, ?int $updatedBy = null): bool {
|
||||
$sql = "UPDATE tickets SET
|
||||
title = ?,
|
||||
priority = ?,
|
||||
@@ -257,7 +257,7 @@ class TicketModel {
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function createTicket($ticketData, $createdBy = null) {
|
||||
public function createTicket(array $ticketData, ?int $createdBy = null): array {
|
||||
// Generate unique ticket ID (9-digit format with leading zeros)
|
||||
// Loop until we find an ID that doesn't exist to prevent collisions
|
||||
$maxAttempts = 10;
|
||||
@@ -347,7 +347,7 @@ class TicketModel {
|
||||
}
|
||||
}
|
||||
|
||||
public function addComment($ticketId, $commentData) {
|
||||
public function addComment(int $ticketId, array $commentData): array {
|
||||
$sql = "INSERT INTO ticket_comments (ticket_id, user_name, comment_text, markdown_enabled)
|
||||
VALUES (?, ?, ?, ?)";
|
||||
|
||||
@@ -387,7 +387,7 @@ class TicketModel {
|
||||
* @param int $assignedBy User ID performing the assignment
|
||||
* @return bool Success status
|
||||
*/
|
||||
public function assignTicket($ticketId, $userId, $assignedBy) {
|
||||
public function assignTicket(int $ticketId, int $userId, int $assignedBy): bool {
|
||||
$sql = "UPDATE tickets SET assigned_to = ?, updated_by = ?, updated_at = NOW() WHERE ticket_id = ?";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bind_param("iii", $userId, $assignedBy, $ticketId);
|
||||
@@ -403,7 +403,7 @@ class TicketModel {
|
||||
* @param int $updatedBy User ID performing the unassignment
|
||||
* @return bool Success status
|
||||
*/
|
||||
public function unassignTicket($ticketId, $updatedBy) {
|
||||
public function unassignTicket(int $ticketId, int $updatedBy): bool {
|
||||
$sql = "UPDATE tickets SET assigned_to = NULL, updated_by = ?, updated_at = NOW() WHERE ticket_id = ?";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bind_param("ii", $updatedBy, $ticketId);
|
||||
@@ -419,7 +419,7 @@ class TicketModel {
|
||||
* @param array $ticketIds Array of ticket IDs
|
||||
* @return array Associative array keyed by ticket_id
|
||||
*/
|
||||
public function getTicketsByIds($ticketIds) {
|
||||
public function getTicketsByIds(array $ticketIds): array {
|
||||
if (empty($ticketIds)) {
|
||||
return [];
|
||||
}
|
||||
@@ -465,7 +465,7 @@ class TicketModel {
|
||||
* @param array $user The user data (must include user_id, is_admin, groups)
|
||||
* @return bool True if user can access the ticket
|
||||
*/
|
||||
public function canUserAccessTicket($ticket, $user) {
|
||||
public function canUserAccessTicket(array $ticket, array $user): bool {
|
||||
// Admins can access all tickets
|
||||
if (!empty($user['is_admin'])) {
|
||||
return true;
|
||||
@@ -505,7 +505,7 @@ class TicketModel {
|
||||
* @param array $user The current user
|
||||
* @return array ['sql' => string, 'params' => array, 'types' => string]
|
||||
*/
|
||||
public function getVisibilityFilter($user) {
|
||||
public function getVisibilityFilter(array $user): array {
|
||||
// Admins see all tickets
|
||||
if (!empty($user['is_admin'])) {
|
||||
return ['sql' => '1=1', 'params' => [], 'types' => ''];
|
||||
@@ -558,7 +558,7 @@ class TicketModel {
|
||||
* @param int $updatedBy User ID
|
||||
* @return bool
|
||||
*/
|
||||
public function updateVisibility($ticketId, $visibility, $visibilityGroups, $updatedBy) {
|
||||
public function updateVisibility(int $ticketId, string $visibility, ?string $visibilityGroups, int $updatedBy): bool {
|
||||
$allowedVisibilities = ['public', 'internal', 'confidential'];
|
||||
if (!in_array($visibility, $allowedVisibilities)) {
|
||||
$visibility = 'public';
|
||||
|
||||
Reference in New Issue
Block a user