Completed
Push — master ( dad5ed...687e58 )
by Igor
15s queued 13s
created

setRandomBarcodesToVariants()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 13
rs 10
cc 3
nc 4
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Loevgaard\SyliusBarcodePlugin\Fixture\Factory;
6
7
use Loevgaard\SyliusBarcodePlugin\Model\ProductVariantInterface as LoevgaardBarcodeProductVariantInterface;
8
use Sylius\Component\Core\Model\ProductInterface;
9
use Sylius\Component\Core\Model\ProductVariantInterface;
10
use Webmozart\Assert\Assert;
11
12
trait ProductExampleFactoryTrait
13
{
14
    protected function setRandomBarcodesToVariants(ProductInterface $product): void
15
    {
16
        static $faker;
17
18
        if (null === $faker) {
19
            $faker = \Faker\Factory::create();
20
        }
21
22
        /** @var ProductVariantInterface|LoevgaardBarcodeProductVariantInterface $variant */
23
        foreach ($product->getVariants() as $variant) {
24
            Assert::isInstanceOf($variant, LoevgaardBarcodeProductVariantInterface::class);
25
26
            $variant->setBarcode($faker->ean13);
27
        }
28
    }
29
}
30