-
Notifications
You must be signed in to change notification settings - Fork 30
feat(OptimizelyConfig): Add new fields to OptimizelyConfig #230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
2 similar comments
@@ -51,6 +51,37 @@ public function getBotFiltering(); | |||
*/ | |||
public function getRevision(); | |||
|
|||
/** | |||
* @return string String represnting environment key of the datafile. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use "representing" instead of "represnting" if you want . If you leave a comment, try to keep in mind the text. This is a minor correction, however--I wouldn't gate an entire review on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Need some changes.
$this->audiences = isset($config['audiences']) ? $config['audiences'] : []; | ||
$this->events = $config['events'] ?: []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we "?:" consistently for all these props?
$this->_botFiltering = isset($config['botFiltering'])? $config['botFiltering'] : null; | ||
$this->attributes = isset($config['attributes']) ? $config['attributes'] : []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming rule? I see inconsistency with and without "_" prefix though they're all private
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Map of rollout Experiments Keys to OptimizelyExperiments. | ||
* | ||
* @var <String, OptimizelyExperiment> associative array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Map of rollout Experiments Keys to OptimizelyExperiments. | |
* | |
* @var <String, OptimizelyExperiment> associative array | |
* Array of delivery rules. | |
* | |
* @var [OptimizelyExperiment] |
* Map of Experiment Keys to OptimizelyExperiments. | ||
* | ||
* @var <String, OptimizelyExperiment> associative array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Map of Experiment Keys to OptimizelyExperiments. | |
* | |
* @var <String, OptimizelyExperiment> associative array | |
* Array of experiment rules. | |
* | |
* @var [OptimizelyExperiment] |
$experimentMapFlag1 = $optimizelyConfig->getFeaturesMap()['flag1']->getExperimentsMap(); // 9300000007569 | ||
$experimentMapFlag2 = $optimizelyConfig->getFeaturesMap()['flag2']->getExperimentsMap(); // 9300000007573 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change these to use "->getExperimentRules()" instead of "->getExperimentsMap()"
array("3468206642"), | ||
array('and', array('or', '3468206642', '3988293899'), '3988293898'), | ||
array('and', 'and'), | ||
array(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have one more test for non-matching audience-id: '[“or”, “1”, “100000”]' in TDD
} | ||
|
||
public function testgetConfigAudiences() | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not see tests for validating typeAudiences and audiences merged properly (filtering duplicate ones and $opt_dummy_audience? Please add if missed.
* @var string sdkKey of the config. | ||
*/ | ||
private $sdkKey; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(1) add warning message about duplicated keys to "experimentsMap" of OptimizelyConfig
(2) add deprecation warning to "getExperimentsMap" of OptimizelyFeature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall Comment about Variable and Method doc comments. I see multiple patterns of commenting. Can we decide and use one. In some cases, there is a comment line and a return type line. In others, there is a single line which casually talks about a type.
/** | ||
* list of Typed Audiences that will be parsed from the datafile | ||
* | ||
* @var [typed_audience] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure but assuming it represents the type, should'nt it be [AUDIENCE]
instead of [typed_audience]
return array_filter( | ||
array_values($this->_experimentIdMap), | ||
function ($experiment) use ($rolloutExperimentIds) { | ||
return !in_array($experiment->getId(), $rolloutExperimentIds); | ||
} | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this diff needed. it looks like only indentation/formatting change?
* Array of events as OptimizelyEvent. | ||
* | ||
* @var [OptimizelyEvent] | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a common pattern, i see two ways of variable and function doc comments here. one is this and one is along the lines of @var string sdkKey of the config
. why two standards and not one?
{ | ||
$finalAudiences = []; | ||
$uniqueIdsMap = []; | ||
$normalAudiences = $this->projectConfig->getAudiences(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
normalAudiences
sounds like an awkward variable name. You can call it audiences
?
foreach ($audiencesArray as $audience) { | ||
$id = $audience['id']; | ||
if ($id != '$opt_dummy_audience') { | ||
$optlyAudience = new OptimizelyAudience( | ||
$id, | ||
$audience['name'], | ||
$audience['conditions'] | ||
); | ||
array_push($finalAudiences, $optlyAudience); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You dont probably need a third loop if you keep building the finalAudiences
array while iterating through the first two
if ($finalAudiences !== '') { | ||
$finalAudiences = $finalAudiences . ' '; | ||
} else { | ||
$finalAudiences = $finalAudiences; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if ($finalAudiences !== '') { | |
$finalAudiences = $finalAudiences . ' '; | |
} else { | |
$finalAudiences = $finalAudiences; | |
} | |
if ($finalAudiences !== '') { | |
$finalAudiences .= ' '; | |
} |
} | ||
} | ||
// Checks if sub audience is empty or not | ||
if (strval($subAudience !== '')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is strVal needed when you are already initializing it to empty string at the top?
* | ||
* @param string feature rollout id. | ||
* | ||
* @return array of optimizelyExperiments as delivery rules . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @return array of optimizelyExperiments as delivery rules . | |
* @return array of optimizelyExperiments as delivery rules. |
$expId = $exp->getId(); | ||
$expKey = $exp->getKey(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: Why do you need to assign these to vars. Cant they be used directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But these values are again required below to assign values in $experimentsKeyMap
and $experimentsIdMap
} | ||
|
||
/** | ||
* @return string event conditions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you correct the comment? copy paste error maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
initial review.
$this->_revision = $config['revision']; | ||
$this->_sendFlagDecisions = isset($config['sendFlagDecisions']) ? $config['sendFlagDecisions'] : false; | ||
|
||
$groups = $config['groups'] ?: []; | ||
$experiments = $config['experiments'] ?: []; | ||
$events = $config['events'] ?: []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't understand why these are removed from here. all three.
$typedAudiences = $this->projectConfig->getTypedAudiences(); | ||
$audiencesArray = $typedAudiences; | ||
foreach ($audiencesArray as $key => $typedAudience) { | ||
$uniqueIdsMap[$typedAudience['id']] = $typedAudience['id']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't we push it in array and check if that id exists or not?
* | ||
* @return array of OptimizelyEvents. | ||
*/ | ||
protected function getConfigAudiences() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please revise the variable names.
finalAudiences, normalAudiences seems weird.
@@ -145,6 +249,7 @@ protected function getVariablesMap(Experiment $experiment, Variation $variation) | |||
} | |||
|
|||
$featureFlag = $this->experimentIdFeatureMap[$experimentId]; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this line.
$subAudience = $this->getSerializedAudiences($var); | ||
|
||
$subAudience = '(' . $subAudience . ')'; | ||
} elseif (in_array($var, array('and', 'or', 'not'), true)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we have 'and', 'or', 'not' in constants.
$optExp = new OptimizelyExperiment( | ||
$expId, | ||
$expKey, | ||
$this->getVariationsMap($exp), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i am not sure, when we get variation, without passing featureFlag, how featurevariables will be merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All changes look good.
Deprecation warning for "getExperimentsMap()" should be moved from OptimizelyConfig to OptimizelyFeature.
@@ -124,6 +128,7 @@ public function getDatafile() | |||
*/ | |||
public function getExperimentsMap() | |||
{ | |||
# This experimentsMap is deprecated. Use experimentRules and deliveryRules instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this deprecation message to "getExperimentsMap()" of OptimizelyFeature. The same-named one here for OptimizelyConfig is not deprecated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks Good! Great work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
zeeshan and jae already done, dismissing my review.
Summary
The following new public properties are added to OptimizelyConfig:
Test plan
All FSC tests OPTIMIZELY_CONFIG_V2 tests should pass.
https://app.travis-ci.com/github/optimizely/fullstack-sdk-compatibility-suite/builds/235923589