Failed Conditions
Pull Request — master (#1)
by
unknown
01:55
created

UnsignedInt::filter()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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