PercentStrategy   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 4
c 1
b 0
f 0
dl 0
loc 21
rs 10

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\Percent;
6
7
/**
8
 * Class PercentStrategy
9
 * @package linkprofit\Chance\Strategies
10
 */
11
class PercentStrategy implements CalculationStrategyInterface
12
{
13
    /** @var int */
14
    protected $value;
15
16
    /**
17
     * PercentStrategy constructor.
18
     *
19
     * @param Percent $percent
20
     */
21
    public function __construct(Percent $percent)
22
    {
23
        $this->value = $percent->getInt();
24
    }
25
26
    /**
27
     * @return bool
28
     */
29
    public function calculate(): bool
30
    {
31
        return mt_rand(1, 100) <= $this->value;
32
    }
33
}