From 9115fc9557f59c00c6f47b57d591591c2480b87d Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Thu, 5 Jun 2025 14:37:42 +0900 Subject: [PATCH] phan and phpstan fixes --- 4dev/tests/Convert/CoreLibsConvertStringsTest.php | 5 +++++ www/admin/class_test.array.php | 2 +- www/lib/CoreLibs/Combined/ArrayHandler.php | 4 ++-- www/lib/CoreLibs/Convert/Strings.php | 9 +++++++-- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/4dev/tests/Convert/CoreLibsConvertStringsTest.php b/4dev/tests/Convert/CoreLibsConvertStringsTest.php index 3233ce07..ed4bbc97 100644 --- a/4dev/tests/Convert/CoreLibsConvertStringsTest.php +++ b/4dev/tests/Convert/CoreLibsConvertStringsTest.php @@ -135,6 +135,11 @@ final class CoreLibsConvertStringsTest extends TestCase public function splitFormatStringExceptionProvider(): array { return [ + 'string format with no splitter match' => [ + '1234', + '22', + '12-34' + ], 'invalid format string' => [ '1234', '2あ2', diff --git a/www/admin/class_test.array.php b/www/admin/class_test.array.php index 87146eaf..439252f3 100644 --- a/www/admin/class_test.array.php +++ b/www/admin/class_test.array.php @@ -333,7 +333,7 @@ print "(kosrt, lower case, reverse): " print "
"; $nested = [ 'B' => 'foo', 'a', '0', 9, - 1 => ['z', 'b', 'a'], + '1' => ['z', 'b', 'a'], 'd' => ['zaip', 'bar', 'baz'] ]; print "Nested: " . DgS::printAr($nested) . "
"; diff --git a/www/lib/CoreLibs/Combined/ArrayHandler.php b/www/lib/CoreLibs/Combined/ArrayHandler.php index 16d2c3ab..4bf3b99d 100644 --- a/www/lib/CoreLibs/Combined/ArrayHandler.php +++ b/www/lib/CoreLibs/Combined/ArrayHandler.php @@ -251,10 +251,10 @@ class ArrayHandler * @param array $array * @param string|int|float|bool $search_value * @param string|array $required_key - * @param ?string $serach_key [null] + * @param ?string $search_key [null] * @param string $path_separator [DATA_SEPARATOR] * @param string $current_path - * @return array,path?:string,missing_key?:string}> + * @return array,path?:string,missing_key?:array}> */ public static function findArraysMissingKey( array $array, diff --git a/www/lib/CoreLibs/Convert/Strings.php b/www/lib/CoreLibs/Convert/Strings.php index ae87c4d2..30d4ad44 100644 --- a/www/lib/CoreLibs/Convert/Strings.php +++ b/www/lib/CoreLibs/Convert/Strings.php @@ -85,7 +85,12 @@ class Strings ); } // get the split characters that are not numerical and check they are ascii - $split_characters = self::removeDuplicates(preg_replace('/[0-9]/', '', $split_format)); + $split_characters = self::removeDuplicates(preg_replace('/[0-9]/', '', $split_format) ?: ''); + if (empty($split_characters)) { + throw new \InvalidArgumentException( + "A split character must exist in the format string: " . $split_format + ); + } if (preg_match('/[^\x20-\x7e]/', $split_characters)) { throw new \InvalidArgumentException( "The split character has to be a valid ascii character: " . $split_characters @@ -296,7 +301,7 @@ class Strings * check if a regex is invalid, returns array with flag and error string * * @param string $pattern - * @return array{valid:bool,preg_error:0,error:null|string,pcre_error:null|string} + * @return array{valid:bool,preg_error:int,error:null|string,pcre_error:null|string} */ public static function validateRegex(string $pattern): array {