ComparerProductFactory::createNew()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Locastic\SyliusComparerPlugin\Factory;
6
7
use Locastic\SyliusComparerPlugin\Entity\ComparerInterface;
8
use Locastic\SyliusComparerPlugin\Entity\ComparerProductInterface;
9
use Sylius\Component\Core\Model\ProductInterface;
10
use Sylius\Component\Resource\Factory\FactoryInterface;
11
12
class ComparerProductFactory implements ComparerProductFactoryInterface
13
{
14
    /** @var FactoryInterface */
15
    private $comparerProductFactory;
16
17
    public function __construct(FactoryInterface $comparerProductFactory)
18
    {
19
        $this->comparerProductFactory = $comparerProductFactory;
20
    }
21
22
    public function createNew(): ComparerProductInterface
23
    {
24
        /** @var ComparerProductInterface $comparerProduct */
25
        $comparerProduct = $this->comparerProductFactory->createNew();
26
27
        return $comparerProduct;
28
    }
29
30
    public function createForComparerAndProduct(ComparerInterface $comparer, ProductInterface $product): ComparerProductInterface
31
    {
32
        $comparerProduct = $this->createNew();
33
34
        $comparerProduct->setComparer($comparer);
35
        $comparerProduct->setProduct($product);
36
37
        return $comparerProduct;
38
    }
39
}
40