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

Hstack   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 22
c 1
b 0
f 0
dl 0
loc 39
ccs 21
cts 21
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B hstack() 0 32 8
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
4
5
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
6
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
7
8
class Hstack
9
{
10
    /**
11
     * Excel function HSTACK.
12
     *
13
     * @return mixed[]|string
14
     */
15 1
    public static function hstack(mixed ...$inputData): array|string
16
    {
17 1
        $maxRow = 0;
18 1
        foreach ($inputData as $matrix) {
19 1
            if (!is_array($matrix)) {
20 1
                $count = 1;
21
            } else {
22 1
                $count = count($matrix);
23
            }
24 1
            $maxRow = max($maxRow, $count);
25
        }
26
        /** @var mixed[] $inputData */
27 1
        foreach ($inputData as &$matrix) {
28 1
            if (!is_array($matrix)) {
29 1
                $matrix = [$matrix];
30
            }
31 1
            $rows = count($matrix);
32 1
            $reset = reset($matrix);
33 1
            $columns = is_array($reset) ? count($reset) : 1;
34 1
            while ($maxRow > $rows) {
35 1
                $matrix[] = array_pad([], $columns, ExcelError::NA());
36 1
                ++$rows;
37
            }
38
        }
39
40 1
        $transpose = array_map(null, ...$inputData); //* @phpstan-ignore-line
41 1
        $returnMatrix = [];
42 1
        foreach ($transpose as $array) {
43 1
            $returnMatrix[] = Functions::flattenArray($array);
44
        }
45
46 1
        return $returnMatrix;
47
    }
48
}
49