| 1 |
<?php |
| 2 |
|
| 3 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. |
| 4 |
namespace Yoast\WP\SEO\Editors\Domain\Analysis_Features; |
| 5 |
|
| 6 |
/** |
| 7 |
* This class describes a single Analysis feature and if it is enabled. |
| 8 |
*/ |
| 9 |
class Analysis_Feature { |
| 10 |
|
| 11 |
/** |
| 12 |
* If the feature is enabled. |
| 13 |
* |
| 14 |
* @var bool |
| 15 |
*/ |
| 16 |
private $is_enabled; |
| 17 |
|
| 18 |
/** |
| 19 |
* What the identifier of the feature is. |
| 20 |
* |
| 21 |
* @var string |
| 22 |
*/ |
| 23 |
private $name; |
| 24 |
|
| 25 |
/** |
| 26 |
* What the identifier is for the old script data array. |
| 27 |
* |
| 28 |
* @var string |
| 29 |
*/ |
| 30 |
private $legacy_key; |
| 31 |
|
| 32 |
/** |
| 33 |
* The constructor. |
| 34 |
* |
| 35 |
* @param bool $is_enabled If the feature is enabled. |
| 36 |
* @param string $name What the identifier of the feature is. |
| 37 |
* @param string $legacy_key What the identifier is for the old script data array. |
| 38 |
*/ |
| 39 |
public function __construct( bool $is_enabled, string $name, string $legacy_key ) { |
| 40 |
$this->is_enabled = $is_enabled; |
| 41 |
$this->name = $name; |
| 42 |
$this->legacy_key = $legacy_key; |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* If the feature is enabled. |
| 47 |
* |
| 48 |
* @return bool If the feature is enabled. |
| 49 |
*/ |
| 50 |
public function is_enabled(): bool { |
| 51 |
return $this->is_enabled; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Gets the identifier. |
| 56 |
* |
| 57 |
* @return string The feature identifier. |
| 58 |
*/ |
| 59 |
public function get_name(): string { |
| 60 |
return $this->name; |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Return this object represented by a key value array. |
| 65 |
* |
| 66 |
* @return array<string, bool> Returns the name and if the feature is enabled. |
| 67 |
*/ |
| 68 |
public function to_array(): array { |
| 69 |
return [ $this->name => $this->is_enabled ]; |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Returns this object represented by a key value structure that is compliant with the script data array. |
| 74 |
* |
| 75 |
* @return array<string, bool> Returns the legacy key and if the feature is enabled. |
| 76 |
*/ |
| 77 |
public function to_legacy_array(): array { |
| 78 |
return [ $this->legacy_key => $this->is_enabled ]; |
| 79 |
} |
| 80 |
} |
| 81 |
|