Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
CommentMentionsInboxDto
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
3 / 3
3
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
 toArray
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
 jsonSerialize
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\Modules\Comments\Application\DTO;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11use JsonSerializable;
12
13/**
14 * Data transfer object encapsulating the full Mentions Inbox view state.
15 *
16 * @package App\Modules\Comments\Application\DTO
17 */
18final readonly class CommentMentionsInboxDto implements JsonSerializable
19{
20    /**
21     * CommentMentionsInboxDto constructor.
22     *
23     * @param array<int, CommentMentionItemDto> $items Mentions list.
24     * @param array<string, int>                $counts Counts by scope tab.
25     */
26    public function __construct(
27        public array $items,
28        public string $scope,
29        public array $counts,
30        public int $unreadCount,
31        public string $searchQuery = '',
32        public ?string $watermarkAt = null
33    ) {
34    }
35
36    /**
37     * Exports DTO state as associative array.
38     *
39     * @return array<string, mixed>
40     */
41    public function toArray(): array
42    {
43        return [
44            'items'        => array_map(static fn(CommentMentionItemDto $i): array => $i->toArray(), $this->items),
45            'scope'        => $this->scope,
46            'counts'       => $this->counts,
47            'unread_count' => $this->unreadCount,
48            'search_query' => $this->searchQuery,
49            'watermark_at' => $this->watermarkAt,
50        ];
51    }
52
53    /**
54     * Serializes DTO to JSON.
55     *
56     * @return array<string, mixed>
57     */
58    public function jsonSerialize(): array
59    {
60        return $this->toArray();
61    }
62}