1 | <?php |
||
12 | class AbTesting |
||
13 | { |
||
14 | protected $experiments; |
||
15 | |||
16 | const SESSION_KEY_EXPERIMENT = 'ab_testing_experiment'; |
||
17 | const SESSION_KEY_GOALS = 'ab_testing_goals'; |
||
18 | |||
19 | 48 | public function __construct() |
|
23 | |||
24 | /** |
||
25 | * Validates the config items and puts them into models. |
||
26 | * |
||
27 | * @return void |
||
28 | */ |
||
29 | 48 | protected function start() |
|
62 | |||
63 | /** |
||
64 | * Triggers a new visitor. Picks a new experiment and saves it to the session. |
||
65 | * |
||
66 | * @return \Ben182\AbTesting\Models\Experiment|void |
||
67 | */ |
||
68 | 48 | public function pageView() |
|
69 | { |
||
70 | 48 | if (! session(self::SESSION_KEY_EXPERIMENT)) { |
|
71 | 48 | $this->start(); |
|
72 | 42 | $this->setNextExperiment(); |
|
73 | |||
74 | 42 | event(new ExperimentNewVisitor($this->getExperiment())); |
|
75 | |||
76 | 42 | return $this->getExperiment(); |
|
77 | } |
||
78 | 9 | } |
|
79 | |||
80 | /** |
||
81 | * Calculates a new experiment and sets it to the session. |
||
82 | * |
||
83 | * @return void |
||
84 | */ |
||
85 | 42 | protected function setNextExperiment() |
|
94 | |||
95 | /** |
||
96 | * Calculates a new experiment. |
||
97 | * |
||
98 | * @return \Ben182\AbTesting\Models\Experiment|null |
||
99 | */ |
||
100 | 42 | protected function getNextExperiment() |
|
106 | |||
107 | /** |
||
108 | * Checks if the currently active experiment is the given one. |
||
109 | * |
||
110 | * @param string $name The experiments name |
||
111 | * |
||
112 | * @return bool |
||
113 | */ |
||
114 | 9 | public function isExperiment(string $name) |
|
120 | |||
121 | /** |
||
122 | * Completes a goal by incrementing the hit property of the model and setting its ID in the session. |
||
123 | * |
||
124 | * @param string $goal The goals name |
||
125 | * |
||
126 | * @return \Ben182\AbTesting\Models\Goal|false |
||
127 | */ |
||
128 | 15 | public function completeGoal(string $goal) |
|
151 | |||
152 | /** |
||
153 | * Returns the currently active experiment. |
||
154 | * |
||
155 | * @return \Ben182\AbTesting\Models\Experiment|null |
||
156 | */ |
||
157 | 42 | public function getExperiment() |
|
161 | |||
162 | /** |
||
163 | * Returns all the completed goals. |
||
164 | * |
||
165 | * @return \Illuminate\Support\Collection|false |
||
166 | */ |
||
167 | 3 | public function getCompletedGoals() |
|
177 | } |
||
178 |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.