Completed
Push — master ( cf353c...bbc3bb )
by Mikołaj
11s
created

ImporterChannelsResolver::resolve()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 2
nc 2
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\Resolver;
14
15
use BitBag\SyliusCmsPlugin\Assigner\ChannelsAssignerInterface;
16
use Sylius\Component\Channel\Model\ChannelsAwareInterface;
17
18
final class ImporterChannelsResolver implements ImporterChannelsResolverInterface
19
{
20
    /** @var ChannelsAssignerInterface */
21
    private $channelsAssigner;
22
23
    public function __construct(ChannelsAssignerInterface $channelsAssigner)
24
    {
25
        $this->channelsAssigner = $channelsAssigner;
26
    }
27
28
    public function resolve(ChannelsAwareInterface $channelsAware, ?string $channelsRow): void
29
    {
30
        if (null === $channelsRow) {
31
            return;
32
        }
33
34
        $channelsCodes = explode(',', $channelsRow);
35
        $channelsCodes = array_map(function (string $element): string {
36
            return trim($element);
37
        }, $channelsCodes);
38
39
        $this->channelsAssigner->assign($channelsAware, $channelsCodes);
40
    }
41
}
42