diff --git a/docs/Experiment.md b/docs/Experiment.md index 7780164..29cfcc6 100644 --- a/docs/Experiment.md +++ b/docs/Experiment.md @@ -267,7 +267,7 @@ This is the percentual chance that a new user will be included in the experiment **Description** ```php -public setAllocation (int $percent) +public setAllocation (int|string $percent) ``` Set experiment allocation @@ -276,7 +276,7 @@ This is the percentual chance that a new user will be included in the experiment **Parameters** -* `(int) $percent` +* `(int|string) $percent` **Return Values** @@ -300,4 +300,4 @@ Return a Result instance from the current experiment **Return Values** -`Result` \ No newline at end of file +`Result` diff --git a/docs/Group.md b/docs/Group.md index 1494ebf..2fbf07a 100644 --- a/docs/Group.md +++ b/docs/Group.md @@ -152,14 +152,14 @@ Get group views **Description** ```php -public setViews (int $views) +public setViews (int|string $views) ``` Set group views **Parameters** -* `(int) $views` +* `(int|string) $views` **Return Values** @@ -192,14 +192,14 @@ Get number of conversions for the group **Description** ```php -public setConversions (int $conversions) +public setConversions (int|string $conversions) ``` Set number of conversions for the group **Parameters** -* `(int) $conversions` +* `(int|string) $conversions` **Return Values** @@ -334,14 +334,14 @@ Returns 0 for control, 1 for variation and null when type is unknown **Description** ```php -public isType (int $type) +public isType (int|string $type) ``` -Get whether the variation is a specific type +Get whether the variation is a specific type (0 or 1) **Parameters** -* `(int) $type` +* `(int|string) $type` **Return Values** @@ -354,14 +354,14 @@ Get whether the variation is a specific type **Description** ```php -public setType (int $type) +public setType (int|string $type) ``` -Set group type +Set group type (0 or 1) **Parameters** -* `(int) $type` +* `(int|string) $type` **Return Values** @@ -445,4 +445,4 @@ Define the group as the variation **Return Values** -`self` \ No newline at end of file +`self` diff --git a/docs/Result.md b/docs/Result.md index 19dabca..859e503 100644 --- a/docs/Result.md +++ b/docs/Result.md @@ -42,14 +42,14 @@ Get the specified minimum confidence **Description** ```php -public setMinimumConfidence (float $confidence) +public setMinimumConfidence (float|string $confidence) ``` Set the minimum confidence **Parameters** -* `(float) $confidence` +* `(float|string) $confidence` **Return Values** @@ -82,14 +82,14 @@ Get the specified minimum detectable effect **Description** ```php -public setMinimumDetectableEffect (float $effect) +public setMinimumDetectableEffect (float|string $effect) ``` Set the minimum detectable effect **Parameters** -* `(float) $effect` +* `(float|string) $effect` **Return Values** @@ -263,4 +263,4 @@ Get complete results **Return Values** -`object` \ No newline at end of file +`object` diff --git a/docs/Token.md b/docs/Token.md index cdc8b0c..4199df3 100644 --- a/docs/Token.md +++ b/docs/Token.md @@ -123,7 +123,7 @@ Set tracking token value **Description** ```php -public setCookie (string|null $value, int|null $expires) +public setCookie (string|null $value, int|string|null $expires) ``` Set tracking cookie with the token name and value @@ -134,7 +134,7 @@ This sends a cookie to the users browser with the configured settings (and if pa * `(string|null) $value` : Defaults to configured value -* `(int|null) $expires` +* `(int|string|null) $expires` : Defaults to current time plus configured max age **Return Values** @@ -161,4 +161,4 @@ This sends a cookie to the users browser with the configured settings, but with **Return Values** -`self` \ No newline at end of file +`self` diff --git a/docs/User.md b/docs/User.md index 2eb4dc9..047418e 100644 --- a/docs/User.md +++ b/docs/User.md @@ -88,14 +88,14 @@ Get all user experiments **Description** ```php -public hasExperiment (Experiment|int $experiment) +public hasExperiment (Experiment|int|string $experiment) ``` Return whether the user has an experiment in the list, regardless of whether the user actually is part of it **Parameters** -* `(Experiment|int) $experiment` +* `(Experiment|int|string) $experiment` : Experiment instance or ID **Return Values** @@ -109,16 +109,16 @@ Return whether the user has an experiment in the list, regardless of whether the **Description** ```php -public isParticipant (Experiment|int $experiment, int|null $group) +public isParticipant (Experiment|int|string $experiment, int|string|null $group) ``` Return whether the user is a participant of an experiment, and optionally, part of a specific group **Parameters** -* `(Experiment|int) $experiment` +* `(Experiment|int|string) $experiment` : Experiment instance or ID -* `(int|null) $group` +* `(int|string|null) $group` : Group type (0 or 1) **Return Values** @@ -132,14 +132,14 @@ Return whether the user is a participant of an experiment, and optionally, part **Description** ```php -public inControl (Experiment|int $experiment) +public inControl (Experiment|int|string $experiment) ``` Return whether the user belongs to the control group of an experiment **Parameters** -* `(Experiment|int) $experiment` +* `(Experiment|int|string) $experiment` : Experiment instance or ID **Return Values** @@ -153,14 +153,14 @@ Return whether the user belongs to the control group of an experiment **Description** ```php -public inVariation (Experiment|int $experiment) +public inVariation (Experiment|int|string $experiment) ``` Return whether the user belongs to the variation group of an experiment **Parameters** -* `(Experiment|int) $experiment` +* `(Experiment|int|string) $experiment` : Experiment instance or ID **Return Values** @@ -174,7 +174,7 @@ Return whether the user belongs to the variation group of an experiment **Description** ```php -public addExperiment (Experiment|int $experiment, Group|null $group, bool $viewed, bool $converted) +public addExperiment (Experiment|int|string $experiment, Group|null $group, bool $viewed, bool $converted) ``` Add an experiment to the users list of experiments @@ -183,7 +183,7 @@ If no group is set, the experiment is added to to list without the user being as **Parameters** -* `(Experiment|id) $experiment` +* `(Experiment|id|string) $experiment` : Experiment instance or ID * `(Group|null) $group` * `(bool) $viewed` @@ -242,14 +242,14 @@ If the experiments coverage is below 100, it's percentage value will be used to **Description** ```php -public hasViewed (int $id) +public hasViewed (int|string $id) ``` Get whether a user has viewed a specific experiment **Parameters** -* `(int) $id` +* `(int|string) $id` : Experiment ID **Return Values** @@ -263,14 +263,14 @@ Get whether a user has viewed a specific experiment **Description** ```php -public setViewed (int $id, bool $viewed) +public setViewed (int|string $id, bool $viewed) ``` Set whether a user has viewed a specific experiment **Parameters** -* `(int) $id` +* `(int|string) $id` : Experiment ID * `(bool) $viewed` @@ -285,14 +285,14 @@ Set whether a user has viewed a specific experiment **Description** ```php -public hasConverted (int $id) +public hasConverted (int|string $id) ``` Get whether a user has converted in a specific experiment **Parameters** -* `(int) $id` +* `(int|string) $id` : Experiment ID **Return Values** @@ -306,15 +306,15 @@ Get whether a user has converted in a specific experiment **Description** ```php -public setConverted (int $id, bool $converted) +public setConverted (int|string $id, bool $converted) ``` Set whether a user has converted in a specific experiment **Parameters** -* `(int) $id` +* `(int|string) $id` : Experiment ID * `(bool) $converted` -**Return Values** \ No newline at end of file +**Return Values** diff --git a/src/Experiment.php b/src/Experiment.php index a822785..78f0a84 100644 --- a/src/Experiment.php +++ b/src/Experiment.php @@ -115,11 +115,11 @@ public function setName($name) */ private function mapGroup($key) { - if (is_string($key)) { + if (!is_numeric($key)) { $index = false; foreach ($this->groups as $i => $group) { - if ($group->getName() == $key) { + if ($group->getName() === $key) { $index = $i; } } @@ -131,7 +131,7 @@ private function mapGroup($key) return $index; } - return $key; + return (int)$key; } /** @@ -252,12 +252,14 @@ public function getAllocation() * * This is the percentual chance that a new user will be included in the experiment * - * @param int $percent + * @param int|string $percent * * @return self */ public function setAllocation($percent) { + $percent = (int)$percent; + if ($percent < 0 || $percent > 100) { throw new \Exception('Invalid $percent (value must be between 0 and 100)'); } @@ -276,4 +278,4 @@ public function getResult() { return new Result($this); } -} \ No newline at end of file +} diff --git a/src/Group.php b/src/Group.php index d404168..c661943 100644 --- a/src/Group.php +++ b/src/Group.php @@ -102,13 +102,13 @@ public function getViews() /** * Set group views * - * @param int $views + * @param int|string $views * * @return self */ public function setViews($views) { - return $this->setValue('views', $views); + return $this->setValue('views', (int)$views); } /** @@ -124,13 +124,13 @@ public function getConversions() /** * Set number of conversions for the group * - * @param int $conversions + * @param int|string $conversions * * @return self */ public function setConversions($conversions) { - return $this->setValue('conversions', $conversions); + return $this->setValue('conversions', (int)$conversions); } /** @@ -203,27 +203,27 @@ public function getType() } /** - * Get whether the variation is a specific type + * Get whether the variation is a specific type (0 or 1) * - * @param int $type + * @param int|string $type * * @return bool */ - public function isType(int $type) + public function isType($type) { - return $this->getType() === $type; + return $this->getType() === (int)$type; } /** - * Set group type + * Set group type (0 or 1) * - * @param int $type + * @param int|string $type * * @return self */ - public function setType(int $type) + public function setType($type) { - return $this->setValue('type', $type); + return $this->setValue('type', (int)$type); } /** @@ -265,4 +265,4 @@ public function setVariation() { return $this->setType(1); } -} \ No newline at end of file +} diff --git a/src/Result.php b/src/Result.php index 8433041..f6ad50a 100644 --- a/src/Result.php +++ b/src/Result.php @@ -246,13 +246,13 @@ public function getMinimumConfidence() /** * Set the minimum confidence * - * @param float $confidence + * @param float|string $confidence * * @return self */ public function setMinimumConfidence($confidence) { - $this->minimumConfidence = $confidence; + $this->minimumConfidence = (float)$confidence; return $this; } @@ -270,13 +270,13 @@ public function getMinimumDetectableEffect() /** * Set the minimum detectable effect * - * @param float $effect + * @param float|string $effect * * @return self */ public function setMinimumDetectableEffect($effect) { - $this->minimumDetectableEffect = $effect; + $this->minimumDetectableEffect = (float)$effect; return $this; } @@ -423,4 +423,4 @@ public function getAll() 'significant' => $this->significant ]; } -} \ No newline at end of file +} diff --git a/src/Token.php b/src/Token.php index 62f7885..27c72d6 100644 --- a/src/Token.php +++ b/src/Token.php @@ -112,7 +112,7 @@ public function generate($id = null) * passed, a custom value and expires timestamp) * * @param string|null $value Defaults to configured value - * @param int|null $expires Defaults to current time plus configured max age + * @param int|string|null $expires Defaults to current time plus configured max age * * @return self */ @@ -152,4 +152,4 @@ public function removeCookie() { return $this->setCookie(false, 1); } -} \ No newline at end of file +} diff --git a/src/User.php b/src/User.php index 834aa9a..2724175 100644 --- a/src/User.php +++ b/src/User.php @@ -93,16 +93,16 @@ public function hasExperiment($experiment) { if ($experiment instanceof Experiment) { $id = $experiment->getID(); - } else if (is_int($experiment)) { - $id = $experiment; + } else if (is_numeric($experiment)) { + $id = (int)$experiment; } else { throw new \Exception( - 'Invalid $experiment (type must be Abby\Experiment or int)' + 'Invalid $experiment (type must be Abby\Experiment or number)' ); } foreach ($this->experiments as $item) { - if ($item->id == $id) { + if ($item->id === $id) { return true; } } @@ -114,8 +114,8 @@ public function hasExperiment($experiment) * Return whether the user is a participant of an experiment (belongs to * either of the groups), and if passed, part of a specific group * - * @param Experiment|int $experiment Experiment instance or ID - * @param int|null $group Group type (0 or 1) + * @param Experiment|int|string $experiment Experiment instance or ID + * @param int|string|null $group Group type (0 or 1) * * @return bool */ @@ -123,19 +123,19 @@ public function isParticipant($experiment, $group = null) { if ($experiment instanceof Experiment) { $id = $experiment->getID(); - } else if (is_int($experiment)) { - $id = $experiment; + } else if (is_numeric($experiment)) { + $id = (int)$experiment; } else { throw new \Exception( - 'Invalid $experiment (type must be Abby\Experiment or int)' + 'Invalid $experiment (type must be Abby\Experiment or number)' ); } foreach ($this->experiments as $item) { - if ($item->id == $id) { + if ($item->id === $id) { if ($group === null && $item->group !== null) { return true; - } else if ($group !== null && $item->group === $group) { + } else if ($group !== null && $item->group === (int)$group) { return true; } } @@ -147,7 +147,7 @@ public function isParticipant($experiment, $group = null) /** * Return whether the user belongs to the control group of an experiment * - * @param Experiment|int $experiment Experiment instance or ID + * @param Experiment|int|string $experiment Experiment instance or ID * * @return bool */ @@ -159,7 +159,7 @@ public function inControl($experiment) /** * Return whether the user belongs to the variation group of an experiment * - * @param Experiment|int $experiment Experiment instance or ID + * @param Experiment|int|string $experiment Experiment instance or ID * * @return bool */ @@ -173,7 +173,7 @@ public function inVariation($experiment) * * If no group is set, the experiment is added to to list without the user being assigned a group * - * @param Experiment|int $experiment Experiment instance or ID + * @param Experiment|int|string $experiment Experiment instance or ID * @param Group|null $group * @param bool $converted * @@ -187,11 +187,11 @@ public function addExperiment( ) { if ($experiment instanceof Experiment) { $id = $experiment->getID(); - } else if (is_int($experiment)) { - $id = $experiment; + } else if (is_numeric($experiment)) { + $id = (int)$experiment; } else { throw new \Exception( - 'Invalid $experiment (type must be Abby\Experiment or int)' + 'Invalid $experiment (type must be Abby\Experiment or number)' ); } @@ -205,8 +205,8 @@ public function addExperiment( // Only set viewed and converted values if the user is part of an experiment group if ($group) { - $userExperiment->viewed = $viewed; - $userExperiment->converted = $converted; + $userExperiment->viewed = (bool)$viewed; + $userExperiment->converted = (bool)$converted; } // Add to list of experiments @@ -229,7 +229,7 @@ public function shouldParticipate(Experiment $experiment) $allocation = $experiment->getAllocation(); // Return true if allocation is 100% - if ($allocation == 100) { + if ($allocation === 100) { return true; } @@ -271,14 +271,14 @@ public function assignGroup(Experiment $experiment) /** * Get whether a user has viewed a specific experiment * - * @param int $id Experiment ID + * @param int|string $id Experiment ID * * @return bool */ public function hasViewed($id) { foreach ($this->experiments as $i => $experiment) { - if ($experiment->id == $id) { + if ($experiment->id === (int)$id) { if ($this->experiments[$i]->viewed) { return true; } @@ -291,7 +291,7 @@ public function hasViewed($id) /** * Set whether a user has viewed a specific experiment * - * @param int $id Experiment ID + * @param int|string $id Experiment ID * @param bool $viewed * * @return self @@ -299,7 +299,7 @@ public function hasViewed($id) public function setViewed($id, $viewed = true) { foreach ($this->experiments as $i => $experiment) { - if ($experiment->id == $id) { + if ($experiment->id === (int)$id) { $this->experiments[$i]->viewed = $viewed; } } @@ -310,14 +310,14 @@ public function setViewed($id, $viewed = true) /** * Get whether a user has converted in a specific experiment * - * @param int $id Experiment ID + * @param int|string $id Experiment ID * * @return bool */ public function hasConverted($id) { foreach ($this->experiments as $i => $experiment) { - if ($experiment->id == $id) { + if ($experiment->id === (int)$id) { if ($this->experiments[$i]->converted) { return true; } @@ -330,7 +330,7 @@ public function hasConverted($id) /** * Set whether a user has converted in a specific experiment * - * @param int $id Experiment ID + * @param int|string $id Experiment ID * @param bool $converted * * @return self @@ -338,7 +338,7 @@ public function hasConverted($id) public function setConverted($id, $converted = true) { foreach ($this->experiments as $i => $experiment) { - if ($experiment->id == $id) { + if ($experiment->id === (int)$id) { $this->experiments[$i]->converted = $converted; } }