Passed
Push — master ( 1825c7...bd792e )
by
unknown
13:44 queued 15s
created

Vstack::vstack()   B

Complexity

Conditions 7
Paths 21

Size

Total Lines 27
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 7

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 27
ccs 16
cts 16
cp 1
rs 8.8333
cc 7
nc 21
nop 1
crap 7
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
4
5
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
6
7
class Vstack
8
{
9
    /**
10
     * Excel function VSTACK.
11
     *
12
     * @return mixed[]
13
     */
14 3
    public static function vstack(mixed ...$inputData): array|string
15
    {
16 3
        $returnMatrix = [];
17
18 3
        $columns = 0;
19 3
        foreach ($inputData as $matrix) {
20 3
            if (!is_array($matrix)) {
21 1
                $count = 1;
22
            } else {
23 3
                $count = count(reset($matrix)); //* @phpstan-ignore-line
24
            }
25 3
            $columns = max($columns, $count);
26
        }
27
28 3
        foreach ($inputData as $matrix) {
29 3
            if (!is_array($matrix)) {
30 1
                $matrix = [$matrix];
31
            }
32 3
            foreach ($matrix as $row) {
33 3
                if (!is_array($row)) {
34 1
                    $row = [$row];
35
                }
36 3
                $returnMatrix[] = array_values(array_pad($row, $columns, ExcelError::NA()));
37
            }
38
        }
39
40 3
        return $returnMatrix;
41
    }
42
}
43