1 | <?php |
||
23 | final class UserToken |
||
24 | { |
||
25 | /** |
||
26 | * The id in a primitive type. |
||
27 | * |
||
28 | * @var string|int |
||
29 | */ |
||
30 | private $token; |
||
31 | |||
32 | /** |
||
33 | * The created on. |
||
34 | * |
||
35 | * @var \DateTimeImmutable |
||
36 | */ |
||
37 | private $createdOn; |
||
38 | |||
39 | /** |
||
40 | * Constructor. |
||
41 | * |
||
42 | * @param string|null $token User token. New will be generated if empty |
||
43 | */ |
||
44 | public function __construct($token = null) |
||
49 | |||
50 | /** |
||
51 | * Gets the id. |
||
52 | * |
||
53 | * @return string|int |
||
54 | */ |
||
55 | public function token() |
||
59 | |||
60 | /** |
||
61 | * Gets the created on. |
||
62 | * |
||
63 | * @return \DateTimeImmutable |
||
64 | */ |
||
65 | public function createdOn() |
||
69 | |||
70 | /** |
||
71 | * Method that checks if the id given is equal to the current. |
||
72 | * |
||
73 | * @param UserToken $aToken The token |
||
74 | * |
||
75 | * @return bool |
||
76 | */ |
||
77 | public function equals(UserToken $aToken) |
||
81 | |||
82 | /** |
||
83 | * Checks if the token is expired comparing |
||
84 | * with the given lifetime. |
||
85 | * |
||
86 | * @param int $lifetime The lifetime of the token |
||
87 | * |
||
88 | * @return bool |
||
89 | */ |
||
90 | public function isExpired($lifetime) |
||
96 | |||
97 | /** |
||
98 | * Magic method that represents the token in string format. |
||
99 | * |
||
100 | * @return string |
||
|
|||
101 | */ |
||
102 | public function __toString() |
||
106 | } |
||
107 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.