| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
/** |
| 8 |
* Immutable record of a match that was found and then rejected for scoring |
| 9 |
* under the auto-redirect threshold. |
| 10 |
* |
| 11 |
* A near miss is the answer to "why was this URL captured instead of |
| 12 |
* redirected?". The matching engines already compute it on every 404 with |
| 13 |
* automatic redirects on; without somewhere to put it the number was discarded |
| 14 |
* on the losing branch and the captured row stored score = NULL. |
| 15 |
* |
| 16 |
* Score and engine travel together because they are only meaningful together: |
| 17 |
* "48" means nothing without "spell check" to say what produced it, and they |
| 18 |
* are persisted as a pair on the redirect row (the `score` and `engine` |
| 19 |
* columns), exactly as they are for an automatic redirect. |
| 20 |
* |
| 21 |
* The matched destination (id/type) is deliberately NOT carried. A captured |
| 22 |
* row's type/final_dest mean "no destination, the 404 page was shown"; writing |
| 23 |
* a suggested destination into them would silently promote a captured URL into |
| 24 |
* a live redirect nobody approved. |
| 25 |
* |
| 26 |
* // allow-no-test-found: exercised by CapturedRedirectNearMissScoreTest |
| 27 |
*/ |
| 28 |
final class ABJ_404_Solution_NearMissMatch { |
| 29 |
|
| 30 |
/** @var float */ |
| 31 |
private $score; |
| 32 |
|
| 33 |
/** @var string */ |
| 34 |
private $engineName; |
| 35 |
|
| 36 |
/** |
| 37 |
* @param float $score |
| 38 |
* @param string $engineName |
| 39 |
*/ |
| 40 |
private function __construct($score, $engineName) { |
| 41 |
$this->score = (float)$score; |
| 42 |
$this->engineName = (string)$engineName; |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* @param float $score Match confidence, on the same 0-100 scale as the |
| 47 |
* score stored for an automatic redirect. |
| 48 |
* @param string $engineName Name of the matching engine that scored it. |
| 49 |
* @return self |
| 50 |
*/ |
| 51 |
public static function create(float $score, string $engineName): self { |
| 52 |
return new self($score, $engineName); |
| 53 |
} |
| 54 |
|
| 55 |
/** @return float */ |
| 56 |
public function getScore(): float { |
| 57 |
return $this->score; |
| 58 |
} |
| 59 |
|
| 60 |
/** @return string */ |
| 61 |
public function getEngineName(): string { |
| 62 |
return $this->engineName; |
| 63 |
} |
| 64 |
} |
| 65 |
|