severity = $severity ?? self::getSeverityForEvent($name); } /** * Create a security event with common parameters */ public static function create( string $name, ?string $ipAddress = null, ?string $deviceFingerprint = null, array $data = [], ?string $tenantId = null, ?string $identityId = null, ?string $userAgent = null, ?string $requestPath = null, ?string $requestMethod = null, ?string $userId = null, ?string $reason = null, ?int $severity = null, ): self { return new self( $name, $data, $tenantId, $identityId, $ipAddress, $deviceFingerprint, $userAgent, $requestPath, $requestMethod, $userId, $reason, $severity, ); } /** * Get default severity for event types */ private static function getSeverityForEvent(string $eventName): int { return match ($eventName) { self::ACCESS_GRANTED, self::TOKEN_REFRESH => self::SEVERITY_INFO, self::AUTH_LOGOUT, self::TOKEN_REVOKED => self::SEVERITY_WARNING, self::IP_BLOCKED, self::DEVICE_BLOCKED => self::SEVERITY_CRITICAL, default => self::SEVERITY_INFO, }; } // Getters and setters public function getIpAddress(): ?string { return $this->ipAddress; } public function getDeviceFingerprint(): ?string { return $this->deviceFingerprint; } public function getUserAgent(): ?string { return $this->userAgent; } public function getRequestPath(): ?string { return $this->requestPath; } public function getRequestMethod(): ?string { return $this->requestMethod; } public function getUserId(): ?string { return $this->userId; } public function getReason(): ?string { return $this->reason; } public function getSeverity(): int { return $this->severity; } }