| 1 |
<?php |
| 2 |
|
| 3 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. |
| 4 |
namespace Yoast\WP\SEO\Dashboard\Domain\Score_Results; |
| 5 |
|
| 6 |
/** |
| 7 |
* This class describes a current score. |
| 8 |
*/ |
| 9 |
class Current_Score { |
| 10 |
|
| 11 |
/** |
| 12 |
* The name of the current score. |
| 13 |
* |
| 14 |
* @var string |
| 15 |
*/ |
| 16 |
private $name; |
| 17 |
|
| 18 |
/** |
| 19 |
* The amount of the current score. |
| 20 |
* |
| 21 |
* @var string |
| 22 |
*/ |
| 23 |
private $amount; |
| 24 |
|
| 25 |
/** |
| 26 |
* The ids of the current score. |
| 27 |
* |
| 28 |
* @var string|null |
| 29 |
*/ |
| 30 |
private $ids; |
| 31 |
|
| 32 |
/** |
| 33 |
* The links of the current score. |
| 34 |
* |
| 35 |
* @var array<string, string>|null |
| 36 |
*/ |
| 37 |
private $links; |
| 38 |
|
| 39 |
/** |
| 40 |
* The constructor. |
| 41 |
* |
| 42 |
* @param string $name The name of the current score. |
| 43 |
* @param int $amount The amount of the current score. |
| 44 |
* @param string|null $ids The ids of the current score. |
| 45 |
* @param array<string, string>|null $links The links of the current score. |
| 46 |
*/ |
| 47 |
public function __construct( string $name, int $amount, ?string $ids = null, ?array $links = null ) { |
| 48 |
$this->name = $name; |
| 49 |
$this->amount = $amount; |
| 50 |
$this->ids = $ids; |
| 51 |
$this->links = $links; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Gets name of the current score. |
| 56 |
* |
| 57 |
* @return string The name of the current score. |
| 58 |
*/ |
| 59 |
public function get_name(): string { |
| 60 |
return $this->name; |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Gets the amount of the current score. |
| 65 |
* |
| 66 |
* @return int The amount of the current score. |
| 67 |
*/ |
| 68 |
public function get_amount(): int { |
| 69 |
return $this->amount; |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Gets the ids of the current score. |
| 74 |
* |
| 75 |
* @return string|null The ids of the current score. |
| 76 |
*/ |
| 77 |
public function get_ids(): ?string { |
| 78 |
return $this->ids; |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Gets the links of the current score in the expected key value representation. |
| 83 |
* |
| 84 |
* @return array<string, string> The links of the current score in the expected key value representation. |
| 85 |
*/ |
| 86 |
public function get_links_to_array(): ?array { |
| 87 |
$links = []; |
| 88 |
|
| 89 |
if ( $this->links === null ) { |
| 90 |
return $links; |
| 91 |
} |
| 92 |
|
| 93 |
foreach ( $this->links as $key => $link ) { |
| 94 |
if ( $link === null ) { |
| 95 |
continue; |
| 96 |
} |
| 97 |
$links[ $key ] = $link; |
| 98 |
} |
| 99 |
return $links; |
| 100 |
} |
| 101 |
} |
| 102 |
|