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

Vstack   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 17
c 1
b 0
f 0
dl 0
loc 34
ccs 16
cts 16
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B vstack() 0 27 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