feat(OptimizelyConfig): Add new fields to OptimizelyConfig#230
feat(OptimizelyConfig): Add new fields to OptimizelyConfig#230msohailhussain merged 9 commits intomasterfrom
Conversation
2 similar comments
| public function getRevision(); | ||
|
|
||
| /** | ||
| * @return string String represnting environment key of the datafile. |
There was a problem hiding this comment.
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.
jaeopt
left a comment
There was a problem hiding this comment.
Looks good. Need some changes.
| $this->audiences = isset($config['audiences']) ? $config['audiences'] : []; | ||
| $this->events = $config['events'] ?: []; |
There was a problem hiding this comment.
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.
Naming rule? I see inconsistency with and without "_" prefix though they're all private
| * Map of rollout Experiments Keys to OptimizelyExperiments. | ||
| * | ||
| * @var <String, OptimizelyExperiment> associative array |
There was a problem hiding this comment.
| * 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.
| * 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.
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.
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.
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.
(1) add warning message about duplicated keys to "experimentsMap" of OptimizelyConfig
(2) add deprecation warning to "getExperimentsMap" of OptimizelyFeature.
zashraf1985
left a comment
There was a problem hiding this comment.
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.
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.
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.
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.
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.
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.
| 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.
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.
| * @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.
NIT: Why do you need to assign these to vars. Cant they be used directly?
There was a problem hiding this comment.
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.
Can you correct the comment? copy paste error maybe?
|
|
||
| $groups = $config['groups'] ?: []; | ||
| $experiments = $config['experiments'] ?: []; | ||
| $events = $config['events'] ?: []; |
There was a problem hiding this comment.
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.
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.
please revise the variable names.
finalAudiences, normalAudiences seems weird.
| } | ||
|
|
||
| $featureFlag = $this->experimentIdFeatureMap[$experimentId]; | ||
|
|
| $subAudience = $this->getSerializedAudiences($var); | ||
|
|
||
| $subAudience = '(' . $subAudience . ')'; | ||
| } elseif (in_array($var, array('and', 'or', 'not'), true)) { |
There was a problem hiding this comment.
can we have 'and', 'or', 'not' in constants.
| $optExp = new OptimizelyExperiment( | ||
| $expId, | ||
| $expKey, | ||
| $this->getVariationsMap($exp), |
There was a problem hiding this comment.
i am not sure, when we get variation, without passing featureFlag, how featurevariables will be merged.
jaeopt
left a comment
There was a problem hiding this comment.
All changes look good.
Deprecation warning for "getExperimentsMap()" should be moved from OptimizelyConfig to OptimizelyFeature.
| */ | ||
| public function getExperimentsMap() | ||
| { | ||
| # This experimentsMap is deprecated. Use experimentRules and deliveryRules instead. |
There was a problem hiding this comment.
Move this deprecation message to "getExperimentsMap()" of OptimizelyFeature. The same-named one here for OptimizelyConfig is not deprecated.
zashraf1985
left a comment
There was a problem hiding this comment.
Looks Good! Great work.
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