Variation::getNbFailures()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace BenTools\SplitTestAnalyzer;
4
5
final class Variation
6
{
7
    /**
8
     * @var string|int
9
     */
10
    private $key;
11
12
    /**
13
     * @var int
14
     */
15
    private $nbTotalActions;
16
17
    /**
18
     * @var int
19
     */
20
    private $nbSuccessfulActions;
21
22
    /**
23
     * Version constructor.
24
     * @param string $key
25
     * @param int    $nbTotalActions
26
     * @param int    $nbSuccessfulActions
27
     * @throws \InvalidArgumentException
28
     */
29
    public function __construct(string $key, int $nbTotalActions, int $nbSuccessfulActions)
30
    {
31
        $this->key = $key;
32
        $this->nbTotalActions = max(0, $nbTotalActions);
33
        $this->nbSuccessfulActions = max(0, $nbSuccessfulActions);
34
        if ($this->nbSuccessfulActions > $this->nbTotalActions) {
35
            throw new \InvalidArgumentException("The number of successful actions should not exceed the total number of actions.");
36
        }
37
    }
38
39
    /**
40
     * @return string|int
41
     */
42
    public function getKey(): string
43
    {
44
        return $this->key;
45
    }
46
47
    /**
48
     * @return int
49
     */
50
    public function getNbSuccesses(): int
51
    {
52
        return $this->nbSuccessfulActions;
53
    }
54
55
    /**
56
     * @return int
57
     */
58
    public function getNbFailures(): int
59
    {
60
        $result = $this->nbTotalActions - $this->nbSuccessfulActions;
61
        return $result;
62
    }
63
64
    public function __toString()
65
    {
66
        return $this->key;
67
    }
68
}
69