phpstan fixes

This commit is contained in:
Chris 2023-04-09 14:10:12 +02:00
parent b9c690cb6e
commit 822b796d40
3 changed files with 26 additions and 10 deletions

View File

@ -39,6 +39,8 @@ $key = new JWTDerivedKey("secret", "salt");
$key = new JWTPlaintextKey("This Should Be Binary Data.."); $key = new JWTPlaintextKey("This Should Be Binary Data..");
``` ```
`JWTDerivedKey` uses hash_pbkdf2.
### Generating tokens ### Generating tokens

View File

@ -21,8 +21,8 @@ class PropertyBag
/** /**
* Add a property value, fails if the property exists * Add a property value, fails if the property exists
* *
* @param string Property name * @param string $prop Property name
* @param mixed Value * @param mixed $value Value
* @throws PropertyException if the property already exists * @throws PropertyException if the property already exists
*/ */
public function add(string $prop, $value) public function add(string $prop, $value)
@ -37,14 +37,19 @@ class PropertyBag
* Set a property value, create the property if it doesn't * Set a property value, create the property if it doesn't
* exist. * exist.
* *
* @param string Property name * @param string $prop Property name
* @param mixed Value * @param mixed $value Value
*/ */
public function set(string $prop, $value) public function set(string $prop, $value)
{ {
$this->props[$prop] = $value; $this->props[$prop] = $value;
} }
/**
* Apply properties without removing anything.
*
* @param array $props The properties to apply
*/
public function setAll(array $props) public function setAll(array $props)
{ {
$this->props = array_merge( $this->props = array_merge(
@ -57,7 +62,7 @@ class PropertyBag
* Get the value of a property, fails if the property does not exist. * Get the value of a property, fails if the property does not exist.
* Use the value() method to get with a default value * Use the value() method to get with a default value
* *
* @param string Property name * @param string $prop Property name
* @return mixed * @return mixed
* @throws PropertyException if the property does not exist * @throws PropertyException if the property does not exist
*/ */
@ -92,8 +97,8 @@ class PropertyBag
/** /**
* Get the value of the property, or use the provided default value. * Get the value of the property, or use the provided default value.
* *
* @param string Property name * @param string $prop Property name
* @param mixed Default value * @param mixed|null $default Default value
* @return mixed * @return mixed
*/ */
public function valueOf(string $prop, $default=null) public function valueOf(string $prop, $default=null)
@ -105,6 +110,8 @@ class PropertyBag
/** /**
* Remove a property * Remove a property
*
* @param string $prop Property name
*/ */
public function delete(string $prop) public function delete(string $prop)
{ {
@ -113,6 +120,8 @@ class PropertyBag
/** /**
* Check if a property is present * Check if a property is present
*
* @param string $prop Property name
*/ */
public function has(string $prop): bool public function has(string $prop): bool
{ {
@ -121,6 +130,8 @@ class PropertyBag
/** /**
* Check if all the provided properties are present * Check if all the provided properties are present
*
* @param array $props Property names
*/ */
public function hasAll(array $props) public function hasAll(array $props)
{ {

View File

@ -10,8 +10,8 @@ use NoccyLabs\SimpleJWT\Key\KeyInterface;
* *
* *
* *
* @property-read header PropertyBag * @property-read PropertyBag $header
* @property-read claim PropertyBag * @property-read PropertyBag $claims
*/ */
class JWTToken class JWTToken
{ {
@ -30,7 +30,8 @@ class JWTToken
* Constructor * Constructor
* *
* *
* @param KeyInterface The key used to sign the token * @param KeyInterface $key The key used to sign the token
* @param string|null $token Token data
*/ */
public function __construct(KeyInterface $key, ?string $token=null) public function __construct(KeyInterface $key, ?string $token=null)
{ {
@ -127,6 +128,8 @@ class JWTToken
case 'm': case 'm':
$fact = 60; $fact = 60;
break; break;
default:
throw new \InvalidArgumentException();
} }
$this->header->set('exp', time() + (intval($match[1]) * $fact)); $this->header->set('exp', time() + (intval($match[1]) * $fact));
} else { } else {