Passed
Push — master ( 5ee4fb...115e39 )
by Mark
08:05
created

LookupRefValidations::validatePositiveInt()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 4
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 4
rs 10
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
4
5
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
6
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
7
8
class LookupRefValidations
9
{
10
    /**
11
     * @param mixed $value
12
     */
13 20
    public static function validateInt($value): int
14
    {
15 20
        if (!is_numeric($value)) {
16 4
            if (Functions::isError($value)) {
17 2
                throw new Exception($value);
18
            }
19
20 2
            throw new Exception(Functions::VALUE());
21
        }
22
23 18
        return (int) floor((float) $value);
24
    }
25
26
    /**
27
     * @param mixed $value
28
     */
29 20
    public static function validatePositiveInt($value, bool $allowZero = true): int
30
    {
31 20
        $value = self::validateInt($value);
32
33 18
        if (($allowZero === false && $value <= 0) || $value < 0) {
34 2
            throw new Exception(Functions::VALUE());
35
        }
36
37 17
        return $value;
38
    }
39
}
40