Completed
Pull Request — master (#75)
by
unknown
01:26
created

UnsignedInt   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 20
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace TraderInteractive\Filter;
4
5
/**
6
 * A collection of filters for unsigned integers.
7
 */
8
final class UnsignedInt
9
{
10
    /**
11
     * Filters $value to an unsigned integer strictly.
12
     *
13
     * @see \TraderInteractive\Filter\Ints::filter()
14
     *
15
     * @param mixed $value     The value to be checked.
16
     * @param bool  $allowNull Indicates if the value can be null.
17
     * @param int   $minValue  Indicates the minimum acceptable value.
18
     * @param int   $maxValue  Indicates the maximum acceptable value.
19
     *
20
     * @return int|null
21
     *
22
     * @throws Exception
23
     */
24
    public static function filter($value, bool $allowNull = false, int $minValue = null, int $maxValue = PHP_INT_MAX)
25
    {
26
        if ($minValue === null) {
27
            $minValue = 0;
28
        } elseif (is_int($minValue) && $minValue < 0) {
29
            throw new \InvalidArgumentException("{$minValue} was not greater or equal to zero");
30
        }
31
32
        return Ints::filter($value, $allowNull, $minValue, $maxValue);
33
    }
34
}
35