| 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 list of analysis features. |
| 8 |
*/ |
| 9 |
class Analysis_Features_List { |
| 10 |
|
| 11 |
/** |
| 12 |
* The features. |
| 13 |
* |
| 14 |
* @var array<Analysis_Feature> |
| 15 |
*/ |
| 16 |
private $features = []; |
| 17 |
|
| 18 |
/** |
| 19 |
* Adds an analysis feature to the list. |
| 20 |
* |
| 21 |
* @param Analysis_Feature $feature The analysis feature to add. |
| 22 |
* |
| 23 |
* @return void |
| 24 |
*/ |
| 25 |
public function add_feature( Analysis_Feature $feature ): void { |
| 26 |
$this->features[] = $feature; |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Parses the feature list to a legacy ready array representation. |
| 31 |
* |
| 32 |
* @return array<string, bool> The list presented as a key value representation. |
| 33 |
*/ |
| 34 |
public function parse_to_legacy_array(): array { |
| 35 |
$array = []; |
| 36 |
foreach ( $this->features as $feature ) { |
| 37 |
$array = \array_merge( $array, $feature->to_legacy_array() ); |
| 38 |
} |
| 39 |
|
| 40 |
return $array; |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Parses the feature list to an array representation. |
| 45 |
* |
| 46 |
* @return array<string, bool> The list presented as a key value representation. |
| 47 |
*/ |
| 48 |
public function to_array(): array { |
| 49 |
$array = []; |
| 50 |
foreach ( $this->features as $feature ) { |
| 51 |
$array = \array_merge( $array, $feature->to_array() ); |
| 52 |
} |
| 53 |
|
| 54 |
return $array; |
| 55 |
} |
| 56 |
} |
| 57 |
|