Failed Conditions
Pull Request — master (#4214)
by Owen
13:09
created

Trunc::evaluate()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 3
nc 2
nop 2
crap 3
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
4
5
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
6
7
class Trunc
8
{
9
    use ArrayEnabled;
10
11
    /**
12
     * TRUNC.
13
     *
14
     * Truncates value to the number of fractional digits by number_digits.
15
     * This will probably not be the precise result in the unlikely
16
     * event that the number of digits to the left of the decimal
17
     * plus the number of digits to the right exceeds PHP_FLOAT_DIG
18
     * (or possibly that value minus 1).
19
     * Excel is unlikely to do any better.
20
     *
21
     * @param null|array|float|string $value Or can be an array of values
22
     * @param array|float|int|string $digits Or can be an array of values
23
     *
24
     * @return array|float|string Truncated value, or a string containing an error
25
     *         If an array of numbers is passed as an argument, then the returned result will also be an array
26
     *            with the same dimensions
27
     */
28
    public static function evaluate(array|float|string|null $value = 0, array|float|int|string $digits = 0): array|float|string
29 57
    {
30
        if (is_array($value) || is_array($digits)) {
31 57
            return self::evaluateArrayArguments([self::class, __FUNCTION__], $value, $digits);
32 12
        }
33
34
        return Round::down($value, $digits);
35
    }
36
}
37