Passed
Push — master ( e1c3af...d33dd4 )
by Mateusz
13:19 queued 07:37
created

SectionsSorter::sortBySections()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 4
eloc 9
c 2
b 0
f 0
nc 4
nop 1
dl 0
loc 18
rs 9.9666
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