Conditions | 8 |
Paths | 54 |
Total Lines | 32 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Tests | 21 |
CRAP Score | 8 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
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 | } |
||
49 |