| 1 |
<?php |
| 2 |
|
| 3 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. |
| 4 |
namespace Yoast\WP\SEO\Dashboard\Domain\Traffic; |
| 5 |
|
| 6 |
use Yoast\WP\SEO\Dashboard\Domain\Data_Provider\Data_Interface; |
| 7 |
|
| 8 |
/** |
| 9 |
* Domain object that represents a single Comparison Traffic record. |
| 10 |
*/ |
| 11 |
class Comparison_Traffic_Data implements Data_Interface { |
| 12 |
|
| 13 |
public const CURRENT_PERIOD_KEY = 'current'; |
| 14 |
public const PREVIOUS_PERIOD_KEY = 'previous'; |
| 15 |
|
| 16 |
/** |
| 17 |
* The current traffic data. |
| 18 |
* |
| 19 |
* @var Traffic_Data |
| 20 |
*/ |
| 21 |
private $current_traffic_data; |
| 22 |
|
| 23 |
/** |
| 24 |
* The previous traffic data. |
| 25 |
* |
| 26 |
* @var Traffic_Data |
| 27 |
*/ |
| 28 |
private $previous_traffic_data; |
| 29 |
|
| 30 |
/** |
| 31 |
* The constructor. |
| 32 |
* |
| 33 |
* @param Traffic_Data $current_traffic_data The current traffic data. |
| 34 |
* @param Traffic_Data $previous_traffic_data The previous traffic data. |
| 35 |
*/ |
| 36 |
public function __construct( ?Traffic_Data $current_traffic_data = null, ?Traffic_Data $previous_traffic_data = null ) { |
| 37 |
$this->current_traffic_data = $current_traffic_data; |
| 38 |
$this->previous_traffic_data = $previous_traffic_data; |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Sets the current traffic data. |
| 43 |
* |
| 44 |
* @param Traffic_Data $current_traffic_data The current traffic data. |
| 45 |
* |
| 46 |
* @return void |
| 47 |
*/ |
| 48 |
public function set_current_traffic_data( Traffic_Data $current_traffic_data ): void { |
| 49 |
$this->current_traffic_data = $current_traffic_data; |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Sets the previous traffic data. |
| 54 |
* |
| 55 |
* @param Traffic_Data $previous_traffic_data The previous traffic data. |
| 56 |
* |
| 57 |
* @return void |
| 58 |
*/ |
| 59 |
public function set_previous_traffic_data( Traffic_Data $previous_traffic_data ): void { |
| 60 |
$this->previous_traffic_data = $previous_traffic_data; |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* The array representation of this domain object. |
| 65 |
* |
| 66 |
* @return array<string|float|int|string[]> |
| 67 |
*/ |
| 68 |
public function to_array(): array { |
| 69 |
return [ |
| 70 |
'current' => $this->current_traffic_data->to_array(), |
| 71 |
'previous' => $this->previous_traffic_data->to_array(), |
| 72 |
]; |
| 73 |
} |
| 74 |
} |
| 75 |
|