Passed
Pull Request — master (#360)
by Mateusz
08:07
created

SectionsSorter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 10
c 2
b 0
f 0
dl 0
loc 20
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A sortBySections() 0 18 4
1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * another great project.
7
 * You can find more information about us on https://bitbag.io and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\SyliusCmsPlugin\Sorter;
14
15
use BitBag\SyliusCmsPlugin\Entity\PageInterface;
16
17
final class SectionsSorter implements SectionsSorterInterface
18
{
19
    public function sortBySections(array $pages): array
20
    {
21
        $result = [];
22
23
        /** @var PageInterface $page */
24
        foreach ($pages as $page) {
25
            foreach ($page->getSections() as $section) {
26
                $sectionCode = $section->getCode();
27
                if (!array_key_exists($sectionCode, $result)) {
28
                    $result[$sectionCode] = [];
29
                    $result[$sectionCode]['section'] = $section;
30
                }
31
32
                $result[$sectionCode][] = $page;
33
            }
34
        }
35
36
        return $result;
37
    }
38
}
39