ProductsAssigner::assign()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 11
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Loevgaard\SyliusBrandPlugin\Assigner;
6
7
use Loevgaard\SyliusBrandPlugin\Model\BrandInterface;
8
use Loevgaard\SyliusBrandPlugin\Model\ProductInterface;
9
10
final class ProductsAssigner implements ProductsAssignerInterface
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15
    public function assign(BrandInterface $brand, array $products): void
16
    {
17
        foreach ($products as $product) {
18
            if (!$product instanceof ProductInterface) {
19
                throw new \RuntimeException(sprintf(
20
                    "Some product was not found to assign to brand '%s'",
21
                    $brand->getCode()
22
                ));
23
            }
24
25
            $brand->addProduct($product);
26
        }
27
    }
28
}
29