From e23ff3e786cb6def4a5f7f07fd9ff86cba4ce11e Mon Sep 17 00:00:00 2001 From: ismaail Date: Sun, 9 Apr 2023 21:40:30 +0000 Subject: [PATCH] Code formatting & cleanup --- src/CmiClient.php | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/CmiClient.php b/src/CmiClient.php index f34f9ae..cc1ab95 100644 --- a/src/CmiClient.php +++ b/src/CmiClient.php @@ -47,29 +47,19 @@ public function generateHash(): string $hashval = ''; foreach ($optionskeys as $param) { - // Skip Store Key - if ('storekey' === $param) { - continue; - } - - $lowerParam = strtolower($param); - // Skip some params - if (in_array($lowerParam, ['hash', 'encoding'])) { + if (in_array(strtolower($param), ['storekey', 'hash', 'encoding'], strict: true)) { continue; } - $paramValue = trim($cmiParams[$param]); - $escapedParamValue = str_replace(['\\', '|'], ['\\\\', '\|'], $paramValue); - $hashval .= $escapedParamValue . '|'; + $paramValue = str_replace(['\\', '|'], ['\\\\', '\|'], trim($cmiParams[$param])); + $hashval .= $paramValue . '|'; } - $escapedStoreKey = str_replace(['\\', '|'], ['\\\\', '\|'], $cmiParams['storekey']); - $hashval .= $escapedStoreKey; - - $calculatedHashValue = hash('sha512', $hashval); + $storeKeyValue = str_replace(['\\', '|'], ['\\\\', '\|'], $cmiParams['storekey']); + $hashval .= $storeKeyValue; - return base64_encode(pack('H*', $calculatedHashValue)); + return base64_encode(pack('H*', hash('sha512', $hashval))); } /**