Percent   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 6
c 1
b 0
f 0
dl 0
loc 25
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 4
A getInt() 0 3 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
}