IsActive   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 2
c 3
b 1
f 1
lcom 0
cbo 2
dl 0
loc 29
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 4 1
1
<?php
2
/**
3
 * This file is part of phpab/phpab-module. (https://github.com/phpab/phpab-module)
4
 *
5
 * @link https://github.com/phpab/phpab-module for the canonical source repository
6
 * @copyright Copyright (c) 2015-2016 phpab. (https://github.com/phpab/)
7
 * @license https://raw.githubusercontent.com/phpab/phpab-module/master/LICENSE MIT
8
 */
9
10
namespace PhpAbModule\Controller\Plugin;
11
12
use PhpAb\Participation\ManagerInterface;
13
use Zend\Mvc\Controller\Plugin\AbstractPlugin;
14
15
/**
16
 * A controller plugin that can be used to check if a test is active.
17
 */
18
class IsActive extends AbstractPlugin
19
{
20
    /**
21
     * @var ManagerInterface The participation manager used to check participation.
22
     */
23
    private $participationManager;
24
25
    /**
26
     * Initializes a new instance of this class.
27
     *
28
     * @param ManagerInterface $participationManager The participation manager used to check participation.
29
     */
30
    public function __construct(ManagerInterface $participationManager)
31
    {
32
        $this->participationManager = $participationManager;
33
    }
34
35
    /**
36
     * Checks if the test with the given variant is active.
37
     *
38
     * @param string $test The identifier of the test to check for activity.
39
     * @param string $variant The identifier of the variant to check for activity.
40
     * @return bool
41
     */
42
    public function __invoke($test, $variant)
43
    {
44
        return $this->participationManager->participates($test, $variant) !== false;
45
    }
46
}
47