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

ProductExampleFactoryTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 7
c 1
b 0
f 0
dl 0
loc 15
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A setRandomBarcodesToVariants() 0 13 3
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