Passed
Pull Request — master (#4492)
by Owen
13:35
created

Vstack   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 17
c 1
b 0
f 0
dl 0
loc 34
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
    public static function vstack(mixed ...$inputData): array|string
15
    {
16
        $returnMatrix = [];
17
18
        $columns = 0;
19
        foreach ($inputData as $matrix) {
20
            if (!is_array($matrix)) {
21
                $count = 1;
22
            } else {
23
                $count = count(reset($matrix)); //* @phpstan-ignore-line
24
            }
25
            $columns = max($columns, $count);
26
        }
27
28
        foreach ($inputData as $matrix) {
29
            if (!is_array($matrix)) {
30
                $matrix = [$matrix];
31
            }
32
            foreach ($matrix as $row) {
33
                if (!is_array($row)) {
34
                    $row = [$row];
35
                }
36
                $returnMatrix[] = array_values(array_pad($row, $columns, ExcelError::NA()));
37
            }
38
        }
39
40
        return $returnMatrix;
41
    }
42
}
43