| Total Complexity | 9 |
| Total Lines | 63 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 19 | class ApiKey extends AbstractEntity |
||
| 20 | { |
||
| 21 | use StringUtilsTrait; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var string |
||
| 25 | * @ORM\Column(name="`key`", nullable=false, unique=true) |
||
| 26 | */ |
||
| 27 | private $key; |
||
| 28 | /** |
||
| 29 | * @var Chronos|null |
||
| 30 | * @ORM\Column(name="expiration_date", nullable=true, type="chronos_datetime") |
||
| 31 | */ |
||
| 32 | private $expirationDate; |
||
| 33 | /** |
||
| 34 | * @var bool |
||
| 35 | * @ORM\Column(type="boolean") |
||
| 36 | */ |
||
| 37 | private $enabled; |
||
| 38 | |||
| 39 | 13 | public function __construct(?Chronos $expirationDate = null) |
|
| 40 | { |
||
| 41 | 13 | $this->key = $this->generateV4Uuid(); |
|
| 42 | 13 | $this->expirationDate = $expirationDate; |
|
| 43 | 13 | $this->enabled = true; |
|
| 44 | 13 | } |
|
| 45 | |||
| 46 | 4 | public function getExpirationDate(): ?Chronos |
|
| 47 | { |
||
| 48 | 4 | return $this->expirationDate; |
|
| 49 | } |
||
| 50 | |||
| 51 | 5 | public function isExpired(): bool |
|
| 58 | } |
||
| 59 | |||
| 60 | 8 | public function isEnabled(): bool |
|
| 61 | { |
||
| 62 | 8 | return $this->enabled; |
|
| 63 | } |
||
| 64 | |||
| 65 | 3 | public function disable(): self |
|
| 69 | } |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Tells if this api key is enabled and not expired |
||
| 73 | */ |
||
| 74 | 5 | public function isValid(): bool |
|
| 77 | } |
||
| 78 | |||
| 79 | 4 | public function __toString(): string |
|
| 82 | } |
||
| 83 | } |
||
| 84 |