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

ImporterProductsResolver::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\ProductsAssignerInterface;
16
use BitBag\SyliusCmsPlugin\Entity\ProductsAwareInterface;
17
18
final class ImporterProductsResolver implements ImporterProductsResolverInterface
19
{
20
    /** @var ProductsAssignerInterface */
21
    private $productsAssigner;
22
23
    public function __construct(ProductsAssignerInterface $productsAssigner)
24
    {
25
        $this->productsAssigner = $productsAssigner;
26
    }
27
28
    public function resolve(ProductsAwareInterface $productsAware, ?string $productsRow): void
29
    {
30
        if (null === $productsRow) {
31
            return;
32
        }
33
34
        $productsCodes = explode(',', $productsRow);
35
        $productsCodes = array_map(function (string $element): string {
36
            return trim($element);
37
        }, $productsCodes);
38
39
        $this->productsAssigner->assign($productsAware, $productsCodes);
40
    }
41
}
42