Skip to content

Commit

Permalink
Merge pull request #212 from kelvinmo/dependabot/composer/phpstan/php…
Browse files Browse the repository at this point in the history
…stan-2.0.1
  • Loading branch information
dependabot[bot] authored Nov 12, 2024
2 parents d76dda3 + 0504d47 commit 3d07ab2
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "PHP",
"image": "mcr.microsoft.com/devcontainers/php:8.1-bullseye",
"image": "mcr.microsoft.com/devcontainers/php:8.2-bullseye",

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"require-dev": {
"phpunit/phpunit": "^9.6 || ^10.0 || ^11.0",
"consolidation/robo": "^4.0 || ^5.0",
"phpstan/phpstan": "^1.3.0",
"phpstan/phpstan": "^2.0.1",
"phlak/semver": "^5.0 || ^6.0"
},
"suggest": {
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
parameters:
level: 7
paths:
- src
- src
treatPhpDocTypesAsCertain: false
2 changes: 0 additions & 2 deletions src/SimpleJWT/Crypt/Encryption/AESGCM.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ public function __construct(?string $alg) {
* {@inheritdoc}
*/
public function getSupportedAlgs(): array {
if (!version_compare(PHP_VERSION, '7.1', '>=')) return [];

$ciphers = array_map('strtolower', openssl_get_cipher_methods());
$results = [];

Expand Down
6 changes: 4 additions & 2 deletions src/SimpleJWT/Crypt/KeyManagement/PBES2.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class PBES2 extends BaseAlgorithm implements KeyEncryptionAlgorithm {
'PBES2-HS512+A256KW' => ['hash' => 'sha512']
];

/** @var string $hash_alg */
/** @var truthy-string $hash_alg */
protected $hash_alg;

/** @var int $iterations */
Expand Down Expand Up @@ -162,8 +162,10 @@ protected function generateSaltInput(): string {
*/
private function generateKeyFromPassword(string $password, array $headers): string {
$salt = $headers['alg'] . "\x00" . Util::base64url_decode($headers['p2s']);
/** @var int<0, max> $length */
$length = intdiv($this->getAESKWKeySize(), 8);

return hash_pbkdf2($this->hash_alg, $password, $salt, $headers['p2c'], $this->getAESKWKeySize() / 8, true);
return hash_pbkdf2($this->hash_alg, $password, $salt, $headers['p2c'], $length, true);
}
}
?>
3 changes: 2 additions & 1 deletion src/SimpleJWT/Util/ASN1/Value.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

namespace SimpleJWT\Util\ASN1;

use \SimpleJWT\Util\Util;
use \InvalidArgumentException;

/**
Expand Down Expand Up @@ -207,7 +208,7 @@ static public function oid(string $value): self {
* @return Value
*/
static public function sequence(array $value): self {
if (!is_array($value)) {
if (!Util::array_is_list($value)) {
throw new InvalidArgumentException('Not a sequence');
}
return new self(static::SEQUENCE, $value);
Expand Down
2 changes: 1 addition & 1 deletion src/SimpleJWT/Util/BigNum.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function __construct($str = 0, int $base = 10) {
$this->value = $value;
return;
default:
if (!is_integer($base) || ($base < 2) || ($base > 36))
if (($base < 2) || ($base > 36))
throw new \InvalidArgumentException('$base cannot be less than 2 or greater than 36');

$value = (new BigNum(0))->value;
Expand Down
2 changes: 1 addition & 1 deletion src/SimpleJWT/Util/CBOR/CBOR.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ protected function decodeNext(string $data, int &$pos): ?DataItem {
}
break;
default:
assert(true);
throw new CBORException('Invalid major type: expected list or map, got ' . ($major_type >> 5));;
}
}

Expand Down
20 changes: 3 additions & 17 deletions src/SimpleJWT/Util/CBOR/DataItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ class DataItem {
* @param int $type the type
* @param mixed $value the native PHP value
* @param int $tag the tag number (i.e. excluding the class and constructed bit masks)
* @throws InvalidArgumentException
*/
function __construct(int $type, $value, int $tag = null) {
$this->type = $type;
Expand Down Expand Up @@ -233,7 +232,7 @@ static public function simple(int $value): self {
* @return DataItem
*/
static public function list(array $value): self {
if (!is_array($value) || !self::array_is_list($value)) {
if (!Util::array_is_list($value)) {
throw new InvalidArgumentException('Not an array');
}
return new self(static::LIST_TYPE, $value);
Expand All @@ -246,7 +245,7 @@ static public function list(array $value): self {
* @return DataItem
*/
static public function map(array $value): self {
if (!is_array($value)|| self::array_is_list($value)) {
if (Util::array_is_list($value)) {
throw new InvalidArgumentException('Not an associative array');
}
return new self(static::MAP_TYPE, $value);
Expand All @@ -260,7 +259,7 @@ static public function default($value): self {
if ($value instanceof DataItem) {
return $value;
} elseif (is_array($value)) {
if (self::array_is_list($value)) {
if (Util::array_is_list($value)) {
return static::list($value);
} else {
return static::map($value);
Expand Down Expand Up @@ -424,19 +423,6 @@ protected function prettyPrint(int $indent = 0): string {
public function __toString(): string {
return $this->prettyPrint();
}

/**
* Returns whether an array is a list.
*
* This is a polyfill for PHP 8.1's array_as_list function.
*
* @param array<mixed> $array
* @return bool if the array is a list
*/
public static function array_is_list(array $array): bool {
if (function_exists('array_is_list')) return \array_is_list($array);
return $array === [] || (array_keys($array) === range(0, count($array) - 1));
}
}

?>
19 changes: 14 additions & 5 deletions src/SimpleJWT/Util/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,7 @@ static public function secure_compare(string $str1, string $str2): bool {
*/
static function packInt64(int $x): string {
if (PHP_INT_SIZE == 8) {
if (version_compare(PHP_VERSION, '5.6.3', '>=')) {
return pack('J', $x);
} else {
return pack('NN', ($x & 0xFFFFFFFF00000000) >> 32, $x & ($x & 0x00000000FFFFFFFF));
}
return pack('J', $x);
} else {
// 32-bit system
return "\x00\x00\x00\x00" . pack('N', $x);
Expand All @@ -143,6 +139,19 @@ static function packInt64(int $x): string {
static function random_bytes(int $num_bytes): string {
return random_bytes($num_bytes);
}

/**
* Returns whether an array is a list.
*
* This is a polyfill for PHP 8.1's array_as_list function.
*
* @param array<mixed> $array
* @return bool if the array is a list
*/
public static function array_is_list(array $array): bool {
if (function_exists('array_is_list')) return \array_is_list($array);
return $array === [] || (array_keys($array) === range(0, count($array) - 1));
}
}

?>

0 comments on commit 3d07ab2

Please sign in to comment.