2424class UserTrustedDevice extends BaseEntity
2525{
2626 #[ORM \JoinColumn(name: 'user_id ' , referencedColumnName: 'id ' , onDelete: 'CASCADE ' )]
27- #[ORM \ManyToOne(targetEntity: \ Auth \ User::class)]
27+ #[ORM \ManyToOne(targetEntity: User::class)]
2828 private $ user ;
2929
3030 #[ORM \Column(name: 'device_identifier ' , type: 'string ' , length: 255 )]
@@ -54,87 +54,111 @@ class UserTrustedDevice extends BaseEntity
5454 public function __construct ()
5555 {
5656 parent ::__construct ();
57+ $ now = new \DateTime ('now ' , new \DateTimeZone ('UTC ' ));
58+ $ this ->trusted_at = $ now ;
59+ $ this ->last_seen_at = clone $ now ;
5760 $ this ->is_revoked = false ;
5861 }
5962
6063 public function getUser (): User
6164 {
6265 return $ this ->user ;
6366 }
64- public function setUser (User $ user ): void
67+ public function setUser (User $ user ): static
6568 {
6669 $ this ->user = $ user ;
70+ return $ this ;
6771 }
6872
6973 public function getDeviceIdentifier (): string
7074 {
7175 return $ this ->device_identifier ;
7276 }
73- public function setDeviceIdentifier (string $ value ): void
77+ public function setDeviceIdentifier (string $ value ): static
7478 {
7579 $ this ->device_identifier = $ value ;
80+ return $ this ;
7681 }
7782
7883 public function getDeviceName (): string
7984 {
8085 return $ this ->device_name ;
8186 }
82- public function setDeviceName (string $ value ): void
87+ public function setDeviceName (string $ value ): static
8388 {
8489 $ this ->device_name = $ value ;
90+ return $ this ;
8591 }
8692
8793 public function getIpAddress (): string
8894 {
8995 return $ this ->ip_address ;
9096 }
91- public function setIpAddress (string $ value ): void
97+ public function setIpAddress (string $ value ): static
9298 {
9399 $ this ->ip_address = $ value ;
100+ return $ this ;
94101 }
95102
96103 public function getUserAgent (): string
97104 {
98105 return $ this ->user_agent ;
99106 }
100- public function setUserAgent (string $ value ): void
107+ public function setUserAgent (string $ value ): static
101108 {
102109 $ this ->user_agent = $ value ;
110+ return $ this ;
103111 }
104112
105113 public function getTrustedAt (): \DateTime
106114 {
107115 return $ this ->trusted_at ;
108116 }
109- public function setTrustedAt (\DateTime $ value ): void
117+ public function setTrustedAt (\DateTime $ value ): static
110118 {
111119 $ this ->trusted_at = $ value ;
120+ return $ this ;
112121 }
113122
114123 public function getExpiresAt (): \DateTime
115124 {
116125 return $ this ->expires_at ;
117126 }
118- public function setExpiresAt (\DateTime $ value ): void
127+ public function setExpiresAt (\DateTime $ value ): static
119128 {
120129 $ this ->expires_at = $ value ;
130+ return $ this ;
121131 }
122132
123133 public function getLastSeenAt (): \DateTime
124134 {
125135 return $ this ->last_seen_at ;
126136 }
127- public function setLastSeenAt (\DateTime $ value ): void
137+ public function setLastSeenAt (\DateTime $ value ): static
128138 {
129139 $ this ->last_seen_at = $ value ;
140+ return $ this ;
130141 }
131142
132143 public function isRevoked (): bool
133144 {
134145 return (bool ) $ this ->is_revoked ;
135146 }
136- public function setIsRevoked (bool $ value ): void
147+
148+ public function getIsRevoked (): bool
149+ {
150+ return $ this ->isRevoked ();
151+ }
152+
153+ public function setIsRevoked (bool $ value ): static
137154 {
138155 $ this ->is_revoked = $ value ;
156+ return $ this ;
157+ }
158+
159+ public function isExpired (): bool
160+ {
161+ $ now = new \DateTime ('now ' , new \DateTimeZone ('UTC ' ));
162+ return $ this ->expires_at < $ now ;
139163 }
140164}
0 commit comments