From 455968a3c830ed9f1c845235d5867fba08336004 Mon Sep 17 00:00:00 2001 From: kawtar1993 Date: Tue, 22 Mar 2022 15:45:59 +0100 Subject: [PATCH 01/29] Update composer.json --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index f249058..e9161d1 100644 --- a/composer.json +++ b/composer.json @@ -20,14 +20,14 @@ } ], "require": { - "php": "^7.2 | ^8.0", - "illuminate/support": "^6.0 | ^7.0", + "php": "^8.1.1", + "illuminate/support": "^9.2", "jaybizzle/crawler-detect": "^1.2" }, "require-dev": { "orchestra/testbench": "3.9.*", - "phpunit/phpunit": "^8.0 | ^9.0", - "mockery/mockery": "^1.0" + "phpunit/phpunit": "^9.0", + "mockery/mockery": "^1.3.1" }, "autoload": { "psr-4": { From ebe93bcad8df3bb822ed240f1caadf2961ed7871 Mon Sep 17 00:00:00 2001 From: kawtar1993 Date: Tue, 22 Mar 2022 15:56:50 +0100 Subject: [PATCH 02/29] Update composer.json --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index e9161d1..f249058 100644 --- a/composer.json +++ b/composer.json @@ -20,14 +20,14 @@ } ], "require": { - "php": "^8.1.1", - "illuminate/support": "^9.2", + "php": "^7.2 | ^8.0", + "illuminate/support": "^6.0 | ^7.0", "jaybizzle/crawler-detect": "^1.2" }, "require-dev": { "orchestra/testbench": "3.9.*", - "phpunit/phpunit": "^9.0", - "mockery/mockery": "^1.3.1" + "phpunit/phpunit": "^8.0 | ^9.0", + "mockery/mockery": "^1.0" }, "autoload": { "psr-4": { From 6768eb7a086435dc88ff94453c3d5deee571b5d5 Mon Sep 17 00:00:00 2001 From: kawtar1993 Date: Tue, 22 Mar 2022 16:02:31 +0100 Subject: [PATCH 03/29] Update composer.json --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index f249058..e9161d1 100644 --- a/composer.json +++ b/composer.json @@ -20,14 +20,14 @@ } ], "require": { - "php": "^7.2 | ^8.0", - "illuminate/support": "^6.0 | ^7.0", + "php": "^8.1.1", + "illuminate/support": "^9.2", "jaybizzle/crawler-detect": "^1.2" }, "require-dev": { "orchestra/testbench": "3.9.*", - "phpunit/phpunit": "^8.0 | ^9.0", - "mockery/mockery": "^1.0" + "phpunit/phpunit": "^9.0", + "mockery/mockery": "^1.3.1" }, "autoload": { "psr-4": { From bc7b1c70585e182c4daf1044760d46cc899124c5 Mon Sep 17 00:00:00 2001 From: kawtar1993 Date: Wed, 23 Mar 2022 10:10:53 +0100 Subject: [PATCH 04/29] Update config.php --- config/config.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/config/config.php b/config/config.php index 186fca1..577ec32 100644 --- a/config/config.php +++ b/config/config.php @@ -25,6 +25,17 @@ 'goals' => [], /* |-------------------------------------------------------------------------- + | Percentage + |-------------------------------------------------------------------------- + | + | Percentage by experiment. + | + | Example: [50, 50] + | + */ + 'percentages' => [], + /* + |-------------------------------------------------------------------------- | Ignore Crawlers |-------------------------------------------------------------------------- | From 9d6cd6ca5bd70dd5f871889e1085ced1850d4192 Mon Sep 17 00:00:00 2001 From: kawtar1993 Date: Wed, 23 Mar 2022 10:36:20 +0100 Subject: [PATCH 05/29] Update config.php --- config/config.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/config/config.php b/config/config.php index 577ec32..add65b1 100644 --- a/config/config.php +++ b/config/config.php @@ -36,6 +36,17 @@ 'percentages' => [], /* |-------------------------------------------------------------------------- + | Interval + |-------------------------------------------------------------------------- + | + | Date interval of AB testing. + | + | Example: ['2022-03-31 00:00:00', '2022-04-30 00:00:00'] + | + */ + 'interval' => [], + /* + |-------------------------------------------------------------------------- | Ignore Crawlers |-------------------------------------------------------------------------- | From 5c9bd83dc0d2b53af8a83b385e02f1079a91638b Mon Sep 17 00:00:00 2001 From: kawtar1993 Date: Wed, 23 Mar 2022 10:58:10 +0100 Subject: [PATCH 06/29] Update AbTesting.php --- src/AbTesting.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/AbTesting.php b/src/AbTesting.php index b7b8b03..d105f69 100644 --- a/src/AbTesting.php +++ b/src/AbTesting.php @@ -31,6 +31,7 @@ protected function start() { $configExperiments = config('ab-testing.experiments'); $configGoals = config('ab-testing.goals'); + $configPercentages = config('ab-testing.percentages'); if (! count($configExperiments)) { throw InvalidConfiguration::noExperiment(); @@ -39,6 +40,10 @@ protected function start() if (count($configExperiments) !== count(array_unique($configExperiments))) { throw InvalidConfiguration::experiment(); } + + if (count($configPercentages) !== count($configExperiments)) { + throw InvalidConfiguration::experiment(); + } if (count($configGoals) !== count(array_unique($configGoals))) { throw InvalidConfiguration::goal(); From 16494d991070c82be5b2016adb239f67cd99e12d Mon Sep 17 00:00:00 2001 From: kawtar1993 Date: Wed, 23 Mar 2022 11:01:47 +0100 Subject: [PATCH 07/29] Update InvalidConfiguration.php --- src/Exceptions/InvalidConfiguration.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Exceptions/InvalidConfiguration.php b/src/Exceptions/InvalidConfiguration.php index 015c148..e96612e 100644 --- a/src/Exceptions/InvalidConfiguration.php +++ b/src/Exceptions/InvalidConfiguration.php @@ -20,4 +20,9 @@ public static function goal(): self { return new static('The goal names should be unique.'); } + + public static function percentage(): self + { + return new static('There is no percentage for every experiment'); + } } From 79e70bca7b9d45ae975d18820ca899cb9771a642 Mon Sep 17 00:00:00 2001 From: kawtar1993 Date: Wed, 23 Mar 2022 11:06:47 +0100 Subject: [PATCH 08/29] Update AbTesting.php --- src/AbTesting.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AbTesting.php b/src/AbTesting.php index d105f69..e59b693 100644 --- a/src/AbTesting.php +++ b/src/AbTesting.php @@ -42,7 +42,7 @@ protected function start() } if (count($configPercentages) !== count($configExperiments)) { - throw InvalidConfiguration::experiment(); + throw InvalidConfiguration::percentage(); } if (count($configGoals) !== count(array_unique($configGoals))) { From 15dea409fffefc364dfac61435dc6a995152dfb9 Mon Sep 17 00:00:00 2001 From: kawtar1993 Date: Wed, 23 Mar 2022 12:15:59 +0100 Subject: [PATCH 09/29] Update InvalidConfiguration.php --- src/Exceptions/InvalidConfiguration.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Exceptions/InvalidConfiguration.php b/src/Exceptions/InvalidConfiguration.php index e96612e..06cf934 100644 --- a/src/Exceptions/InvalidConfiguration.php +++ b/src/Exceptions/InvalidConfiguration.php @@ -25,4 +25,9 @@ public static function percentage(): self { return new static('There is no percentage for every experiment'); } + + public static function totalPercentage(): self + { + return new static('Total percentage should be equal to 100'); + } } From be63544c6ba68642a525efe7214462fff320a943 Mon Sep 17 00:00:00 2001 From: kawtar1993 Date: Wed, 23 Mar 2022 12:18:47 +0100 Subject: [PATCH 10/29] Update AbTesting.php --- src/AbTesting.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/AbTesting.php b/src/AbTesting.php index e59b693..69cd1fd 100644 --- a/src/AbTesting.php +++ b/src/AbTesting.php @@ -32,6 +32,7 @@ protected function start() $configExperiments = config('ab-testing.experiments'); $configGoals = config('ab-testing.goals'); $configPercentages = config('ab-testing.percentages'); + $totalPercentage = array_sum($configPercentages); if (! count($configExperiments)) { throw InvalidConfiguration::noExperiment(); @@ -41,6 +42,10 @@ protected function start() throw InvalidConfiguration::experiment(); } + if ($totalPercentage !== 100) { + throw InvalidConfiguration::totalPercentage(); + } + if (count($configPercentages) !== count($configExperiments)) { throw InvalidConfiguration::percentage(); } @@ -48,6 +53,7 @@ protected function start() if (count($configGoals) !== count(array_unique($configGoals))) { throw InvalidConfiguration::goal(); } + foreach ($configExperiments as $configExperiment) { $this->experiments[] = $experiment = Experiment::with('goals')->firstOrCreate([ From e2c94fd849f7d2df458e6c190bef92dc251f3114 Mon Sep 17 00:00:00 2001 From: kawtar1993 Date: Wed, 23 Mar 2022 12:35:47 +0100 Subject: [PATCH 11/29] Update 2019_02_02_200315_create_experiments_table.php --- .../migrations/2019_02_02_200315_create_experiments_table.php | 1 + 1 file changed, 1 insertion(+) diff --git a/database/migrations/2019_02_02_200315_create_experiments_table.php b/database/migrations/2019_02_02_200315_create_experiments_table.php index 9d26207..067b04b 100644 --- a/database/migrations/2019_02_02_200315_create_experiments_table.php +++ b/database/migrations/2019_02_02_200315_create_experiments_table.php @@ -17,6 +17,7 @@ public function up() $table->increments('id'); $table->string('name')->unique(); $table->integer('visitors'); + $table->double('percentage'); $table->timestamps(); }); } From da1091b5194fc940d03a2d514eb910b06f13ccb0 Mon Sep 17 00:00:00 2001 From: kawtar1993 Date: Wed, 23 Mar 2022 12:38:12 +0100 Subject: [PATCH 12/29] Update Experiment.php --- src/Models/Experiment.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Models/Experiment.php b/src/Models/Experiment.php index 9973052..c661295 100644 --- a/src/Models/Experiment.php +++ b/src/Models/Experiment.php @@ -11,6 +11,7 @@ class Experiment extends Model protected $fillable = [ 'name', 'visitors', + 'percentage', ]; protected $casts = [ From 709765fc8d00d7ba7e6c21f763aba41a1bd92fdb Mon Sep 17 00:00:00 2001 From: kawtar1993 Date: Wed, 23 Mar 2022 12:45:35 +0100 Subject: [PATCH 13/29] Update AbTesting.php --- src/AbTesting.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/AbTesting.php b/src/AbTesting.php index 69cd1fd..1362b43 100644 --- a/src/AbTesting.php +++ b/src/AbTesting.php @@ -55,10 +55,11 @@ protected function start() } - foreach ($configExperiments as $configExperiment) { + foreach ($configExperiments as $index => $configExperiment) { $this->experiments[] = $experiment = Experiment::with('goals')->firstOrCreate([ 'name' => $configExperiment, ], [ + 'percentage' => $configPercentages[$index], 'visitors' => 0, ]); From 827719cacee58f4720627f314611f68a79442df4 Mon Sep 17 00:00:00 2001 From: kawtar1993 Date: Thu, 24 Mar 2022 10:51:16 +0100 Subject: [PATCH 14/29] Update AbTesting.php --- src/AbTesting.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/AbTesting.php b/src/AbTesting.php index 1362b43..ca6b7c0 100644 --- a/src/AbTesting.php +++ b/src/AbTesting.php @@ -122,9 +122,19 @@ protected function setNextExperiment() */ protected function getNextExperiment() { - $sorted = $this->experiments->sortBy('visitors'); - - return $sorted->first(); + $experiments = $this->experiments->sortByDesc('percentage'); + + $visitorsSum = $experiments->sum('visitors'); + + $nextExperiment = collect([]); + + if($visitorsSum != 0) + { + $nextExperiment = $experiments->find(function($experiment){ + return (($experiment->visitors / $visitorsSum) * 100) < $experiment->percentage; + }); + } + return !$nextExperiment->isEmpty() ? $nextExperiment : $experiments->first(); } /** From 55286e03dc4ff00b87526745a2939f422fe94953 Mon Sep 17 00:00:00 2001 From: kawtar1993 Date: Thu, 24 Mar 2022 11:23:01 +0100 Subject: [PATCH 15/29] Update AbTesting.php --- src/AbTesting.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AbTesting.php b/src/AbTesting.php index ca6b7c0..59e007a 100644 --- a/src/AbTesting.php +++ b/src/AbTesting.php @@ -130,7 +130,7 @@ protected function getNextExperiment() if($visitorsSum != 0) { - $nextExperiment = $experiments->find(function($experiment){ + $nextExperiment = $experiments->filter(function($experiment) use ($visitorsSum) { return (($experiment->visitors / $visitorsSum) * 100) < $experiment->percentage; }); } From 1cbf27314e0a8007519f368e1d6739cc0ef2162a Mon Sep 17 00:00:00 2001 From: kawtar1993 Date: Thu, 24 Mar 2022 11:25:59 +0100 Subject: [PATCH 16/29] Update AbTesting.php --- src/AbTesting.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AbTesting.php b/src/AbTesting.php index 59e007a..35bbf6b 100644 --- a/src/AbTesting.php +++ b/src/AbTesting.php @@ -134,7 +134,7 @@ protected function getNextExperiment() return (($experiment->visitors / $visitorsSum) * 100) < $experiment->percentage; }); } - return !$nextExperiment->isEmpty() ? $nextExperiment : $experiments->first(); + return !$nextExperiment->isEmpty() ? $nextExperiment->first() : $experiments->first(); } /** From 4d4b2622505698a15834a97aeccceb11a7bb6f6c Mon Sep 17 00:00:00 2001 From: kawtar1993 Date: Fri, 25 Mar 2022 09:20:42 +0100 Subject: [PATCH 17/29] Update AbTesting.php --- src/AbTesting.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/AbTesting.php b/src/AbTesting.php index 35bbf6b..8a72957 100644 --- a/src/AbTesting.php +++ b/src/AbTesting.php @@ -9,6 +9,7 @@ use Ben182\AbTesting\Models\Goal; use Illuminate\Support\Collection; use Jaybizzle\CrawlerDetect\CrawlerDetect; +use Carbon\Carbon; class AbTesting { @@ -84,6 +85,8 @@ protected function start() */ public function pageView() { + $interval = config('ab-testing.interval'); + if (config('ab-testing.ignore_crawlers') && (new CrawlerDetect)->isCrawler()) { return; } @@ -91,6 +94,10 @@ public function pageView() if (session(self::SESSION_KEY_EXPERIMENT)) { return; } + + if (!empty($interval) && !$this->inInterval($interval)) { + return; + } $this->start(); $this->setNextExperiment(); @@ -99,6 +106,19 @@ public function pageView() return $this->getExperiment(); } + + /** + * Check if the current date is in the interval + * + * @return bool + */ + protected function inInterval($interval) + { + $currentDate = Carbon::now(); + $startDate = Carbon::createFromFormat('Y-m-d H:i:s', $interval[0]); + $endDate = Carbon::createFromFormat('Y-m-d H:i:s', $interval[1]); + return $currentDate->between($startDate,$endDate); + } /** * Calculates a new experiment and sets it to the session. From 7158b753add6011be92f6caf5599ca4c5a0b87a6 Mon Sep 17 00:00:00 2001 From: kawtar1993 Date: Fri, 25 Mar 2022 10:24:49 +0100 Subject: [PATCH 18/29] Update AbTesting.php --- src/AbTesting.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/AbTesting.php b/src/AbTesting.php index 8a72957..8bec6b9 100644 --- a/src/AbTesting.php +++ b/src/AbTesting.php @@ -33,6 +33,7 @@ protected function start() $configExperiments = config('ab-testing.experiments'); $configGoals = config('ab-testing.goals'); $configPercentages = config('ab-testing.percentages'); + $configInterval = config('ab-testing.interval'); $totalPercentage = array_sum($configPercentages); if (! count($configExperiments)) { @@ -55,6 +56,12 @@ protected function start() throw InvalidConfiguration::goal(); } + if(count($configInterval) == 1 || + (count($configInterval) == 2 && (!Carbon::createFromFormat('Y-m-d H:i:s', $interval[0]) || !Carbon::createFromFormat('Y-m-d H:i:s', $interval[1]))) || + (count($configInterval) == 2 && Carbon::createFromFormat('Y-m-d H:i:s', $interval[0])->gt(Carbon::createFromFormat('Y-m-d H:i:s', $interval[1])))) { + + } + foreach ($configExperiments as $index => $configExperiment) { $this->experiments[] = $experiment = Experiment::with('goals')->firstOrCreate([ From 525187eb1f90fc65d42f144988c8f2108c5b5f1c Mon Sep 17 00:00:00 2001 From: kawtar1993 Date: Fri, 25 Mar 2022 10:29:13 +0100 Subject: [PATCH 19/29] Update InvalidConfiguration.php --- src/Exceptions/InvalidConfiguration.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Exceptions/InvalidConfiguration.php b/src/Exceptions/InvalidConfiguration.php index 06cf934..c4f4618 100644 --- a/src/Exceptions/InvalidConfiguration.php +++ b/src/Exceptions/InvalidConfiguration.php @@ -30,4 +30,9 @@ public static function totalPercentage(): self { return new static('Total percentage should be equal to 100'); } + + public static function interval(): self + { + return new static('The elements of interval array must be dates of format Y-m-d H:i:s and the first element less than the second'); + } } From 489ebabe34a40a5b2f5405dafa69319570c97faa Mon Sep 17 00:00:00 2001 From: kawtar1993 Date: Fri, 25 Mar 2022 10:31:16 +0100 Subject: [PATCH 20/29] Update AbTesting.php --- src/AbTesting.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AbTesting.php b/src/AbTesting.php index 8bec6b9..ad1e7b5 100644 --- a/src/AbTesting.php +++ b/src/AbTesting.php @@ -59,7 +59,7 @@ protected function start() if(count($configInterval) == 1 || (count($configInterval) == 2 && (!Carbon::createFromFormat('Y-m-d H:i:s', $interval[0]) || !Carbon::createFromFormat('Y-m-d H:i:s', $interval[1]))) || (count($configInterval) == 2 && Carbon::createFromFormat('Y-m-d H:i:s', $interval[0])->gt(Carbon::createFromFormat('Y-m-d H:i:s', $interval[1])))) { - + throw InvalidConfiguration::interval(); } From 9990b70d59cf22bbcb1520c986a5f4def71ca014 Mon Sep 17 00:00:00 2001 From: kawtar1993 Date: Fri, 25 Mar 2022 10:50:10 +0100 Subject: [PATCH 21/29] Update AbTesting.php --- src/AbTesting.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AbTesting.php b/src/AbTesting.php index ad1e7b5..2c9de11 100644 --- a/src/AbTesting.php +++ b/src/AbTesting.php @@ -57,8 +57,8 @@ protected function start() } if(count($configInterval) == 1 || - (count($configInterval) == 2 && (!Carbon::createFromFormat('Y-m-d H:i:s', $interval[0]) || !Carbon::createFromFormat('Y-m-d H:i:s', $interval[1]))) || - (count($configInterval) == 2 && Carbon::createFromFormat('Y-m-d H:i:s', $interval[0])->gt(Carbon::createFromFormat('Y-m-d H:i:s', $interval[1])))) { + (count($configInterval) == 2 && (!Carbon::createFromFormat('Y-m-d H:i:s', configInterval[0]) || !Carbon::createFromFormat('Y-m-d H:i:s', configInterval[1]))) || + (count($configInterval) == 2 && Carbon::createFromFormat('Y-m-d H:i:s', configInterval[0])->gt(Carbon::createFromFormat('Y-m-d H:i:s', configInterval[1])))) { throw InvalidConfiguration::interval(); } From 93e7e69dc76d9ac48868267882b73fcf9acb1834 Mon Sep 17 00:00:00 2001 From: kawtar1993 Date: Fri, 25 Mar 2022 10:51:59 +0100 Subject: [PATCH 22/29] Update AbTesting.php --- src/AbTesting.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AbTesting.php b/src/AbTesting.php index 2c9de11..41184cc 100644 --- a/src/AbTesting.php +++ b/src/AbTesting.php @@ -57,8 +57,8 @@ protected function start() } if(count($configInterval) == 1 || - (count($configInterval) == 2 && (!Carbon::createFromFormat('Y-m-d H:i:s', configInterval[0]) || !Carbon::createFromFormat('Y-m-d H:i:s', configInterval[1]))) || - (count($configInterval) == 2 && Carbon::createFromFormat('Y-m-d H:i:s', configInterval[0])->gt(Carbon::createFromFormat('Y-m-d H:i:s', configInterval[1])))) { + (count($configInterval) == 2 && (!Carbon::createFromFormat('Y-m-d H:i:s', $configInterval[0]) || !Carbon::createFromFormat('Y-m-d H:i:s', $configInterval[1]))) || + (count($configInterval) == 2 && Carbon::createFromFormat('Y-m-d H:i:s', $configInterval[0])->gt(Carbon::createFromFormat('Y-m-d H:i:s', $configInterval[1])))) { throw InvalidConfiguration::interval(); } From 91dea45c176504fb2ffa845c35627e1edb049629 Mon Sep 17 00:00:00 2001 From: kawtar1993 Date: Fri, 25 Mar 2022 10:58:00 +0100 Subject: [PATCH 23/29] Update AbTesting.php --- src/AbTesting.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AbTesting.php b/src/AbTesting.php index 41184cc..9b8351e 100644 --- a/src/AbTesting.php +++ b/src/AbTesting.php @@ -55,7 +55,7 @@ protected function start() if (count($configGoals) !== count(array_unique($configGoals))) { throw InvalidConfiguration::goal(); } - + dd(count($configInterval)); if(count($configInterval) == 1 || (count($configInterval) == 2 && (!Carbon::createFromFormat('Y-m-d H:i:s', $configInterval[0]) || !Carbon::createFromFormat('Y-m-d H:i:s', $configInterval[1]))) || (count($configInterval) == 2 && Carbon::createFromFormat('Y-m-d H:i:s', $configInterval[0])->gt(Carbon::createFromFormat('Y-m-d H:i:s', $configInterval[1])))) { From ce123437b006510024de57f3c9b36f35866a149f Mon Sep 17 00:00:00 2001 From: kawtar1993 Date: Fri, 25 Mar 2022 11:00:07 +0100 Subject: [PATCH 24/29] Update AbTesting.php --- src/AbTesting.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/AbTesting.php b/src/AbTesting.php index 9b8351e..9e31121 100644 --- a/src/AbTesting.php +++ b/src/AbTesting.php @@ -55,7 +55,8 @@ protected function start() if (count($configGoals) !== count(array_unique($configGoals))) { throw InvalidConfiguration::goal(); } - dd(count($configInterval)); + var_dump(count($configInterval)); + exit; if(count($configInterval) == 1 || (count($configInterval) == 2 && (!Carbon::createFromFormat('Y-m-d H:i:s', $configInterval[0]) || !Carbon::createFromFormat('Y-m-d H:i:s', $configInterval[1]))) || (count($configInterval) == 2 && Carbon::createFromFormat('Y-m-d H:i:s', $configInterval[0])->gt(Carbon::createFromFormat('Y-m-d H:i:s', $configInterval[1])))) { From bca9341c662bbd949e55cbe6d9871eece8a8315c Mon Sep 17 00:00:00 2001 From: kawtar1993 Date: Fri, 25 Mar 2022 11:03:36 +0100 Subject: [PATCH 25/29] Update AbTesting.php --- src/AbTesting.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/AbTesting.php b/src/AbTesting.php index 9e31121..a47cfe7 100644 --- a/src/AbTesting.php +++ b/src/AbTesting.php @@ -55,13 +55,6 @@ protected function start() if (count($configGoals) !== count(array_unique($configGoals))) { throw InvalidConfiguration::goal(); } - var_dump(count($configInterval)); - exit; - if(count($configInterval) == 1 || - (count($configInterval) == 2 && (!Carbon::createFromFormat('Y-m-d H:i:s', $configInterval[0]) || !Carbon::createFromFormat('Y-m-d H:i:s', $configInterval[1]))) || - (count($configInterval) == 2 && Carbon::createFromFormat('Y-m-d H:i:s', $configInterval[0])->gt(Carbon::createFromFormat('Y-m-d H:i:s', $configInterval[1])))) { - throw InvalidConfiguration::interval(); - } foreach ($configExperiments as $index => $configExperiment) { @@ -93,7 +86,13 @@ protected function start() */ public function pageView() { - $interval = config('ab-testing.interval'); + $configInterval = config('ab-testing.interval'); + + if(count($configInterval) == 1 || + (count($configInterval) == 2 && (!Carbon::createFromFormat('Y-m-d H:i:s', $configInterval[0]) || !Carbon::createFromFormat('Y-m-d H:i:s', $configInterval[1]))) || + (count($configInterval) == 2 && Carbon::createFromFormat('Y-m-d H:i:s', $configInterval[0])->gt(Carbon::createFromFormat('Y-m-d H:i:s', $configInterval[1])))) { + throw InvalidConfiguration::interval(); + } if (config('ab-testing.ignore_crawlers') && (new CrawlerDetect)->isCrawler()) { return; @@ -103,7 +102,7 @@ public function pageView() return; } - if (!empty($interval) && !$this->inInterval($interval)) { + if (!empty($configInterval) && !$this->inInterval($configInterval)) { return; } From e1129ecc50ced18e09d35185feed50efb6cc4e31 Mon Sep 17 00:00:00 2001 From: kawtar1993 Date: Fri, 25 Mar 2022 12:44:33 +0100 Subject: [PATCH 26/29] Update InvalidConfiguration.php --- src/Exceptions/InvalidConfiguration.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Exceptions/InvalidConfiguration.php b/src/Exceptions/InvalidConfiguration.php index c4f4618..8302fd0 100644 --- a/src/Exceptions/InvalidConfiguration.php +++ b/src/Exceptions/InvalidConfiguration.php @@ -31,6 +31,11 @@ public static function totalPercentage(): self return new static('Total percentage should be equal to 100'); } + public static function numericPercentage(): self + { + return new static('Percentages should be numeric'); + } + public static function interval(): self { return new static('The elements of interval array must be dates of format Y-m-d H:i:s and the first element less than the second'); From 05f01e3fd98a6bd77a8bd72d938b954afd92cb6a Mon Sep 17 00:00:00 2001 From: kawtar1993 Date: Fri, 25 Mar 2022 12:46:07 +0100 Subject: [PATCH 27/29] Update InvalidConfiguration.php --- src/Exceptions/InvalidConfiguration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Exceptions/InvalidConfiguration.php b/src/Exceptions/InvalidConfiguration.php index 8302fd0..5361e9c 100644 --- a/src/Exceptions/InvalidConfiguration.php +++ b/src/Exceptions/InvalidConfiguration.php @@ -31,7 +31,7 @@ public static function totalPercentage(): self return new static('Total percentage should be equal to 100'); } - public static function numericPercentage(): self + public static function numericPercentages(): self { return new static('Percentages should be numeric'); } From 84d6a0c9863422b8d5099e99e0d4560aeda86bdf Mon Sep 17 00:00:00 2001 From: kawtar1993 Date: Fri, 25 Mar 2022 12:46:35 +0100 Subject: [PATCH 28/29] Update AbTesting.php --- src/AbTesting.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/AbTesting.php b/src/AbTesting.php index a47cfe7..4ac5085 100644 --- a/src/AbTesting.php +++ b/src/AbTesting.php @@ -34,6 +34,15 @@ protected function start() $configGoals = config('ab-testing.goals'); $configPercentages = config('ab-testing.percentages'); $configInterval = config('ab-testing.interval'); + + $ConfigPercentagesNumeric = array_filter($configPercentages, function($percentage) { + return is_numeric($percentage); + }); + + if (count($isConfigPercentagesNumeric) !== count($configPercentages)) { + throw InvalidConfiguration::numericPercentages(); + } + $totalPercentage = array_sum($configPercentages); if (! count($configExperiments)) { From 37d9b54ea712de0fbabb2bb9c728aa059fd562e6 Mon Sep 17 00:00:00 2001 From: kawtar1993 Date: Fri, 25 Mar 2022 12:48:44 +0100 Subject: [PATCH 29/29] Update AbTesting.php --- src/AbTesting.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AbTesting.php b/src/AbTesting.php index 4ac5085..894c685 100644 --- a/src/AbTesting.php +++ b/src/AbTesting.php @@ -35,11 +35,11 @@ protected function start() $configPercentages = config('ab-testing.percentages'); $configInterval = config('ab-testing.interval'); - $ConfigPercentagesNumeric = array_filter($configPercentages, function($percentage) { + $configPercentagesNumeric = array_filter($configPercentages, function($percentage) { return is_numeric($percentage); }); - if (count($isConfigPercentagesNumeric) !== count($configPercentages)) { + if (count($configPercentagesNumeric) !== count($configPercentages)) { throw InvalidConfiguration::numericPercentages(); }