Completed
Pull Request — master (#169)
by Mikołaj
05:25
created

ImporterSectionsResolver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 24
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A resolve() 0 13 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\Resolver;
14
15
use BitBag\SyliusCmsPlugin\Assigner\SectionsAssignerInterface;
16
use BitBag\SyliusCmsPlugin\Entity\SectionableInterface;
17
18
final class ImporterSectionsResolver implements ImporterSectionsResolverInterface
19
{
20
    /** @var SectionsAssignerInterface */
21
    private $sectionsAssigner;
22
23
    public function __construct(SectionsAssignerInterface $sectionsAssigner)
24
    {
25
        $this->sectionsAssigner = $sectionsAssigner;
26
    }
27
28
    public function resolve(SectionableInterface $sectionable, ?string $sectionsRow): void
29
    {
30
        if (null === $sectionsRow) {
31
            return;
32
        }
33
34
        $sectionCodes = explode(',', $sectionsRow);
35
        $sectionCodes = array_map(function (string $element): string {
36
            return trim($element);
37
        }, $sectionCodes);
38
39
        $this->sectionsAssigner->assign($sectionable, $sectionCodes);
40
    }
41
}
42