|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* Copyright Humbly Arrogant Ltd 2020-2022. |
|
7
|
|
|
* |
|
8
|
|
|
* Use of this software is governed by the Business Source License included in the LICENSE file and at https://getparthenon.com/docs/next/license. |
|
9
|
|
|
* |
|
10
|
|
|
* Change Date: TBD ( 3 years after 2.0.0 release ) |
|
11
|
|
|
* |
|
12
|
|
|
* On the date above, in accordance with the Business Source License, use of this software will be governed by the open source license specified in the LICENSE file. |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace Parthenon\AbTesting\Entity; |
|
16
|
|
|
|
|
17
|
|
|
use Parthenon\Athena\Entity\DeletableInterface; |
|
18
|
|
|
use Ramsey\Uuid\UuidInterface; |
|
19
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
|
20
|
|
|
|
|
21
|
|
|
class Experiment implements DeletableInterface |
|
22
|
|
|
{ |
|
23
|
|
|
protected UuidInterface $id; |
|
24
|
|
|
|
|
25
|
|
|
protected ?\DateTimeInterface $deletedAt; |
|
26
|
|
|
|
|
27
|
|
|
protected $isDeleted = false; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @Assert\NotBlank |
|
31
|
|
|
*/ |
|
32
|
|
|
private string $type; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @Assert\NotBlank |
|
36
|
|
|
*/ |
|
37
|
|
|
private string $name; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @Assert\NotBlank |
|
41
|
|
|
*/ |
|
42
|
|
|
private string $desiredResult; |
|
43
|
|
|
|
|
44
|
|
|
private \DateTime $createdAt; |
|
45
|
|
|
|
|
46
|
|
|
private ?\DateTime $updatedAt; |
|
47
|
|
|
|
|
48
|
|
|
private $variants = []; |
|
49
|
|
|
|
|
50
|
|
|
public function __construct() |
|
51
|
|
|
{ |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function getId() |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->id; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function setId(UuidInterface $id): void |
|
60
|
|
|
{ |
|
61
|
|
|
$this->id = $id; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function getType(): string |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->type; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function setType(string $type): void |
|
70
|
|
|
{ |
|
71
|
|
|
$this->type = $type; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function getName(): string |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->name; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function setName(string $name): void |
|
80
|
|
|
{ |
|
81
|
|
|
$this->name = $name; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function getCreatedAt(): \DateTime |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->createdAt; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function setCreatedAt(\DateTime $createdAt): void |
|
90
|
|
|
{ |
|
91
|
|
|
$this->createdAt = $createdAt; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function getUpdatedAt(): ?\DateTime |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->updatedAt; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function setUpdatedAt(?\DateTime $updatedAt): void |
|
100
|
|
|
{ |
|
101
|
|
|
$this->updatedAt = $updatedAt; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function setDeletedAt(\DateTimeInterface $dateTime): DeletableInterface |
|
105
|
|
|
{ |
|
106
|
|
|
$this->deletedAt = $dateTime; |
|
107
|
|
|
|
|
108
|
|
|
return $this; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function getDeletedAt(): ?\DateTimeInterface |
|
112
|
|
|
{ |
|
113
|
|
|
return $this->deletedAt; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
public function isDeleted(): bool |
|
117
|
|
|
{ |
|
118
|
|
|
return $this->isDeleted; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
public function markAsDeleted(): DeletableInterface |
|
122
|
|
|
{ |
|
123
|
|
|
$this->isDeleted = true; |
|
124
|
|
|
$this->deletedAt = new \DateTime('Now'); |
|
125
|
|
|
|
|
126
|
|
|
return $this; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
public function unmarkAsDeleted(): DeletableInterface |
|
130
|
|
|
{ |
|
131
|
|
|
$this->isDeleted = false; |
|
132
|
|
|
$this->deletedAt = null; |
|
133
|
|
|
|
|
134
|
|
|
return $this; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
public function getDesiredResult(): string |
|
138
|
|
|
{ |
|
139
|
|
|
return $this->desiredResult; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
public function setDesiredResult(string $desiredResult): void |
|
143
|
|
|
{ |
|
144
|
|
|
$this->desiredResult = $desiredResult; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* @return Variant[] |
|
149
|
|
|
*/ |
|
150
|
|
|
public function getVariants() |
|
151
|
|
|
{ |
|
152
|
|
|
return $this->variants; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
public function setVariants($variants): void |
|
156
|
|
|
{ |
|
157
|
|
|
$this->variants = $variants; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* @Assert\EqualTo(100, message="Variant percentages should equal 100") |
|
162
|
|
|
*/ |
|
163
|
|
|
public function getTotalPercentage(): int |
|
164
|
|
|
{ |
|
165
|
|
|
$total = 0; |
|
166
|
|
|
/** @var Variant $variant */ |
|
167
|
|
|
foreach ($this->variants as $variant) { |
|
168
|
|
|
$total += $variant->getPercentage(); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
return $total; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* @Assert\LessThanOrEqual(1, message="There can only be one default variant") |
|
176
|
|
|
*/ |
|
177
|
|
|
public function getNumberOfDefaultVariants(): int |
|
178
|
|
|
{ |
|
179
|
|
|
$count = 0; |
|
180
|
|
|
foreach ($this->variants as $variant) { |
|
181
|
|
|
if ($variant->isIsDefault()) { |
|
182
|
|
|
++$count; |
|
183
|
|
|
} |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
return $count; |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
public function isPredecided(): bool |
|
190
|
|
|
{ |
|
191
|
|
|
foreach ($this->variants as $variant) { |
|
192
|
|
|
if ($variant->isIsDefault()) { |
|
193
|
|
|
return true; |
|
194
|
|
|
} |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
return false; |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
public function isUserBased(): bool |
|
201
|
|
|
{ |
|
202
|
|
|
return 'user' === $this->type; |
|
203
|
|
|
} |
|
204
|
|
|
} |
|
205
|
|
|
|