Skip to content

Commit 88fcf5f

Browse files
emyllerclaude
andauthored
fix(Engine): Evaluate multivariates from segment overrides (#120)
* Evaluate multivariates from segment overrides Co-authored-by: Claude <[email protected]> * Update engine-test-data to v3.4.1 Co-authored-by: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
1 parent 1eaa8e4 commit 88fcf5f

File tree

5 files changed

+11
-27
lines changed

5 files changed

+11
-27
lines changed

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[submodule "tests/Engine/EngineTests/EngineTestData"]
22
path = tests/Engine/EngineTests/EngineTestData
33
url = [email protected]:Flagsmith/engine-test-data.git
4-
tag = v3.2.1
4+
tag = v3.4.1

src/Engine/Engine.php

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,16 @@ public static function getEvaluationResult($context): EvaluationResult
8181
foreach ($context->features as $feature) {
8282
$featureName = $feature->name;
8383
$evaluatedFeature = $evaluatedFeatures[$featureName] ?? null;
84+
$reason = 'DEFAULT';
8485
if ($evaluatedFeature) {
85-
$evaluatedFlags[$featureName] = self::getFlagResultFromSegmentContext(
86-
$evaluatedFeature,
87-
$matchedSegmentsByFeatureName[$featureName],
88-
);
89-
continue;
86+
$feature = $evaluatedFeature;
87+
$reason = "TARGETING_MATCH; segment={$matchedSegmentsByFeatureName[$featureName]->name}";
9088
}
9189

9290
$evaluatedFlags[$featureName] = self::getFlagResultFromFeatureContext(
9391
$feature,
9492
$context->identity?->key,
93+
$reason,
9594
);
9695
}
9796

@@ -142,9 +141,10 @@ private static function isContextInSegment($context, $segment): bool
142141
/**
143142
* @param FeatureContext $feature
144143
* @param ?string $splitKey
144+
* @param string $reason
145145
* @return FlagResult
146146
*/
147-
private static function getFlagResultFromFeatureContext($feature, $splitKey)
147+
private static function getFlagResultFromFeatureContext($feature, $splitKey, $reason = 'DEFAULT')
148148
{
149149
if ($splitKey !== null && !empty($feature->variants)) {
150150
$hashing = new Hashing();
@@ -180,23 +180,7 @@ private static function getFlagResultFromFeatureContext($feature, $splitKey)
180180
$flag->name = $feature->name;
181181
$flag->enabled = $feature->enabled;
182182
$flag->value = $feature->value;
183-
$flag->reason = 'DEFAULT';
184-
$flag->metadata = $feature->metadata;
185-
return $flag;
186-
}
187-
188-
/**
189-
* @param FeatureContext $feature
190-
* @param SegmentContext $segment
191-
* @return FlagResult
192-
*/
193-
private static function getFlagResultFromSegmentContext($feature, $segment)
194-
{
195-
$flag = new FlagResult();
196-
$flag->name = $feature->name;
197-
$flag->enabled = $feature->enabled;
198-
$flag->value = $feature->value;
199-
$flag->reason = "TARGETING_MATCH; segment={$segment->name}";
183+
$flag->reason = $reason;
200184
$flag->metadata = $feature->metadata;
201185
return $flag;
202186
}

src/Engine/Utils/Types/Context/EvaluationContext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static function fromJsonObject($jsonContext)
3030

3131
if (!empty($jsonContext->identity)) {
3232
$context->identity = new IdentityContext();
33-
$context->identity->key = $jsonContext->identity->key;
33+
$context->identity->key = $jsonContext->identity->key ?? null;
3434
$context->identity->identifier = $jsonContext->identity->identifier;
3535
$context->identity->traits = (array) ($jsonContext->identity->traits ?? []);
3636
}

src/Engine/Utils/Types/Context/IdentityContext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class IdentityContext
66
{
7-
/** @var string */
7+
/** @var ?string */
88
public $key;
99

1010
/** @var string */
Submodule EngineTestData updated 104 files

0 commit comments

Comments
 (0)