refactor(audit): remove factory chain and repository interfaces

Remove AuditRepositoryFactory and AuditServicesFactory — two-layer
factory chain replaced by direct DI container wiring. Delete 4
single-consumer repository interfaces. Register all 4 repositories
and SystemAuditRedactionService directly in container. Update all
service constructors to type-hint concrete classes. Fix architecture
test and documentation references to deleted factories.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-26 12:33:59 +01:00
parent 4bf871b640
commit 570e3923b7
22 changed files with 68 additions and 247 deletions

View File

@@ -5,7 +5,7 @@ namespace MintyPHP\Module\Audit\Service;
use MintyPHP\Http\ApiAuth;
use MintyPHP\Http\RequestContext;
use MintyPHP\Http\RequestRuntimeInterface;
use MintyPHP\Module\Audit\Repository\ApiAuditLogRepositoryInterface;
use MintyPHP\Module\Audit\Repository\ApiAuditLogRepository;
class ApiAuditService
{
@@ -17,7 +17,7 @@ class ApiAuditService
private ?array $context = null;
public function __construct(
private readonly ApiAuditLogRepositoryInterface $apiAuditLogRepository,
private readonly ApiAuditLogRepository $apiAuditLogRepository,
private readonly RequestRuntimeInterface $requestRuntime
) {
}

View File

@@ -1,40 +0,0 @@
<?php
namespace MintyPHP\Module\Audit\Service;
use MintyPHP\Module\Audit\Repository\ApiAuditLogRepository;
use MintyPHP\Module\Audit\Repository\ApiAuditLogRepositoryInterface;
use MintyPHP\Module\Audit\Repository\ImportAuditRunRepository;
use MintyPHP\Module\Audit\Repository\ImportAuditRunRepositoryInterface;
use MintyPHP\Module\Audit\Repository\SystemAuditLogRepository;
use MintyPHP\Module\Audit\Repository\SystemAuditLogRepositoryInterface;
use MintyPHP\Module\Audit\Repository\UserLifecycleAuditRepository;
use MintyPHP\Module\Audit\Repository\UserLifecycleAuditRepositoryInterface;
class AuditRepositoryFactory
{
private ?ApiAuditLogRepository $apiAuditLogRepository = null;
private ?ImportAuditRunRepository $importAuditRunRepository = null;
private ?UserLifecycleAuditRepository $userLifecycleAuditRepository = null;
private ?SystemAuditLogRepository $systemAuditLogRepository = null;
public function createApiAuditLogRepository(): ApiAuditLogRepositoryInterface
{
return $this->apiAuditLogRepository ??= new ApiAuditLogRepository();
}
public function createUserLifecycleAuditRepository(): UserLifecycleAuditRepositoryInterface
{
return $this->userLifecycleAuditRepository ??= new UserLifecycleAuditRepository();
}
public function createSystemAuditLogRepository(): SystemAuditLogRepositoryInterface
{
return $this->systemAuditLogRepository ??= new SystemAuditLogRepository();
}
public function createImportAuditRunRepository(): ImportAuditRunRepositoryInterface
{
return $this->importAuditRunRepository ??= new ImportAuditRunRepository();
}
}

View File

@@ -1,71 +0,0 @@
<?php
namespace MintyPHP\Module\Audit\Service;
use MintyPHP\Http\RequestRuntimeInterface;
use MintyPHP\Http\SessionStoreInterface;
use MintyPHP\Module\Audit\Repository\ApiAuditLogRepositoryInterface;
use MintyPHP\Module\Audit\Repository\SystemAuditLogRepositoryInterface;
use MintyPHP\Module\Audit\Repository\UserLifecycleAuditRepositoryInterface;
use MintyPHP\Service\Settings\SettingsSystemAuditGateway;
class AuditServicesFactory
{
private ?ApiAuditService $apiAuditService = null;
private ?UserLifecycleAuditService $userLifecycleAuditService = null;
private ?SystemAuditRedactionService $systemAuditRedactionService = null;
private ?SystemAuditService $systemAuditService = null;
public function __construct(
private readonly AuditRepositoryFactory $auditRepositoryFactory,
private readonly SettingsSystemAuditGateway $settingsSystemAuditGateway,
private readonly RequestRuntimeInterface $requestRuntime,
private readonly SessionStoreInterface $sessionStore
) {
}
public function createApiAuditLogRepository(): ApiAuditLogRepositoryInterface
{
return $this->auditRepositoryFactory->createApiAuditLogRepository();
}
public function createUserLifecycleAuditRepository(): UserLifecycleAuditRepositoryInterface
{
return $this->auditRepositoryFactory->createUserLifecycleAuditRepository();
}
public function createSystemAuditLogRepository(): SystemAuditLogRepositoryInterface
{
return $this->auditRepositoryFactory->createSystemAuditLogRepository();
}
public function createApiAuditService(): ApiAuditService
{
return $this->apiAuditService ??= new ApiAuditService(
$this->createApiAuditLogRepository(),
$this->requestRuntime
);
}
public function createUserLifecycleAuditService(): UserLifecycleAuditService
{
return $this->userLifecycleAuditService ??= new UserLifecycleAuditService(
$this->createUserLifecycleAuditRepository()
);
}
public function createSystemAuditRedactionService(): SystemAuditRedactionService
{
return $this->systemAuditRedactionService ??= new SystemAuditRedactionService();
}
public function createSystemAuditService(): SystemAuditService
{
return $this->systemAuditService ??= new SystemAuditService(
$this->createSystemAuditLogRepository(),
$this->createSystemAuditRedactionService(),
$this->settingsSystemAuditGateway,
$this->sessionStore
);
}
}

View File

@@ -4,9 +4,9 @@ namespace MintyPHP\Module\Audit\Service;
use DateTimeImmutable;
use DateTimeZone;
use MintyPHP\Module\Audit\Domain\SystemAuditOutcome;
use MintyPHP\Http\RequestContext;
use MintyPHP\Http\SessionStoreInterface;
use MintyPHP\Module\Audit\Domain\SystemAuditOutcome;
use MintyPHP\Service\Security\RateLimiterService;
use MintyPHP\Service\Settings\SettingsFrontendTelemetryGateway;

View File

@@ -3,7 +3,7 @@
namespace MintyPHP\Module\Audit\Service;
use MintyPHP\Module\Audit\Domain\ImportAuditStatus;
use MintyPHP\Module\Audit\Repository\ImportAuditRunRepositoryInterface;
use MintyPHP\Module\Audit\Repository\ImportAuditRunRepository;
use MintyPHP\Repository\Support\RepoQuery;
use MintyPHP\Service\Audit\ImportAuditInterface;
@@ -16,7 +16,7 @@ class ImportAuditService implements ImportAuditInterface
*/
private array $startedAtByRunId = [];
public function __construct(private readonly ImportAuditRunRepositoryInterface $importAuditRunRepository)
public function __construct(private readonly ImportAuditRunRepository $importAuditRunRepository)
{
}

View File

@@ -2,12 +2,12 @@
namespace MintyPHP\Module\Audit\Service;
use MintyPHP\Module\Audit\Domain\SystemAuditChannel;
use MintyPHP\Module\Audit\Domain\SystemAuditOutcome;
use MintyPHP\Http\ApiAuth;
use MintyPHP\Http\RequestContext;
use MintyPHP\Http\SessionStoreInterface;
use MintyPHP\Module\Audit\Repository\SystemAuditLogRepositoryInterface;
use MintyPHP\Module\Audit\Domain\SystemAuditChannel;
use MintyPHP\Module\Audit\Domain\SystemAuditOutcome;
use MintyPHP\Module\Audit\Repository\SystemAuditLogRepository;
use MintyPHP\Repository\Support\RepoQuery;
use MintyPHP\Service\Audit\AuditRecorderInterface;
use MintyPHP\Service\Settings\SettingsSystemAuditGateway;
@@ -19,7 +19,7 @@ class SystemAuditService implements AuditRecorderInterface
private const RETENTION_DAYS_FALLBACK = 365;
public function __construct(
private readonly SystemAuditLogRepositoryInterface $systemAuditLogRepository,
private readonly SystemAuditLogRepository $systemAuditLogRepository,
private readonly SystemAuditRedactionService $systemAuditRedactionService,
private readonly SettingsSystemAuditGateway $settingsSystemAuditGateway,
private readonly SessionStoreInterface $sessionStore

View File

@@ -5,7 +5,7 @@ namespace MintyPHP\Module\Audit\Service;
use MintyPHP\Module\Audit\Domain\UserLifecycleAction;
use MintyPHP\Module\Audit\Domain\UserLifecycleStatus;
use MintyPHP\Module\Audit\Domain\UserLifecycleTriggerType;
use MintyPHP\Module\Audit\Repository\UserLifecycleAuditRepositoryInterface;
use MintyPHP\Module\Audit\Repository\UserLifecycleAuditRepository;
use MintyPHP\Service\Audit\UserLifecycleAuditInterface;
use MintyPHP\Support\Crypto;
@@ -43,7 +43,7 @@ class UserLifecycleAuditService implements UserLifecycleAuditInterface
'active_changed_at',
];
public function __construct(private readonly UserLifecycleAuditRepositoryInterface $userLifecycleAuditRepository)
public function __construct(private readonly UserLifecycleAuditRepository $userLifecycleAuditRepository)
{
}