RatioStrategy::calculate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 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