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

UnsignedInt::filter()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.2
c 0
b 0
f 0
cc 4
eloc 6
nc 3
nop 4
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