Completed
Pull Request — master (#169)
by Mikołaj
02:27
created

SectionsAssigner::assign()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 3
nc 3
nop 2
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.shop and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\SyliusCmsPlugin\Assigner;
14
15
use BitBag\SyliusCmsPlugin\Entity\SectionableInterface;
16
use BitBag\SyliusCmsPlugin\Entity\SectionInterface;
17
use BitBag\SyliusCmsPlugin\Repository\SectionRepositoryInterface;
18
19
final class SectionsAssigner implements SectionsAssignerInterface
20
{
21
    /** @var SectionRepositoryInterface */
22
    private $sectionRepository;
23
24
    public function __construct(SectionRepositoryInterface $sectionRepository)
25
    {
26
        $this->sectionRepository = $sectionRepository;
27
    }
28
29
    public function assign(SectionableInterface $sectionsAware, array $sectionsCodes): void
30
    {
31
        foreach ($sectionsCodes as $sectionCode) {
32
            /** @var SectionInterface $section */
33
            $section = $this->sectionRepository->findOneBy(['code' => $sectionCode]);
34
35
            if (null !== $section) {
36
                $sectionsAware->addSection($section);
37
            }
38
        }
39
    }
40
}
41