Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
SearchResultGroup
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
2 / 2
2
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
 jsonSerialize
100.00% covered (success)
100.00%
8 / 8
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\Search\Domain\Model;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11use JsonSerializable;
12
13/**
14 * Search Result Group Value Object.
15 *
16 * Groups results belonging to a single module with totals.
17 *
18 * @package App\Core\Search\Domain\Model
19 */
20final readonly class SearchResultGroup implements JsonSerializable
21{
22    /**
23     * SearchResultGroup constructor.
24     *
25     * @param string             $moduleName  Module machine name.
26     * @param string             $moduleLabel Module display label.
27     * @param string             $iconClass   Module icon CSS class.
28     * @param int                $totalCount  Total matching records in module.
29     * @param list<SearchResult> $results     List of search result items.
30     */
31    public function __construct(
32        public string $moduleName,
33        public string $moduleLabel,
34        public string $iconClass,
35        public int $totalCount,
36        public array $results
37    ) {
38    }
39
40    /**
41     * Serializes result group to array for JSON responses.
42     *
43     * @return array<string, mixed> Serialized data.
44     */
45    public function jsonSerialize(): array
46    {
47        return [
48            'module_name'  => $this->moduleName,
49            'module_label' => $this->moduleLabel,
50            'icon_class'   => $this->iconClass,
51            'total_count'  => $this->totalCount,
52            'count'        => count($this->results),
53            'results'      => $this->results,
54        ];
55    }
56}