Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
91.67% |
11 / 12 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| CommentStreamDto | |
90.91% |
10 / 11 |
|
66.67% |
2 / 3 |
3.01 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toArray | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 | |||
| jsonSerialize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 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 App\Modules\Comments\Domain\Model\Comment; |
| 12 | use App\Modules\Comments\Domain\Model\CommentFilterScope; |
| 13 | use JsonSerializable; |
| 14 | |
| 15 | /** |
| 16 | * Data transfer object encapsulating a loaded comment stream with filter counts. |
| 17 | * |
| 18 | * @package App\Modules\Comments\Application\DTO |
| 19 | */ |
| 20 | final readonly class CommentStreamDto implements JsonSerializable |
| 21 | { |
| 22 | /** |
| 23 | * CommentStreamDto constructor. |
| 24 | * |
| 25 | * @param array<int, Comment> $comments |
| 26 | * @param array{all: int, mine: int, pinned: int, verified: int} $counts |
| 27 | */ |
| 28 | public function __construct( |
| 29 | public array $comments, |
| 30 | public CommentFilterScope $scope, |
| 31 | public array $counts, |
| 32 | public int $totalCount, |
| 33 | public string $targetModule, |
| 34 | public int $targetRecordId, |
| 35 | public ?int $currentUserId |
| 36 | ) { |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Exports DTO state as associative array. |
| 41 | * |
| 42 | * @return array<string, mixed> |
| 43 | */ |
| 44 | public function toArray(): array |
| 45 | { |
| 46 | return [ |
| 47 | 'comments' => array_map(static fn(Comment $c): array => $c->toArray(), $this->comments), |
| 48 | 'scope' => $this->scope->value, |
| 49 | 'counts' => $this->counts, |
| 50 | 'total_count' => $this->totalCount, |
| 51 | 'target_module' => $this->targetModule, |
| 52 | 'target_record_id' => $this->targetRecordId, |
| 53 | 'current_user_id' => $this->currentUserId, |
| 54 | ]; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Serializes DTO to JSON. |
| 59 | * |
| 60 | * @return array<string, mixed> |
| 61 | */ |
| 62 | public function jsonSerialize(): array |
| 63 | { |
| 64 | return $this->toArray(); |
| 65 | } |
| 66 | } |