Skip to content

Commit

Permalink
Pull request #10: fix: Pre-segmentation result comparison logic
Browse files Browse the repository at this point in the history
Merge in SST/vwo-fme-php-sdk from fix/failingTestcaseFix to master

* commit '859b2c7630089b8dfff5ceb1238d3ef160561990':
  fix: Pre-segmentation result comparison logic
  • Loading branch information
sakshamGupta1999 authored and softvar-wingify committed Oct 4, 2024
2 parents c68b5d3 + 859b2c7 commit 3084dd4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

[1.3.1] - 2024-10-04

### Fixed

- Improved Pre-segmentation result comparison logic to handle numeric values more accurately by trimming trailing zeroes and decimal points across various operand types


[1.3.0] - 2024-10-03

### Added
Expand Down
2 changes: 1 addition & 1 deletion src/Constants/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Constants {
const DEFAULT_REQUEST_TIME_INTERVAL = 600; // 10 * 60(secs) = 600 secs i.e. 10 minutes
const DEFAULT_EVENTS_PER_REQUEST = 100;
const SDK_NAME = 'vwo-fme-php-sdk';
const SDK_VERSION = '1.3.0';
const SDK_VERSION = '1.3.1';
const AP = 'server';

const SETTINGS = 'settings';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,37 +180,43 @@ public function processValues($operandValue, $tagValue) {
public function extractResult($operandType, $operandValue, $tagValue) {
$result = false;

$normalizedOperandValue = is_numeric($operandValue) ? rtrim(rtrim($operandValue, '0'), '.') : $operandValue;
$normalizedTagValue = is_numeric($tagValue) ? rtrim(rtrim($tagValue, '0'), '.') : $tagValue;

switch ($operandType) {
case SegmentOperandValueEnum::LOWER_VALUE:
if ($tagValue !== null) {
$result = strtolower($operandValue) === strtolower($tagValue);
$result = strtolower($normalizedOperandValue) === strtolower($normalizedTagValue);
}
break;
case SegmentOperandValueEnum::STARTING_ENDING_STAR_VALUE:
if ($tagValue !== null) {
$result = strpos($tagValue, $operandValue) !== false;
$result = strpos($normalizedTagValue, $normalizedOperandValue) !== false;
}
break;
case SegmentOperandValueEnum::STARTING_STAR_VALUE:
if ($tagValue !== null) {
$result = substr($tagValue, -strlen($operandValue)) === $operandValue;
$result = substr($normalizedTagValue, -strlen($normalizedOperandValue)) === $normalizedOperandValue;
}
break;
case SegmentOperandValueEnum::ENDING_STAR_VALUE:
if ($tagValue !== null) {
$result = substr($tagValue, 0, strlen($operandValue)) === $operandValue;
$result = substr($normalizedTagValue, 0, strlen($normalizedOperandValue)) === $normalizedOperandValue;
}
break;
case SegmentOperandValueEnum::REGEX_VALUE:
// Check if operandValue is a valid regex pattern
if (@preg_match('/' . $operandValue . '/', '') === false) {
$result = false;
} else {
$result = preg_match('/' . $operandValue . '/', $tagValue);
}
break;
break;
case SegmentOperandValueEnum::EQUAL_VALUE:
$result = $tagValue === $operandValue;
if (is_numeric($operandValue) && is_numeric($tagValue)) {
$result = (float)$operandValue === (float)$tagValue;
} else {
$result = $normalizedOperandValue === $normalizedTagValue;
}
break;
case SegmentOperandValueEnum::GREATER_THAN_VALUE:
$result = $this->isValidNumericComparison($operandValue, $tagValue, function ($opValue, $tValue) {
Expand All @@ -226,17 +232,17 @@ public function extractResult($operandType, $operandValue, $tagValue) {
$result = $this->isValidNumericComparison($operandValue, $tagValue, function ($opValue, $tValue) {
return $opValue > $tValue;
});
break;
break;
case SegmentOperandValueEnum::LESS_THAN_EQUAL_TO_VALUE:
$result = $this->isValidNumericComparison($operandValue, $tagValue, function ($opValue, $tValue) {
return $opValue >= $tValue;
});
break;
break;
default:
$result = false;
break;
}

return $result;
}

Expand All @@ -253,4 +259,4 @@ private function isValidNumericComparison($operandValue, $tagValue, callable $co
}
}

?>
?>

0 comments on commit 3084dd4

Please sign in to comment.