Skip to content

Commit

Permalink
Improve typing
Browse files Browse the repository at this point in the history
  • Loading branch information
André Ekeberg committed May 20, 2020
1 parent aa786d0 commit ca55709
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 95 deletions.
6 changes: 3 additions & 3 deletions docs/Experiment.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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**

Expand All @@ -300,4 +300,4 @@ Return a Result instance from the current experiment

**Return Values**

`Result`
`Result`
22 changes: 11 additions & 11 deletions docs/Group.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand Down Expand Up @@ -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**

Expand Down Expand Up @@ -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**

Expand All @@ -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**

Expand Down Expand Up @@ -445,4 +445,4 @@ Define the group as the variation

**Return Values**

`self`
`self`
10 changes: 5 additions & 5 deletions docs/Result.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand Down Expand Up @@ -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**

Expand Down Expand Up @@ -263,4 +263,4 @@ Get complete results

**Return Values**

`object`
`object`
6 changes: 3 additions & 3 deletions docs/Token.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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**
Expand All @@ -161,4 +161,4 @@ This sends a cookie to the users browser with the configured settings, but with

**Return Values**

`self`
`self`
40 changes: 20 additions & 20 deletions docs/User.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand All @@ -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**
Expand All @@ -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**
Expand All @@ -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**
Expand All @@ -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
Expand All @@ -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`
Expand Down Expand Up @@ -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**
Expand All @@ -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`

Expand All @@ -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**
Expand All @@ -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**
**Return Values**
12 changes: 7 additions & 5 deletions src/Experiment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -131,7 +131,7 @@ private function mapGroup($key)
return $index;
}

return $key;
return (int)$key;
}

/**
Expand Down Expand Up @@ -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)');
}
Expand All @@ -276,4 +278,4 @@ public function getResult()
{
return new Result($this);
}
}
}
Loading

0 comments on commit ca55709

Please sign in to comment.