Skip to content

Commit 38f33df

Browse files
Merge pull request #72 from optimizely/arizvi/some_cleanups
Minor cleanups and re-formatting
2 parents 258ce17 + da0adae commit 38f33df

File tree

11 files changed

+29
-25
lines changed

11 files changed

+29
-25
lines changed

src/Optimizely/DecisionService/DecisionService.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@
2929
use Optimizely\UserProfile\UserProfileUtils;
3030
use Optimizely\Utils\Validator;
3131

32-
// This value was decided between App Backend, Audience, and Oasis teams, but may possibly change.
33-
// We decided to prefix the reserved keyword with '$' because it is a symbol that is not
34-
// allowed in custom attributes.
35-
// We also thought that the prefix 'opt' makes it apparent to users that the variable belongs to Optimizely.
32+
// Reserved attribute for bucketing ID.
3633
define("RESERVED_ATTRIBUTE_KEY_BUCKETING_ID", "\$opt_bucketing_id");
3734

3835
/**

src/Optimizely/Entity/FeatureFlag.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919

2020
use Optimizely\Utils\ConfigParser;
2121

22-
class FeatureFlag{
22+
class FeatureFlag
23+
{
2324

2425
/**
2526
* variable to hold feature flag ID

src/Optimizely/Entity/FeatureVariable.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
namespace Optimizely\Entity;
1919

20-
class FeatureVariable{
20+
class FeatureVariable
21+
{
2122

2223
// Feature variable primitive types
2324
const BOOLEAN_TYPE = 'boolean';

src/Optimizely/Entity/Rollout.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919

2020
use Optimizely\Utils\ConfigParser;
2121

22-
class Rollout{
22+
class Rollout
23+
{
2324

2425
/**
2526
* The ID of the rollout

src/Optimizely/Entity/VariableUsage.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
namespace Optimizely\Entity;
1919

20-
class VariableUsage{
20+
class VariableUsage
21+
{
2122

2223
/**
2324
* The ID of the live variable this usage is modifying

src/Optimizely/Event/Builder/EventBuilder.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ class EventBuilder
6161
* @param $config ProjectConfig Configuration for the project.
6262
* @param $userId string ID of user.
6363
* @param $attributes array Attributes of the user.
64+
*
65+
* @return array Hash representing parameters which are common to both impression and conversion events.
6466
*/
6567
private function getCommonParams($config, $userId, $attributes)
6668
{
@@ -89,14 +91,12 @@ private function getCommonParams($config, $userId, $attributes)
8991
if (!is_null($attributeValue)) {
9092
// check for reserved attributes
9193
if (strcmp($attributeKey , RESERVED_ATTRIBUTE_KEY_BUCKETING_ID) == 0) {
92-
// TODO (Alda): the type for bucketing ID attribute may change so that custom
93-
// attributes are not overloaded
9494
$feature = [
95-
ENTITY_ID => RESERVED_ATTRIBUTE_KEY_BUCKETING_ID,
96-
KEY => RESERVED_ATTRIBUTE_KEY_BUCKETING_ID_EVENT_PARAM_KEY,
97-
TYPE => CUSTOM_ATTRIBUTE_FEATURE_TYPE,
98-
VALUE => $attributeValue
99-
];
95+
ENTITY_ID => RESERVED_ATTRIBUTE_KEY_BUCKETING_ID,
96+
KEY => RESERVED_ATTRIBUTE_KEY_BUCKETING_ID_EVENT_PARAM_KEY,
97+
TYPE => CUSTOM_ATTRIBUTE_FEATURE_TYPE,
98+
VALUE => $attributeValue
99+
];
100100

101101
} else {
102102
$attributeEntity = $config->getAttribute($attributeKey);
@@ -122,7 +122,9 @@ private function getCommonParams($config, $userId, $attributes)
122122
* Helper function to get parameters specific to impression event.
123123
*
124124
* @param $experiment Experiment Experiment being activated.
125-
* @param $variationId string
125+
* @param $variationId String ID representing the variation for the user.
126+
*
127+
* @return array Hash representing parameters particular to impression event.
126128
*/
127129
private function getImpressionParams(Experiment $experiment, $variationId)
128130
{
@@ -156,6 +158,8 @@ private function getImpressionParams(Experiment $experiment, $variationId)
156158
* @param $eventKey string Key representing the event.
157159
* @param $experimentVariationMap array Map of experiment ID to the ID of the variation that the user is bucketed into.
158160
* @param $eventTags array Hash representing metadata associated with the event.
161+
*
162+
* @return array Hash representing parameters particular to conversion event.
159163
*/
160164
private function getConversionParams($config, $eventKey, $experimentVariationMap, $eventTags)
161165
{

src/Optimizely/Optimizely.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
use Throwable;
2323
use Monolog\Logger;
2424
use Optimizely\DecisionService\DecisionService;
25-
use Optimizely\Entity\Experiment;
2625
use Optimizely\Logger\DefaultLogger;
2726
use Optimizely\ErrorHandler\ErrorHandlerInterface;
2827
use Optimizely\ErrorHandler\NoOpErrorHandler;
@@ -175,10 +174,10 @@ private function validateUserInputs($attributes, $eventTags = null) {
175174
* is one that is in "Running" state and into which the user has been bucketed.
176175
*
177176
* @param $event string Event key representing the event which needs to be recorded.
178-
* @param $user string ID for user.
177+
* @param $userId string ID for user.
179178
* @param $attributes array Attributes of the user.
180179
*
181-
* @return Array Of objects where each object contains the ID of the experiment to track and the ID of the variation the user is bucketed into.
180+
* @return array Of objects where each object contains the ID of the experiment to track and the ID of the variation the user is bucketed into.
182181
*/
183182
private function getValidExperimentsForEvent($event, $userId, $attributes = null) {
184183
$validExperiments = [];

tests/BucketerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
class BucketerTest extends \PHPUnit_Framework_TestCase
3030
{
3131
private $testBucketingIdControl;
32+
private $testBucketingIdVariation;
3233
private $testBucketingIdGroupExp2Var2;
3334
private $testUserId;
3435
private $testUserIdBucketsToVariation;

tests/EventTests/EventBuilderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function setUp()
4444
$this->eventBuilder = new EventBuilder();
4545
$this->timestamp = time()*1000;
4646
$this->uuid = 'a68cf1ad-0393-4e18-af87-efe8f01a7c9c';
47-
$this->differ = new Differ;
47+
$this->differ = new Differ();
4848

4949
$this->expectedEventUrl = 'https://logx.optimizely.com/v1/events';
5050
$this->expectedEventParams = [

tests/OptimizelyTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@
1818

1919
use Exception;
2020
use Monolog\Logger;
21+
use Optimizely\ErrorHandler\DefaultErrorHandler;
2122
use Optimizely\ErrorHandler\NoOpErrorHandler;
23+
use Optimizely\Event\Builder\EventBuilder;
2224
use Optimizely\Event\LogEvent;
2325
use Optimizely\Exceptions\InvalidAttributeException;
26+
use Optimizely\Logger\DefaultLogger;
2427
use Optimizely\Logger\NoOpLogger;
28+
use Optimizely\Optimizely;
2529
use Optimizely\ProjectConfig;
2630
use TypeError;
27-
use Optimizely\ErrorHandler\DefaultErrorHandler;
28-
use Optimizely\Event\Builder\EventBuilder;
29-
use Optimizely\Logger\DefaultLogger;
30-
use Optimizely\Optimizely;
3131

3232

3333
class OptimizelyTest extends \PHPUnit_Framework_TestCase

0 commit comments

Comments
 (0)