random key fixes for phpstan checks

This commit is contained in:
Clemens Schwaighofer
2025-06-04 11:58:20 +09:00
parent 991750aa5f
commit 4bebec2b47
2 changed files with 18 additions and 9 deletions

View File

@@ -64,12 +64,19 @@ final class CoreLibsCreateRandomKeyTest extends TestCase
} }
// Alternative more efficient version using strpos // Alternative more efficient version using strpos
private function allCharsInSet(string $input, string $allowedChars): bool /**
* check if all characters are in set
*
* @param string $input
* @param string $allowed_chars
* @return bool
*/
private function allCharsInSet(string $input, string $allowed_chars): bool
{ {
$inputLength = strlen($input); $inputLength = strlen($input);
for ($i = 0; $i < $inputLength; $i++) { for ($i = 0; $i < $inputLength; $i++) {
if (strpos($allowedChars, $input[$i]) === false) { if (strpos($allowed_chars, $input[$i]) === false) {
return false; return false;
} }
} }

View File

@@ -30,6 +30,8 @@ class RandomKey
/** /**
* if launched as class, init random key data first * if launched as class, init random key data first
*
* @param array<string> ...$key_range
*/ */
public function __construct(array ...$key_range) public function __construct(array ...$key_range)
{ {
@@ -39,7 +41,7 @@ class RandomKey
/** /**
* internal key range validation * internal key range validation
* *
* @param array<array<string>> ...$key_range * @param array<string> ...$key_range
* @return string * @return string
*/ */
private static function validateRandomKeyData(array ...$key_range): string private static function validateRandomKeyData(array ...$key_range): string
@@ -54,7 +56,7 @@ class RandomKey
/** /**
* sets the random key range with the default values * sets the random key range with the default values
* *
* @param array<array<string>> $key_range a list of key ranges as array * @param array<string> $key_range a list of key ranges as array
* @return void has no return * @return void has no return
* @throws \LengthException If the string length is only 1 abort * @throws \LengthException If the string length is only 1 abort
*/ */
@@ -150,11 +152,11 @@ class RandomKey
* if override key length is set, it will check on valid key and use this * if override key length is set, it will check on valid key and use this
* this will not set the class key length variable * this will not set the class key length variable
* *
* @param int $key_length [default=-1] key length override, * @param int $key_length [default=-1] key length override,
* if not set use default [LEGACY] * if not set use default [LEGACY]
* @param array<array<string>> $key_range a list of key ranges as array, * @param array<string> $key_range a list of key ranges as array,
* if not set use previous set data * if not set use previous set data
* @return string random key * @return string random key
*/ */
public static function randomKeyGen( public static function randomKeyGen(
int $key_length = self::KEY_LENGTH_DEFAULT, int $key_length = self::KEY_LENGTH_DEFAULT,