Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
15 / 15 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| SearchResult | |
100.00% |
14 / 14 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| jsonSerialize | |
100.00% |
13 / 13 |
|
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\Core\Search\Domain\Model; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | use JsonSerializable; |
| 12 | |
| 13 | /** |
| 14 | * Search Result Value Object. |
| 15 | * |
| 16 | * Represents an individual matched record in global search. |
| 17 | * |
| 18 | * @package App\Core\Search\Domain\Model |
| 19 | */ |
| 20 | final readonly class SearchResult implements JsonSerializable |
| 21 | { |
| 22 | /** |
| 23 | * SearchResult constructor. |
| 24 | * |
| 25 | * @param int $id Record primary key identifier. |
| 26 | * @param string $moduleName Target module machine name. |
| 27 | * @param string $moduleLabel Target module display label. |
| 28 | * @param string $iconClass Bootstrap icon CSS class. |
| 29 | * @param string $title Display title for the record. |
| 30 | * @param string $matchedField Field key where match was found. |
| 31 | * @param string $matchedFieldLabel Human-readable field label. |
| 32 | * @param string $snippet Contextual excerpt with match. |
| 33 | * @param string $url Direct URL to detail view. |
| 34 | * @param float $score Relevance ranking score. |
| 35 | * @param string|null $updatedAt Record modification timestamp. |
| 36 | */ |
| 37 | public function __construct( |
| 38 | public int $id, |
| 39 | public string $moduleName, |
| 40 | public string $moduleLabel, |
| 41 | public string $iconClass, |
| 42 | public string $title, |
| 43 | public string $matchedField, |
| 44 | public string $matchedFieldLabel, |
| 45 | public string $snippet, |
| 46 | public string $url, |
| 47 | public float $score = 1.0, |
| 48 | public ?string $updatedAt = null |
| 49 | ) { |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Serializes result object to array for JSON responses. |
| 54 | * |
| 55 | * @return array<string, mixed> Serialized data. |
| 56 | */ |
| 57 | public function jsonSerialize(): array |
| 58 | { |
| 59 | return [ |
| 60 | 'id' => $this->id, |
| 61 | 'module_name' => $this->moduleName, |
| 62 | 'module_label' => $this->moduleLabel, |
| 63 | 'icon_class' => $this->iconClass, |
| 64 | 'title' => $this->title, |
| 65 | 'matched_field' => $this->matchedField, |
| 66 | 'matched_field_label' => $this->matchedFieldLabel, |
| 67 | 'snippet' => $this->snippet, |
| 68 | 'url' => $this->url, |
| 69 | 'score' => $this->score, |
| 70 | 'updated_at' => $this->updatedAt, |
| 71 | ]; |
| 72 | } |
| 73 | } |