Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
27 / 27 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| CommentMentionItemDto | |
100.00% |
26 / 26 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toArray | |
100.00% |
24 / 24 |
|
100.00% |
1 / 1 |
1 | |||
| jsonSerialize | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** @license For full copyright and license information, please see the LICENSE.md file. */ |
| 6 | |
| 7 | namespace App\Modules\Comments\Application\DTO; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | use JsonSerializable; |
| 12 | |
| 13 | /** |
| 14 | * Data transfer object representing a single comment mention on the timeline. |
| 15 | * |
| 16 | * @package App\Modules\Comments\Application\DTO |
| 17 | */ |
| 18 | final readonly class CommentMentionItemDto implements JsonSerializable |
| 19 | { |
| 20 | /** |
| 21 | * CommentMentionItemDto constructor. |
| 22 | */ |
| 23 | public function __construct( |
| 24 | public int $id, |
| 25 | public string $content, |
| 26 | public string $formattedContent, |
| 27 | public string $createdAt, |
| 28 | public string $createdAtRelative, |
| 29 | public int $authorId, |
| 30 | public string $authorName, |
| 31 | public ?string $authorAvatar, |
| 32 | public bool $isRead, |
| 33 | public string $targetModule, |
| 34 | public int $targetRecordId, |
| 35 | public string $targetRecordTitle, |
| 36 | public ?int $companyId = null, |
| 37 | public ?string $companyTitle = null, |
| 38 | public ?int $projectId = null, |
| 39 | public ?string $projectTitle = null, |
| 40 | public ?int $ticketId = null, |
| 41 | public ?string $ticketTitle = null, |
| 42 | public ?int $taskId = null, |
| 43 | public ?string $taskTitle = null, |
| 44 | public string $matchedMentionType = 'direct_user', |
| 45 | public string $matchedMentionLabel = '' |
| 46 | ) { |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Exports DTO state as associative array. |
| 51 | * |
| 52 | * @return array<string, mixed> |
| 53 | */ |
| 54 | public function toArray(): array |
| 55 | { |
| 56 | return [ |
| 57 | 'id' => $this->id, |
| 58 | 'content' => $this->content, |
| 59 | 'formatted_content' => $this->formattedContent, |
| 60 | 'created_at' => $this->createdAt, |
| 61 | 'created_at_relative' => $this->createdAtRelative, |
| 62 | 'author_id' => $this->authorId, |
| 63 | 'author_name' => $this->authorName, |
| 64 | 'author_avatar' => $this->authorAvatar, |
| 65 | 'is_read' => $this->isRead, |
| 66 | 'target_module' => $this->targetModule, |
| 67 | 'target_record_id' => $this->targetRecordId, |
| 68 | 'target_record_title' => $this->targetRecordTitle, |
| 69 | 'company_id' => $this->companyId, |
| 70 | 'company_title' => $this->companyTitle, |
| 71 | 'project_id' => $this->projectId, |
| 72 | 'project_title' => $this->projectTitle, |
| 73 | 'ticket_id' => $this->ticketId, |
| 74 | 'ticket_title' => $this->ticketTitle, |
| 75 | 'task_id' => $this->taskId, |
| 76 | 'task_title' => $this->taskTitle, |
| 77 | 'matched_mention_type' => $this->matchedMentionType, |
| 78 | 'matched_mention_label' => $this->matchedMentionLabel, |
| 79 | ]; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Serializes DTO to JSON. |
| 84 | * |
| 85 | * @return array<string, mixed> |
| 86 | */ |
| 87 | public function jsonSerialize(): array |
| 88 | { |
| 89 | return $this->toArray(); |
| 90 | } |
| 91 | } |