refactoring of ab classes
This commit is contained in:
parent
baf43e21f9
commit
280f7f01b1
|
@ -7,11 +7,11 @@ namespace App\Core\Ab;
|
||||||
*
|
*
|
||||||
* @author Simon Vieille <simon@deblan.fr>
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
*/
|
*/
|
||||||
class AbContainer
|
class AbContainer implements AbContainerInterface
|
||||||
{
|
{
|
||||||
protected array $tests = [];
|
protected array $tests = [];
|
||||||
|
|
||||||
public function add(AbTest $test): self
|
public function add(AbTestInterface $test): self
|
||||||
{
|
{
|
||||||
$this->tests[$test->getName()] = $test;
|
$this->tests[$test->getName()] = $test;
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ class AbContainer
|
||||||
return isset($this->tests[$name]);
|
return isset($this->tests[$name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get(string $name): AbTest
|
public function get(string $name): AbTestInterface
|
||||||
{
|
{
|
||||||
return $this->tests[$name];
|
return $this->tests[$name];
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ namespace App\Core\Ab;
|
||||||
*
|
*
|
||||||
* @author Simon Vieille <simon@deblan.fr>
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
*/
|
*/
|
||||||
class AbTest
|
class AbTest implements AbTestInterface
|
||||||
{
|
{
|
||||||
protected $results;
|
protected $results;
|
||||||
protected string $name;
|
protected string $name;
|
||||||
|
@ -106,7 +106,7 @@ class AbTest
|
||||||
|
|
||||||
krsort($this->probabilities);
|
krsort($this->probabilities);
|
||||||
|
|
||||||
$number = \rand(0, (int) \array_sum($this->probabilities) * 10);
|
$number = mt_rand(0, (int) array_sum($this->probabilities) * 10);
|
||||||
$starter = 0;
|
$starter = 0;
|
||||||
$return = '';
|
$return = '';
|
||||||
|
|
||||||
|
|
|
@ -221,7 +221,7 @@
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
{{ form_row(form.hasAbTest) }}
|
{{ form_row(form.hasAbTest) }}
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-6 {% if not form.vars.data.abTestCode %}d-none{% endif %}">
|
<div class="col-md-6 {% if not form.vars.data.hasAbTest %}d-none{% endif %}">
|
||||||
{{ form_row(form.abTestCode) }}
|
{{ form_row(form.abTestCode) }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
namespace App\Core\Twig\Extension;
|
namespace App\Core\Twig\Extension;
|
||||||
|
|
||||||
use App\Core\Ab\AbContainer;
|
use App\Core\Ab\AbContainer;
|
||||||
use App\Core\Ab\AbTest;
|
|
||||||
use Twig\Extension\AbstractExtension;
|
use Twig\Extension\AbstractExtension;
|
||||||
use Twig\TwigFunction;
|
use Twig\TwigFunction;
|
||||||
|
use App\Core\Ab\AbTestInterface;
|
||||||
|
|
||||||
class AbTestExtension extends AbstractExtension
|
class AbTestExtension extends AbstractExtension
|
||||||
{
|
{
|
||||||
|
@ -31,7 +31,7 @@ class AbTestExtension extends AbstractExtension
|
||||||
return $this->container->has($name);
|
return $this->container->has($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get(string $name): AbTest
|
public function get(string $name): AbTestInterface
|
||||||
{
|
{
|
||||||
return $this->container->get($name);
|
return $this->container->get($name);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue