2323 */
2424namespace Facebook \Authentication ;
2525
26+ use DateTime ;
27+
2628/**
2729 * Class AccessToken
2830 *
@@ -35,22 +37,19 @@ class AccessToken
3537 *
3638 * @var string
3739 */
38- protected $ value = '' ;
40+ protected string $ value = '' ;
3941
4042 /**
4143 * Date when token expires.
4244 *
43- * @var \ DateTime|null
45+ * @var DateTime|null
4446 */
45- protected $ expiresAt ;
47+ protected ? DateTime $ expiresAt = null ;
4648
4749 /**
4850 * Create a new access token entity.
49- *
50- * @param string $accessToken
51- * @param int $expiresAt
5251 */
53- public function __construct ($ accessToken , $ expiresAt = 0 )
52+ public function __construct (string $ accessToken , int $ expiresAt = 0 )
5453 {
5554 $ this ->value = $ accessToken ;
5655 if ($ expiresAt ) {
@@ -65,73 +64,61 @@ public function __construct($accessToken, $expiresAt = 0)
6564 *
6665 * @return string
6766 */
68- public function getAppSecretProof ($ appSecret )
67+ public function getAppSecretProof (string $ appSecret ): string
6968 {
7069 return hash_hmac ('sha256 ' , $ this ->value , $ appSecret );
7170 }
7271
7372 /**
7473 * Getter for expiresAt.
7574 *
76- * @return \ DateTime|null
75+ * @return DateTime|null
7776 */
78- public function getExpiresAt ()
77+ public function getExpiresAt (): ? DateTime
7978 {
8079 return $ this ->expiresAt ;
8180 }
8281
8382 /**
8483 * Determines whether or not this is an app access token.
85- *
86- * @return bool
8784 */
88- public function isAppAccessToken ()
85+ public function isAppAccessToken (): bool
8986 {
90- return strpos ($ this ->value , '| ' ) !== false ;
87+ return str_contains ($ this ->value , '| ' );
9188 }
9289
9390 /**
9491 * Determines whether or not this is a long-lived token.
9592 *
9693 * @return bool
9794 */
98- public function isLongLived ()
95+ public function isLongLived (): bool
9996 {
10097 if ($ this ->expiresAt ) {
10198 return $ this ->expiresAt ->getTimestamp () > time () + (60 * 60 * 2 );
10299 }
103100
104- if ($ this ->isAppAccessToken ()) {
105- return true ;
106- }
101+ return $ this ->isAppAccessToken ();
107102
108- return false ;
109103 }
110104
111105 /**
112106 * Checks the expiration of the access token.
113- *
114- * @return boolean|null
115107 */
116- public function isExpired ()
108+ public function isExpired (): bool
117109 {
118- if ($ this ->getExpiresAt () instanceof \ DateTime) {
110+ if ($ this ->getExpiresAt () instanceof DateTime) {
119111 return $ this ->getExpiresAt ()->getTimestamp () < time ();
120112 }
121113
122- if ($ this ->isAppAccessToken ()) {
123- return false ;
124- }
114+ return false ;
125115
126- return null ;
127116 }
128117
129118 /**
130119 * Returns the access token as a string.
131- *
132- * @return string
133120 */
134- public function getValue ()
121+ public function getValue (): string
135122 {
136123 return $ this ->value ;
137124 }
@@ -146,14 +133,9 @@ public function __toString()
146133 return $ this ->getValue ();
147134 }
148135
149- /**
150- * Setter for expires_at.
151- *
152- * @param int $timeStamp
153- */
154- protected function setExpiresAtFromTimeStamp ($ timeStamp )
136+ protected function setExpiresAtFromTimeStamp (int $ timeStamp ): void
155137 {
156- $ dt = new \ DateTime ();
138+ $ dt = new DateTime ();
157139 $ dt ->setTimestamp ($ timeStamp );
158140 $ this ->expiresAt = $ dt ;
159141 }
0 commit comments