PercentStrategy::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 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
}