Percent::__construct()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 4
nc 2
nop 1
1
<?php
2
3
namespace linkprofit\Chance\ValueObjects;
4
5
use InvalidArgumentException;
6
7
class Percent
8
{
9
    /** @var int */
10
    protected $value;
11
12
    /**
13
     * Percent constructor.
14
     *
15
     * @param $value
16
     */
17
    public function __construct($value)
18
    {
19
        if ($value < 0 || $value > 100 || !filter_var($value, FILTER_VALIDATE_INT)) {
20
            throw new InvalidArgumentException('Percent value must be an integer and in range of 0 and 100');
21
        }
22
23
        $this->value = $value;
24
    }
25
26
    /**
27
     * @return int
28
     */
29
    public function getInt(): int
30
    {
31
        return (int) $this->value;
32
    }
33
}