Skip to content

Commit 9aaf98b

Browse files
committed
Fix inappropriate decoding logic
1 parent 1f941ac commit 9aaf98b

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

src/CodeCalculator/CodeCalculatorFloat.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ protected function generateCodeArea(string $strippedCode): CodeArea
8181
// Define the place value for the digits. We'll divide this down as we work through the code.
8282
$latPlaceVal = self::LAT_MSP_VALUE;
8383
$lngPlaceVal = self::LNG_MSP_VALUE;
84-
for ($i = OpenLocationCode::PAIR_CODE_LENGTH; $i < min(strlen($strippedCode), OpenLocationCode::MAX_DIGIT_COUNT); $i += 2) {
84+
for ($i = 0; $i < min(strlen($strippedCode), OpenLocationCode::MAX_DIGIT_COUNT); $i += 2) {
8585
$latPlaceVal = floor($latPlaceVal / OpenLocationCode::ENCODING_BASE);
8686
$lngPlaceVal = floor($lngPlaceVal / OpenLocationCode::ENCODING_BASE);
8787
$latVal += strpos(OpenLocationCode::CODE_ALPHABET, $strippedCode[$i]) * $latPlaceVal;

src/CodeCalculator/CodeCalculatorInt.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ protected function generateCodeArea(string $strippedCode): CodeArea
8383
// Define the place value for the digits. We'll divide this down as we work through the code.
8484
$latPlaceVal = self::LAT_MSP_VALUE;
8585
$lngPlaceVal = self::LNG_MSP_VALUE;
86-
for ($i = OpenLocationCode::PAIR_CODE_LENGTH; $i < min(strlen($strippedCode), OpenLocationCode::MAX_DIGIT_COUNT); $i += 2) {
86+
for ($i = 0; $i < min(strlen($strippedCode), OpenLocationCode::MAX_DIGIT_COUNT); $i += 2) {
8787
$latPlaceVal = intdiv($latPlaceVal, OpenLocationCode::ENCODING_BASE);
8888
$lngPlaceVal = intdiv($lngPlaceVal, OpenLocationCode::ENCODING_BASE);
8989
$latVal += strpos(OpenLocationCode::CODE_ALPHABET, $strippedCode[$i]) * $latPlaceVal;
90-
$lngVal = strpos(OpenLocationCode::CODE_ALPHABET, $strippedCode[$i + 1]) * $lngPlaceVal;
90+
$lngVal += strpos(OpenLocationCode::CODE_ALPHABET, $strippedCode[$i + 1]) * $lngPlaceVal;
9191
}
9292
unset($i);
9393
for ($i = OpenLocationCode::PAIR_CODE_LENGTH; $i < min(strlen($strippedCode), OpenLocationCode::MAX_DIGIT_COUNT); $i++) {

0 commit comments

Comments
 (0)