WidgetArrangement   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 9
dl 0
loc 29
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getColumnCount() 0 3 1
A getChildrenInColumns() 0 4 1
A arrange() 0 8 2
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