Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
50.00% covered (danger)
50.00%
1 / 2
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ApiLogEntry
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
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
11use DateTimeImmutable;
12
13/**
14 * API Request Log Entry Value Object.
15 *
16 * Immutable representation of an API request metadata record (NIST AU-3 / OWASP ASVS V7.1).
17 *
18 * @package App\Core\Api\Domain\Model
19 */
20final readonly class ApiLogEntry
21{
22    /**
23     * ApiLogEntry constructor.
24     *
25     * @param string                 $requestId        Correlation / trace ID.
26     * @param string                 $httpMethod       HTTP verb (GET, POST, etc.).
27     * @param string                 $routePattern     Normalized route template.
28     * @param string                 $requestUri       Complete request URI with query.
29     * @param int                    $statusCode       HTTP response status code.
30     * @param float                  $durationMs       Execution time in milliseconds.
31     * @param int                    $memoryPeakBytes  Peak RAM allocated in bytes.
32     * @param int                    $responseBytes    Response payload size in bytes.
33     * @param string                 $ipAddress        Client remote IP address.
34     * @param string                 $userAgent        Client User-Agent string.
35     * @param string                 $logLevel         Severity level ('info', 'warning', 'error', 'critical').
36     * @param bool                   $isSlow           Whether duration exceeded threshold.
37     * @param bool                   $isError          Whether status code >= 400.
38     * @param bool                   $isAborted        Whether connection was cancelled or timed out.
39     * @param bool                   $hasPayloadDump   Whether detailed payload was dumped.
40     * @param DateTimeImmutable      $createdAt        Timestamp of the request.
41     * @param int|null               $clientInstanceId SaaS client instance ID if available.
42     * @param int|null               $userId           Authenticated user ID if available.
43     * @param int|null               $apiKeyId         API key ID if token-authenticated.
44     * @param int|null               $id               Database primary key (null on creation).
45     */
46    public function __construct(
47        public string            $requestId,
48        public string            $httpMethod,
49        public string            $routePattern,
50        public string            $requestUri,
51        public int               $statusCode,
52        public float             $durationMs,
53        public int               $memoryPeakBytes,
54        public int               $responseBytes,
55        public string            $ipAddress,
56        public string            $userAgent = '',
57        public string            $logLevel = 'info',
58        public bool              $isSlow = false,
59        public bool              $isError = false,
60        public bool              $isAborted = false,
61        public bool              $hasPayloadDump = false,
62        public DateTimeImmutable $createdAt = new DateTimeImmutable(),
63        public ?int              $clientInstanceId = null,
64        public ?int              $userId = null,
65        public ?int              $apiKeyId = null,
66        public ?int              $id = null,
67    ) {
68    }
69}