Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ApiLoggingMode
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
6
100.00% covered (success)
100.00%
1 / 1
 shouldCapturePayload
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
6
1<?php
2
3declare(strict_types=1);
4
5/** @license For full copyright and license information, please see the LICENSE.md file. */
6
7namespace App\Core\Api\Domain\Model;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11/**
12 * API Request Logging Modes.
13 *
14 * Defines the detail level for logging API requests (OWASP / NIST AU-3).
15 * - STANDARD: Logs only request metadata (fastest, lowest storage).
16 * - FULL: Always logs metadata, sanitized headers, and payloads.
17 * - SMART_HYBRID: Logs metadata for normal requests, automatically captures full dump on error (>=400) or slow.
18 *
19 * @package App\Core\Api\Domain\Model
20 */
21enum ApiLoggingMode: string
22{
23    case STANDARD = 'standard';
24    case FULL = 'full';
25    case SMART_HYBRID = 'smart_hybrid';
26
27    /**
28     * Determines whether full payload dump should be captured for a given request result.
29     *
30     * @param int   $statusCode Response HTTP status code.
31     * @param float $durationMs Request execution time in milliseconds.
32     * @param float $slowThresholdMs Threshold above which request is considered slow.
33     * @return bool True if full payload dump should be recorded.
34     */
35    public function shouldCapturePayload(int $statusCode, float $durationMs, float $slowThresholdMs = 500.0): bool
36    {
37        return match ($this) {
38            self::FULL => true,
39            self::STANDARD => false,
40            self::SMART_HYBRID => $statusCode >= 400 || $statusCode === 0 || $durationMs >= $slowThresholdMs,
41        };
42    }
43}