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

ImporterChannelsResolver   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\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