maxExceptions < 1) { throw new \InvalidArgumentException('maxExceptions must be at least 1'); } } /** * Create default configuration */ public static function default(): self { return new self(); } /** * Create configuration with custom limits */ public static function withLimits(int $maxExceptions, Duration $timeWindow): self { return new self( maxExceptions: $maxExceptions, timeWindow: $timeWindow ); } /** * Create disabled configuration */ public static function disabled(): self { return new self(enabled: false); } /** * Create new instance with different max exceptions */ public function withMaxExceptions(int $maxExceptions): self { return new self( maxExceptions: $maxExceptions, timeWindow: $this->timeWindow, enabled: $this->enabled, skipLoggingOnLimit: $this->skipLoggingOnLimit, skipAuditOnLimit: $this->skipAuditOnLimit, trackMetricsOnLimit: $this->trackMetricsOnLimit ); } /** * Create new instance with different time window */ public function withTimeWindow(Duration $timeWindow): self { return new self( maxExceptions: $this->maxExceptions, timeWindow: $timeWindow, enabled: $this->enabled, skipLoggingOnLimit: $this->skipLoggingOnLimit, skipAuditOnLimit: $this->skipAuditOnLimit, trackMetricsOnLimit: $this->trackMetricsOnLimit ); } /** * Create new instance with enabled/disabled state */ public function withEnabled(bool $enabled): self { return new self( maxExceptions: $this->maxExceptions, timeWindow: $this->timeWindow, enabled: $enabled, skipLoggingOnLimit: $this->skipLoggingOnLimit, skipAuditOnLimit: $this->skipAuditOnLimit, trackMetricsOnLimit: $this->trackMetricsOnLimit ); } }