• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

optimizely / php-sdk / 13883417585

16 Mar 2025 12:37PM UTC coverage: 97.336%. Remained the same
13883417585

push

github

web-flow
[FSSDK-10015] chore: Prepare release 4.0.2

EventBuilder.php -> Updated SDK version to 4.0.2 
EventBuilderTest.php -> Updated client version to 4.0.2
CHANGELOG.md -> Added version 4.0.2 details (#291)

2704 of 2778 relevant lines covered (97.34%)

109.34 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.19
/src/Optimizely/Entity/Experiment.php
1
<?php
2
/**
3
 * Copyright 2016, 2018-2019, Optimizely
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17

18
namespace Optimizely\Entity;
19

20
use Optimizely\Utils\ConfigParser;
21

22
class Experiment
23
{
24
    /**
25
     * @const string String denoting running state of experiment.
26
     */
27
    const STATUS_RUNNING = 'Running';
28

29
    /**
30
     * @const string String denoting policy of mutually exclusive group.
31
     */
32
    const MUTEX_GROUP_POLICY = 'random';
33

34
    /**
35
     * @var string Experiment ID.
36
     */
37
    private $_id;
38

39
    /**
40
     * @var string Experiment key.
41
     */
42
    private $_key;
43

44
    /**
45
     * @var string Experiment status.
46
     */
47
    private $_status;
48

49
    /**
50
     * @var string Layer ID for the experiment.
51
     */
52
    private $_layerId;
53

54
    /**
55
     * @var string Group ID for the experiment.
56
     */
57
    private $_groupId;
58

59
    /**
60
     * @var array Variations in experiment.
61
     */
62
    private $_variations;
63

64
    /**
65
     * @var array Forced variations for experiment.
66
     */
67
    private $_forcedVariations;
68

69
    /**
70
     * @var string Policy of the experiment group.
71
     */
72
    private $_groupPolicy;
73

74
    /**
75
     * @var array ID(s) of audience(s) the experiment is targeted to.
76
     */
77
    private $_audienceIds;
78

79
    /**
80
     * @var array/string Single audience ID the experiment is attached to or
81
     *                   hierarchical conditions array of audience IDs related by AND/OR/NOT operators.
82
     */
83
    private $_audienceConditions;
84

85
    /**
86
     * @var array Traffic allocation of variations in the experiment.
87
     */
88
    private $_trafficAllocation;
89

90

91
    public function __construct(
92
        $id = null,
93
        $key = null,
94
        $layerId = null,
95
        $status = null,
96
        $groupId = null,
97
        $variations = null,
98
        $forcedVariations = null,
99
        $groupPolicy = null,
100
        $audienceIds = null,
101
        $audienceConditions = null,
102
        $trafficAllocation = null
103
    ) {
104
        $this->_id = $id;
726✔
105
        $this->_key = $key;
726✔
106
        $this->_status = $status;
726✔
107
        $this->_layerId = $layerId;
726✔
108
        $this->_groupId = $groupId;
726✔
109
        $this->_variations = $variations;
726✔
110
        $this->_forcedVariations = $forcedVariations;
726✔
111
        $this->_groupPolicy = $groupPolicy;
726✔
112
        $this->_audienceIds = $audienceIds;
726✔
113
        $this->_audienceConditions = $audienceConditions;
726✔
114
        $this->_trafficAllocation = $trafficAllocation;
726✔
115
    }
116

117
    /**
118
     * @return string ID of experiment.
119
     */
120
    public function getId()
121
    {
122
        return $this->_id;
726✔
123
    }
124

125
    /**
126
     * @param $id string ID for experiment.
127
     */
128
    public function setId($id)
129
    {
130
        $this->_id = $id;
726✔
131
    }
132

133
    /**
134
     * @return string Key of experiment.
135
     */
136
    public function getKey()
137
    {
138
        return $this->_key;
726✔
139
    }
140

141
    /**
142
     * @param $key string Key for experiment.
143
     */
144
    public function setKey($key)
145
    {
146
        $this->_key = $key;
726✔
147
    }
148

149
    /**
150
     * @return string Status of experiment.
151
     */
152
    public function getStatus()
153
    {
154
        return $this->_status;
×
155
    }
156

157
    /**
158
     * @param $status string Status for experiment.
159
     */
160
    public function setStatus($status)
161
    {
162
        $this->_status = $status;
726✔
163
    }
164

165
    /**
166
     * @return string Layer ID of experiment.
167
     */
168
    public function getLayerId()
169
    {
170
        return $this->_layerId;
40✔
171
    }
172

173
    /**
174
     * @param $layerId string Layer ID for experiment.
175
     */
176
    public function setLayerId($layerId)
177
    {
178
        $this->_layerId = $layerId;
726✔
179
    }
180

181
    /**
182
     * @return string ID of group experiment belongs to.
183
     */
184
    public function getGroupId()
185
    {
186
        return $this->_groupId;
22✔
187
    }
188

189
    /*
190
     * @param $groupId Group ID for the experiment.
191
     */
192
    public function setGroupId($groupId)
193
    {
194
        $this->_groupId = $groupId;
720✔
195
    }
196

197
    /**
198
     * @return array Variations in experiment.
199
     */
200
    public function getVariations()
201
    {
202
        return $this->_variations;
726✔
203
    }
204

205
    /**
206
     * @param $variations array Variations in experiment.
207
     */
208
    public function setVariations($variations)
209
    {
210
        $this->_variations = ConfigParser::generateMap($variations, null, Variation::class);
726✔
211
    }
212

213
    /**
214
     * @return array Forced variations for experiment.
215
     */
216
    public function getForcedVariations()
217
    {
218
        return $this->_forcedVariations;
120✔
219
    }
220

221
    /**
222
     * @param $forcedVariations array Forced variations for experiment.
223
     */
224
    public function setForcedVariations($forcedVariations)
225
    {
226
        $this->_forcedVariations = $forcedVariations;
726✔
227
    }
228

229
    /**
230
     * @return string Policy of group experiment belongs to.
231
     */
232
    public function getGroupPolicy()
233
    {
234
        return $this->_groupPolicy;
×
235
    }
236

237
    /**
238
     * @param $groupPolicy Group policy of the experiment's group.
239
     */
240
    public function setGroupPolicy($groupPolicy)
241
    {
242
        $this->_groupPolicy = $groupPolicy;
720✔
243
    }
244

245
    /**
246
     * @return array Audiences used by experiment.
247
     */
248
    public function getAudienceIds()
249
    {
250
        return $this->_audienceIds;
140✔
251
    }
252

253
    /**
254
     * @param $audienceIds array Audiences to which experiment is targeted.
255
     */
256
    public function setAudienceIds($audienceIds)
257
    {
258
        $this->_audienceIds = $audienceIds;
726✔
259
    }
260

261
    /**
262
     * @return array/string Audience conditions attached to experiment.
263
     */
264
    public function getAudienceConditions()
265
    {
266
        return $this->_audienceConditions;
176✔
267
    }
268

269
    /**
270
     * @param array/string $audienceConditions Audience conditions attached to experiment.
271
     */
272
    public function setAudienceConditions($audienceConditions)
273
    {
274
        $this->_audienceConditions = $audienceConditions;
700✔
275
    }
276

277
    /**
278
     * @return array Traffic allocation of variations in experiment.
279
     */
280
    public function getTrafficAllocation()
281
    {
282
        return $this->_trafficAllocation;
96✔
283
    }
284

285
    /**
286
     * @param $trafficAllocation array Traffic allocation of variations in experiment.
287
     */
288
    public function setTrafficAllocation($trafficAllocation)
289
    {
290
        $this->_trafficAllocation = ConfigParser::generateMap($trafficAllocation, null, TrafficAllocation::class);
726✔
291
    }
292

293
    /**
294
     * Determine if experiment is in a mutually exclusive group.
295
     *
296
     * @return boolean True if in a mutually exclusive group. False otherwise.
297
     */
298
    public function isInMutexGroup()
299
    {
300
        return !is_null($this->_groupPolicy) && $this->_groupPolicy == self::MUTEX_GROUP_POLICY;
96✔
301
    }
302

303
    /**
304
     * Determine if experiment is running or not.
305
     *
306
     * @return boolean True if experiment has status "Running". False otherwise.
307
     */
308
    public function isExperimentRunning()
309
    {
310
        return !is_null($this->_status) && $this->_status == self::STATUS_RUNNING;
134✔
311
    }
312

313
    /**
314
     * Determine if user is in forced variation of experiment.
315
     *
316
     * @param  $userId string ID of the user.
317
     * @return boolean True if user is in forced variation of experiment. False otherwise.
318
     */
319
    public function isUserInForcedVariation($userId)
320
    {
321
        $forcedVariations = $this->getForcedVariations();
×
322
        return !is_null($forcedVariations) && isset($forcedVariations[$userId]);
×
323
    }
324
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc