CallbackVariant   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 3
c 1
b 1
f 0
lcom 1
cbo 0
dl 0
loc 44
ccs 9
cts 9
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getIdentifier() 0 4 1
A run() 0 4 1
1
<?php
2
/**
3
 * This file is part of phpab/phpab. (https://github.com/phpab/phpab)
4
 *
5
 * @link https://github.com/phpab/phpab for the canonical source repository
6
 * @copyright Copyright (c) 2015-2016 phpab. (https://github.com/phpab/)
7
 * @license https://raw.githubusercontent.com/phpab/phpab/master/LICENSE.md MIT
8
 */
9
10
namespace PhpAb\Variant;
11
12
/**
13
 * The representation of a variant that invokes a callback when ran.
14
 *
15
 * @package PhpAb
16
 */
17
class CallbackVariant implements VariantInterface
18
{
19
    /**
20
     * The identifier of this variant.
21
     *
22
     * @var string
23
     */
24
    private $identifier;
25
26
    /**
27
     * The callback that should be invoked when this variant is ran.
28
     *
29
     * @var callable
30
     */
31
    private $callback;
32
33
    /**
34
     * Initializes a new instance of this class.
35
     *
36
     * @param string $identifier The Identifier of the Variant
37
     * @param callable $callback The Callable to execute on run
38
     */
39 4
    public function __construct($identifier, callable $callback)
40
    {
41 4
        $this->identifier = $identifier;
42 4
        $this->callback = $callback;
43 4
    }
44
45
    /**
46
     * {@inheritDoc}
47
     */
48 1
    public function getIdentifier()
49
    {
50 1
        return $this->identifier;
51
    }
52
53
    /**
54
     * {@inheritDoc}
55
     */
56 3
    public function run()
57
    {
58 3
        call_user_func($this->callback);
59 2
    }
60
}
61