From c5dd77302673a5016d7d6c9d103ce570e001ca26 Mon Sep 17 00:00:00 2001 From: Christopher Vagnetoft Date: Mon, 10 Apr 2023 00:53:51 +0200 Subject: [PATCH] Added docblocks --- src/JWTToken.php | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/JWTToken.php b/src/JWTToken.php index d0d1cf0..f42899e 100644 --- a/src/JWTToken.php +++ b/src/JWTToken.php @@ -72,11 +72,25 @@ class JWTToken } } + /** + * Returns true if the expiry is not in the past. + * + * NOTE: This function will return true if the expiry header is missing, and + * it will not validate any claims. For actual verification of a token matching + * issuers, audience or other claims, see Validator\JWTValidator. + * + * @return bool True if the token expiry timestamp is missing or in the future + */ public function isValid(): bool { return $this->valid; } + /** + * Returns true if the token was generated as opposed to parsed. + * + * @return bool + */ public function isGenerated(): bool { return $this->generated; @@ -90,16 +104,43 @@ class JWTToken } } + /** + * Add a claim to a token. Throws an exception if the claim already exists. + * + * @param string $name The name of the claim + * @param mixed $value Claim value + * @throws \NoccyLabs\SimpleJWT\Collection\PropertyException if the claim already exists. + */ public function addClaim(string $name, $value) { $this->claims->add($name, $value); } + /** + * Add a claim to a token. If the claim already exists it will be updated with + * the provided value. + * + * @param string $name The name of the claim + * @param mixed $value Claim value + */ public function setClaim(string $name, $value) { $this->claims->set($name, $value); } + /** + * Set the time of expiry for the token. + * + * The expiry can be supplied as: + * - \DateTime instance + * - Unixtime as an integer + * - A string represening the expiry time + * - A period followed by a letter (m,h,d,w) + * - null, to unset the expiry + * + * @param string|int|\DateTime $expiry + * @return void + */ public function setExpiry($expiry) { if ($expiry instanceof \DateTime) {