| 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 Daily Traffic record. |
| 10 |
*/ |
| 11 |
class Daily_Traffic_Data implements Data_Interface { |
| 12 |
|
| 13 |
/** |
| 14 |
* The date of the traffic data, in YYYYMMDD format. |
| 15 |
* |
| 16 |
* @var string |
| 17 |
*/ |
| 18 |
private $date; |
| 19 |
|
| 20 |
/** |
| 21 |
* The traffic data for the date. |
| 22 |
* |
| 23 |
* @var Traffic_Data |
| 24 |
*/ |
| 25 |
private $traffic_data; |
| 26 |
|
| 27 |
/** |
| 28 |
* The constructor. |
| 29 |
* |
| 30 |
* @param string $date The date of the traffic data, in YYYYMMDD format. |
| 31 |
* @param Traffic_Data $traffic_data The traffic data for the date. |
| 32 |
*/ |
| 33 |
public function __construct( string $date, Traffic_Data $traffic_data ) { |
| 34 |
$this->date = $date; |
| 35 |
$this->traffic_data = $traffic_data; |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* The array representation of this domain object. |
| 40 |
* |
| 41 |
* @return array<string, string|int> |
| 42 |
*/ |
| 43 |
public function to_array(): array { |
| 44 |
$result = []; |
| 45 |
$result['date'] = $this->date; |
| 46 |
|
| 47 |
return \array_merge( $result, $this->traffic_data->to_array() ); |
| 48 |
} |
| 49 |
} |
| 50 |
|