Skip to content

Commit 1ce4795

Browse files
rashidspaliabbasrizvi
authored andcommitted
Fix(FeatureVariable): Resolves variable value type cast issue (#165)
1 parent 1ac1429 commit 1ce4795

File tree

2 files changed

+149
-76
lines changed

2 files changed

+149
-76
lines changed

src/Optimizely/Optimizely.php

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,10 @@ public function getFeatureVariableValueForType(
684684
}
685685
}
686686

687+
if (!is_null($variableValue)) {
688+
$variableValue = VariableTypeUtils::castStringToType($variableValue, $variableType, $this->_logger);
689+
}
690+
687691
$attributes = $attributes ?: [];
688692
$this->notificationCenter->sendNotifications(
689693
NotificationType::DECISION,
@@ -719,19 +723,13 @@ public function getFeatureVariableValueForType(
719723
*/
720724
public function getFeatureVariableBoolean($featureFlagKey, $variableKey, $userId, $attributes = null)
721725
{
722-
$variableValue = $this->getFeatureVariableValueForType(
726+
return $this->getFeatureVariableValueForType(
723727
$featureFlagKey,
724728
$variableKey,
725729
$userId,
726730
$attributes,
727731
FeatureVariable::BOOLEAN_TYPE
728732
);
729-
730-
if (!is_null($variableValue)) {
731-
return VariableTypeUtils::castStringToType($variableValue, FeatureVariable::BOOLEAN_TYPE, $this->_logger);
732-
}
733-
734-
return $variableValue;
735733
}
736734

737735
/**
@@ -746,19 +744,13 @@ public function getFeatureVariableBoolean($featureFlagKey, $variableKey, $userId
746744
*/
747745
public function getFeatureVariableInteger($featureFlagKey, $variableKey, $userId, $attributes = null)
748746
{
749-
$variableValue = $this->getFeatureVariableValueForType(
747+
return $this->getFeatureVariableValueForType(
750748
$featureFlagKey,
751749
$variableKey,
752750
$userId,
753751
$attributes,
754752
FeatureVariable::INTEGER_TYPE
755753
);
756-
757-
if (!is_null($variableValue)) {
758-
return VariableTypeUtils::castStringToType($variableValue, FeatureVariable::INTEGER_TYPE, $this->_logger);
759-
}
760-
761-
return $variableValue;
762754
}
763755

764756
/**
@@ -773,19 +765,13 @@ public function getFeatureVariableInteger($featureFlagKey, $variableKey, $userId
773765
*/
774766
public function getFeatureVariableDouble($featureFlagKey, $variableKey, $userId, $attributes = null)
775767
{
776-
$variableValue = $this->getFeatureVariableValueForType(
768+
return $this->getFeatureVariableValueForType(
777769
$featureFlagKey,
778770
$variableKey,
779771
$userId,
780772
$attributes,
781773
FeatureVariable::DOUBLE_TYPE
782774
);
783-
784-
if (!is_null($variableValue)) {
785-
return VariableTypeUtils::castStringToType($variableValue, FeatureVariable::DOUBLE_TYPE, $this->_logger);
786-
}
787-
788-
return $variableValue;
789775
}
790776

791777
/**
@@ -800,15 +786,13 @@ public function getFeatureVariableDouble($featureFlagKey, $variableKey, $userId,
800786
*/
801787
public function getFeatureVariableString($featureFlagKey, $variableKey, $userId, $attributes = null)
802788
{
803-
$variableValue = $this->getFeatureVariableValueForType(
789+
return $this->getFeatureVariableValueForType(
804790
$featureFlagKey,
805791
$variableKey,
806792
$userId,
807793
$attributes,
808794
FeatureVariable::STRING_TYPE
809795
);
810-
811-
return $variableValue;
812796
}
813797

814798
/**

0 commit comments

Comments
 (0)