RatioStrategy   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 4
dl 0
loc 18
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A calculate() 0 3 1
1
<?php
2
3
namespace linkprofit\Chance\Strategies;
4
5
use linkprofit\Chance\ValueObjects\Ratio;
6
7
/**
8
 * Вычисление вероятности по отношению к целому
9
 *
10
 * Например, когда надо вычислить веротяность в одной второй части случаев или в одной пятой и т.д.
11
 */
12
class RatioStrategy implements CalculationStrategyInterface
13
{
14
    /** @var int */
15
    protected $value;
16
17 8
    public function __construct(Ratio $ratio)
18
    {
19 8
        $this->value = $ratio->getInt();
20 8
    }
21
22
    /**
23
     * Calculate probability
24
     *
25
     * @return bool
26
     */
27 4
    public function calculate(): bool
28
    {
29 4
        return (mt_rand(1, $this->value) % $this->value) === 0;
30
    }
31
}
32