| 1 |
<?php |
| 2 |
|
| 3 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. |
| 4 |
namespace Yoast\WP\SEO\Abilities\Domain; |
| 5 |
|
| 6 |
/** |
| 7 |
* Immutable value object representing a score result. |
| 8 |
*/ |
| 9 |
class Score_Result { |
| 10 |
|
| 11 |
/** |
| 12 |
* The post title. |
| 13 |
* |
| 14 |
* @var string |
| 15 |
*/ |
| 16 |
private $title; |
| 17 |
|
| 18 |
/** |
| 19 |
* The score slug (na, bad, ok, good). |
| 20 |
* |
| 21 |
* @var string |
| 22 |
*/ |
| 23 |
private $score; |
| 24 |
|
| 25 |
/** |
| 26 |
* The translated human-readable label. |
| 27 |
* |
| 28 |
* @var string |
| 29 |
*/ |
| 30 |
private $label; |
| 31 |
|
| 32 |
/** |
| 33 |
* Constructor. |
| 34 |
* |
| 35 |
* @param string $title The post title. |
| 36 |
* @param string $score The score slug. |
| 37 |
* @param string $label The translated human-readable label. |
| 38 |
*/ |
| 39 |
public function __construct( string $title, string $score, string $label ) { |
| 40 |
$this->title = $title; |
| 41 |
$this->score = $score; |
| 42 |
$this->label = $label; |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Serializes the score result to an array for ability output. |
| 47 |
* |
| 48 |
* @return array<string, string> The serialized score result. |
| 49 |
*/ |
| 50 |
public function to_array(): array { |
| 51 |
return [ |
| 52 |
'title' => $this->title, |
| 53 |
'score' => $this->score, |
| 54 |
'label' => $this->label, |
| 55 |
]; |
| 56 |
} |
| 57 |
} |
| 58 |
|