1 | <?php |
||
15 | class AbTesting |
||
16 | { |
||
17 | protected $experiments; |
||
18 | protected $visitor; |
||
19 | 48 | ||
20 | const SESSION_KEY_GOALS = 'ab_testing_goals'; |
||
21 | 48 | ||
22 | 48 | public function __construct() |
|
26 | |||
27 | /** |
||
28 | * Validates the config items and puts them into models. |
||
29 | 48 | * |
|
30 | * @return void |
||
31 | 48 | */ |
|
32 | 48 | protected function start() |
|
65 | |||
66 | /** |
||
67 | * Resets the visitor data. |
||
68 | 48 | * |
|
69 | * @return void |
||
70 | 48 | */ |
|
71 | 48 | public function resetVisitor() |
|
76 | 42 | ||
77 | /** |
||
78 | 9 | * Triggers a new visitor. Picks a new experiment and saves it to the Visitor. |
|
79 | * |
||
80 | * @param integer $visitor_id An optional visitor identifier |
||
81 | * |
||
82 | * @return \Ben182\AbTesting\Models\Experiment|void |
||
83 | */ |
||
84 | public function pageView($visitor_id = null) |
||
97 | |||
98 | /** |
||
99 | * Calculates a new experiment and sets it to the Visitor. |
||
100 | 42 | * |
|
101 | * @param VisitorInterface $visitor An object implementing VisitorInterface |
||
102 | 42 | * |
|
103 | * @return void |
||
104 | 42 | */ |
|
105 | protected function setNextExperiment(VisitorInterface $visitor) |
||
112 | |||
113 | /** |
||
114 | 9 | * Calculates a new experiment. |
|
115 | * |
||
116 | 9 | * @return \Ben182\AbTesting\Models\Experiment|null |
|
117 | */ |
||
118 | 9 | protected function getNextExperiment() |
|
124 | |||
125 | /** |
||
126 | * Checks if the currently active experiment is the given one. |
||
127 | * |
||
128 | 15 | * @param string $name The experiments name |
|
129 | * |
||
130 | 15 | * @return bool |
|
131 | 12 | */ |
|
132 | public function isExperiment(string $name) |
||
138 | |||
139 | /** |
||
140 | 12 | * Completes a goal by incrementing the hit property of the model and setting its ID in the session. |
|
141 | 3 | * |
|
142 | * @param string $goal The goals name |
||
143 | * @param integer $visitor_id An optional visitor identifier |
||
144 | 12 | * |
|
145 | * @return \Ben182\AbTesting\Models\Goal|false |
||
146 | 12 | */ |
|
147 | 12 | public function completeGoal(string $goal, $visitor_id = null) |
|
168 | |||
169 | 3 | /** |
|
170 | * Returns the currently active experiment. |
||
171 | * |
||
172 | * @param integer $visitor_id An optional visitor identifier |
||
173 | * |
||
174 | 3 | * @return \Ben182\AbTesting\Models\Experiment|null |
|
175 | 3 | */ |
|
176 | public function getExperiment($visitor_id = null) |
||
180 | |||
181 | /** |
||
182 | * Returns all the completed goals. |
||
183 | * |
||
184 | * @param integer $visitor_id An optional visitor identifier |
||
185 | * |
||
186 | * @return \Illuminate\Support\Collection|false |
||
187 | */ |
||
188 | public function getCompletedGoals() |
||
198 | |||
199 | /** |
||
200 | * Returns a visitor instance. |
||
201 | * |
||
202 | * @param integer $visitor_id An optional visitor identifier |
||
203 | * |
||
204 | * @return \Ben182\AbTesting\Models\SessionVisitor|\Ben182\AbTesting\Models\DatabaseVisitor |
||
205 | */ |
||
206 | public function getVisitor($visitor_id = null) |
||
218 | } |
||
219 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: