PluginProbe
404 Solution / trunk
404 Solution vtrunk
4.3.5 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.2.0 4.1.19 4.1.18 4.1.17 4.1.16 4.1.15 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.1.7 4.1.6 4.1.5 4.1.4 4.1.3 trunk 2.30.0 All 109 releases
404-solution / includes / matching / MatchResult.php

MatchResult.php in 404 Solution trunk, at includes/matching/MatchResult.php

103 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) {
4 exit;
5 }
6
7 /**
8 * Value object representing a successful match from a matching engine.
9 *
10 * Immutable after construction. Provides toLegacyArray() for backward compatibility
11 * with code that expects the old associative array shape.
12 */
13 class ABJ_404_Solution_MatchResult {
14
15 /** @var string */
16 private $id;
17
18 /** @var string */
19 private $type;
20
21 /** @var string */
22 private $link;
23
24 /** @var string */
25 private $title;
26
27 /** @var float */
28 private $score;
29
30 /** @var string */
31 private $engineName;
32
33 /**
34 * @param string $id Post/page ID
35 * @param string $type Content type (ABJ404_TYPE_POST, etc.)
36 * @param string $link Permalink URL
37 * @param string $title Post/page title
38 * @param float $score Match confidence score
39 * @param string $engineName Name of the engine that produced this result
40 */
41 public function __construct(
42 string $id,
43 string $type,
44 string $link,
45 string $title,
46 float $score,
47 string $engineName
48 ) {
49 $this->id = $id;
50 $this->type = $type;
51 $this->link = $link;
52 $this->title = $title;
53 $this->score = $score;
54 $this->engineName = $engineName;
55 }
56
57 /** @return string */
58 public function getId(): string {
59 return $this->id;
60 }
61
62 /** @return string */
63 public function getType(): string {
64 return $this->type;
65 }
66
67 /** @return string */
68 public function getLink(): string {
69 return $this->link;
70 }
71
72 /** @return string */
73 public function getTitle(): string {
74 return $this->title;
75 }
76
77 /** @return float */
78 public function getScore(): float {
79 return $this->score;
80 }
81
82 /** @return string */
83 public function getEngineName(): string {
84 return $this->engineName;
85 }
86
87 /**
88 * Convert to the legacy associative array used by existing pipeline code.
89 *
90 * @return array{id: string, type: string, link: string, title: string, score: float, engine: string}
91 */
92 public function toLegacyArray(): array {
93 return [
94 'id' => $this->id,
95 'type' => $this->type,
96 'link' => $this->link,
97 'title' => $this->title,
98 'score' => $this->score,
99 'engine' => $this->engineName,
100 ];
101 }
102 }
103