From 1791ec39084fa12b81553d3fb97168c042f2a3b5 Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Fri, 4 Apr 2025 15:17:42 +0900 Subject: [PATCH] phan and phpstan fixes for hash uses in CoreLibs --- www/admin/class_test.hash.php | 8 ++++---- www/lib/CoreLibs/Basic.php | 12 ++++++++---- www/lib/CoreLibs/DB/IO.php | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/www/admin/class_test.hash.php b/www/admin/class_test.hash.php index 57da698f..0d78175d 100644 --- a/www/admin/class_test.hash.php +++ b/www/admin/class_test.hash.php @@ -39,10 +39,10 @@ print '

' . $PAGE_NAME . '

'; $to_crc = 'Some text block'; // static print "S::__CRC32B: $to_crc: " . Hash::__crc32b($to_crc) . "
"; -print "S::__SHA1SHORT(off): $to_crc: " . Hash::__sha1short($to_crc) . "
"; +// print "S::__SHA1SHORT(off): $to_crc: " . Hash::__sha1short($to_crc) . "
"; print "S::hashShort(__sha1Short replace): $to_crc: " . Hash::hashShort($to_crc) . "
"; -print "S::__SHA1SHORT(on): $to_crc: " . Hash::__sha1short($to_crc, true) . "
"; -print "S::sha1Short(__sha1Short replace): $to_crc: " . Hash::sha1Short($to_crc, true) . "
"; +// print "S::__SHA1SHORT(on): $to_crc: " . Hash::__sha1short($to_crc, true) . "
"; +print "S::sha1Short(__sha1Short replace): $to_crc: " . Hash::sha1Short($to_crc) . "
"; print "S::__hash(d): " . $to_crc . "/" . Hash::STANDARD_HASH_SHORT . ": " . $hash_class::__hash($to_crc) . "
"; foreach (['adler32', 'fnv132', 'fnv1a32', 'joaat', 'sha512'] as $__hash_c) { @@ -55,7 +55,7 @@ echo "
"; $text = 'Some String Text'; $type = 'crc32b'; print "Hash: " . $type . ": " . hash($type, $text) . "
"; -print "Class (old): " . $type . ": " . Hash::__hash($text, $type) . "
"; +// print "Class (old): " . $type . ": " . Hash::__hash($text, $type) . "
"; print "Class (new): " . $type . ": " . Hash::hash($text, $type) . "
"; echo "
"; diff --git a/www/lib/CoreLibs/Basic.php b/www/lib/CoreLibs/Basic.php index c259bd79..1eb3410f 100644 --- a/www/lib/CoreLibs/Basic.php +++ b/www/lib/CoreLibs/Basic.php @@ -1024,8 +1024,12 @@ class Basic */ public function __sha1Short(string $string, bool $use_sha = false): string { - trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Create\Hash::__sha1Short()', E_USER_DEPRECATED); - return \CoreLibs\Create\Hash::__sha1Short($string, $use_sha); + trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Create\Hash::sha1Short() or ::__crc32b()', E_USER_DEPRECATED); + if ($use_sha) { + return \CoreLibs\Create\Hash::sha1Short($string); + } else { + return \CoreLibs\Create\Hash::__crc32b($string); + } } /** @@ -1040,8 +1044,8 @@ class Basic */ public function __hash(string $string, string $hash_type = 'adler32'): string { - trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Create\Hash::__hash()', E_USER_DEPRECATED); - return \CoreLibs\Create\Hash::__hash($string, $hash_type); + trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Create\Hash::hash()', E_USER_DEPRECATED); + return \CoreLibs\Create\Hash::hash($string, $hash_type); } // *** HASH FUNCTIONS END diff --git a/www/lib/CoreLibs/DB/IO.php b/www/lib/CoreLibs/DB/IO.php index 47206323..a10a089b 100644 --- a/www/lib/CoreLibs/DB/IO.php +++ b/www/lib/CoreLibs/DB/IO.php @@ -4056,7 +4056,7 @@ class IO */ public function dbGetQueryHash(string $query, array $params = []): string { - return Hash::__hashLong( + return Hash::hashLong( $query . ( $params !== [] ? '#' . json_encode($params) : ''