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
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);
for ($i = 0; $i < $inputLength; $i++) {
if (strpos($allowedChars, $input[$i]) === false) {
if (strpos($allowed_chars, $input[$i]) === false) {
return false;
}
}

View File

@@ -30,6 +30,8 @@ class RandomKey
/**
* if launched as class, init random key data first
*
* @param array<string> ...$key_range
*/
public function __construct(array ...$key_range)
{
@@ -39,7 +41,7 @@ class RandomKey
/**
* internal key range validation
*
* @param array<array<string>> ...$key_range
* @param array<string> ...$key_range
* @return string
*/
private static function validateRandomKeyData(array ...$key_range): string
@@ -54,7 +56,7 @@ class RandomKey
/**
* 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
* @throws \LengthException If the string length is only 1 abort
*/
@@ -152,7 +154,7 @@ class RandomKey
*
* @param int $key_length [default=-1] key length override,
* 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
* @return string random key
*/