WidgetArrangement::arrange()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Firegento\DevDashboard\ViewModel;
4
5
use Magento\Backend\Block\Template;
6
use Magento\Framework\View\Element\AbstractBlock;
7
use Magento\Framework\View\Element\Block\ArgumentInterface;
8
9
class WidgetArrangement implements ArgumentInterface
10
{
11
    /**
12
     * @param AbstractBlock $block
13
     * @return AbstractBlock[][]
14
     */
15
    public function getChildrenInColumns(AbstractBlock $block): array
16
    {
17
        $children = $block->getLayout()->getChildBlocks($block->getNameInLayout());
18
        return $this->arrange($children);
19
    }
20
21
    /**
22
     * @param AbstractBlock[] $children
23
     * @return AbstractBlock[][]
24
     */
25
    public function arrange(array $children): array
26
    {
27
        $columns = $this->getColumnCount();
28
        $result = [];
29
        foreach (array_values($children) as $index => $child) {
30
            $result[$index % $columns][] = $child;
31
        }
32
        return $result;
33
    }
34
35
    private function getColumnCount(): int
36
    {
37
        return 2;
38
    }
39
}
40