| Total Complexity | 5 |
| Total Lines | 55 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | class Node |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * @var string |
||
| 15 | */ |
||
| 16 | public $data; |
||
| 17 | /** |
||
| 18 | * @var Node|null |
||
| 19 | */ |
||
| 20 | public $next; |
||
| 21 | /** |
||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | public $key; |
||
| 25 | /** |
||
| 26 | * @var DateTime |
||
| 27 | */ |
||
| 28 | protected $expiredAt; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Node constructor. |
||
| 32 | * @param string $key |
||
| 33 | * @param string $data |
||
| 34 | * @param DateTime $expiredAt |
||
| 35 | */ |
||
| 36 | 12 | public function __construct(string $key, string $data, DateTime $expiredAt = null) |
|
| 37 | { |
||
| 38 | 12 | $this->key = $key; |
|
| 39 | 12 | $this->data = $data; |
|
| 40 | 12 | $this->expiredAt = $expiredAt; |
|
| 41 | 12 | } |
|
| 42 | |||
| 43 | /** |
||
| 44 | * @param null|string $default |
||
| 45 | * @return string|null |
||
| 46 | * @throws \Exception |
||
| 47 | */ |
||
| 48 | 9 | public function getData($default = null): ?string |
|
| 49 | { |
||
| 50 | 9 | if ($this->isExpired()) { |
|
| 51 | 3 | return $default; |
|
| 52 | } |
||
| 53 | 6 | return $this->data; |
|
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @return bool |
||
| 58 | * @throws \Exception |
||
| 59 | */ |
||
| 60 | 9 | public function isExpired(): bool |
|
| 66 | } |
||
| 67 | } |
||
| 68 |