refactor: fix 7 CRUD system inconsistencies for robustness and maintainability

- Add user-assignment dependency check to DepartmentService.deleteByUuid (409 when users assigned)
- Standardize POST detection to isMethod('POST') in 10 create/edit actions
- Align RoleService code uniqueness to warning pattern (matching departments)
- Normalize repository create() return types from mixed to int|false (3 repos + 3 interfaces)
- Add JSON response branches to 4 non-user delete actions
- Document delete authorization ordering pattern
- Decompose AdminSettingsService.updateFromAdmin into domain-scoped private methods

Workflow: .agents/runs/CRUD-CONSISTENCY-001/
Reviewed by: Code Reviewer (pass), Security Reviewer (pass), Acceptance Tester (pass)
Quality gates: QG-001 PHPUnit pass, QG-002 PHPStan pass, QG-003 Architecture pass

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-22 18:25:33 +01:00
parent 984d0430d3
commit c429ff43cd
29 changed files with 495 additions and 207 deletions

View File

@@ -119,7 +119,7 @@ class RoleRepository implements RoleRepositoryInterface
return $count ? ((int) $count > 0) : false;
}
public function create(array $data): mixed
public function create(array $data): int|false
{
return DB::insert(
'insert into roles (uuid, description, code, active, created_by, created) values (?,?,?,?,?,NOW())',

View File

@@ -23,7 +23,7 @@ interface RoleRepositoryInterface
public function existsByCode(string $code, int $excludeId = 0): bool;
public function create(array $data): mixed;
public function create(array $data): int|false;
public function update(int $id, array $data): bool;

View File

@@ -242,7 +242,7 @@ class DepartmentRepository implements DepartmentRepositoryInterface
return $count ? (int) $count : 0;
}
public function create(array $data): mixed
public function create(array $data): int|false
{
return DB::insert(
'insert into departments (uuid, description, tenant_id, code, cost_center, active, created_by, created) values (?,?,?,?,?,?,?,NOW())',

View File

@@ -27,7 +27,7 @@ interface DepartmentRepositoryInterface
public function countByTenantId(int $tenantId): int;
public function create(array $data): mixed;
public function create(array $data): int|false;
public function update(int $id, array $data): bool;

View File

@@ -127,7 +127,7 @@ class TenantRepository implements TenantRepositoryInterface
return RepositoryArrayHelper::unwrap($row, 'tenants');
}
public function create(array $data): mixed
public function create(array $data): int|false
{
return DB::insert(
'insert into tenants (uuid, description, address, postal_code, city, country, region, vat_id, tax_number, phone, fax, email, support_email, support_phone, billing_email, website, privacy_url, imprint_url, primary_color, default_theme, allow_user_theme, status, status_changed_at, status_changed_by, created_by, created) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,NOW())',

View File

@@ -19,7 +19,7 @@ interface TenantRepositoryInterface
public function findByUuid(string $uuid): ?array;
public function create(array $data): mixed;
public function create(array $data): int|false;
public function update(int $id, array $data): bool;