| 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 Traffic record. |
| 10 |
*/ |
| 11 |
class Traffic_Data implements Data_Interface { |
| 12 |
|
| 13 |
/** |
| 14 |
* The sessions, if any. |
| 15 |
* |
| 16 |
* @var int|null |
| 17 |
*/ |
| 18 |
private $sessions; |
| 19 |
|
| 20 |
/** |
| 21 |
* The total users, if any. |
| 22 |
* |
| 23 |
* @var int|null |
| 24 |
*/ |
| 25 |
private $total_users; |
| 26 |
|
| 27 |
/** |
| 28 |
* The array representation of this domain object. |
| 29 |
* |
| 30 |
* @return array<string, int> |
| 31 |
*/ |
| 32 |
public function to_array(): array { |
| 33 |
$result = []; |
| 34 |
|
| 35 |
if ( $this->sessions !== null ) { |
| 36 |
$result['sessions'] = $this->sessions; |
| 37 |
} |
| 38 |
|
| 39 |
if ( $this->total_users !== null ) { |
| 40 |
$result['total_users'] = $this->total_users; |
| 41 |
} |
| 42 |
|
| 43 |
return $result; |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Sets the sessions. |
| 48 |
* |
| 49 |
* @param int $sessions The sessions. |
| 50 |
* |
| 51 |
* @return void |
| 52 |
*/ |
| 53 |
public function set_sessions( int $sessions ): void { |
| 54 |
$this->sessions = $sessions; |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Sets the total users. |
| 59 |
* |
| 60 |
* @param int $total_users The total users. |
| 61 |
* |
| 62 |
* @return void |
| 63 |
*/ |
| 64 |
public function set_total_users( int $total_users ): void { |
| 65 |
$this->total_users = $total_users; |
| 66 |
} |
| 67 |
} |
| 68 |
|