Completed
Pull Request — master (#18)
by Kamil
02:30
created

CustomBlockFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 1
cbo 3
dl 0
loc 41
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A createNew() 0 8 1
1
<?php
2
3
namespace Lakion\SyliusCmsBundle\Factory;
4
5
use Doctrine\Common\Persistence\ObjectManager;
6
use Lakion\SyliusCmsBundle\Document\CustomBlock;
7
use Sylius\Component\Resource\Factory\FactoryInterface;
8
9
final class CustomBlockFactory implements FactoryInterface
10
{
11
    /**
12
     * @var FactoryInterface
13
     */
14
    private $decoratedFactory;
15
16
    /**
17
     * @var ObjectManager
18
     */
19
    private $documentManager;
20
21
    /**
22
     * @var string
23
     */
24
    private $customBlockParentPath;
25
26
    /**
27
     * @param FactoryInterface $decoratedFactory
28
     * @param ObjectManager $documentManager
29
     * @param string $customBlockParentPath
30
     */
31
    public function __construct(FactoryInterface $decoratedFactory, ObjectManager $documentManager, $customBlockParentPath)
32
    {
33
        $this->decoratedFactory = $decoratedFactory;
34
        $this->documentManager = $documentManager;
35
        $this->customBlockParentPath = $customBlockParentPath;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function createNew()
42
    {
43
        /** @var CustomBlock $customBlock */
44
        $customBlock = $this->decoratedFactory->createNew();
45
        $customBlock->setParentDocument($this->documentManager->find(null, $this->customBlockParentPath));
46
47
        return $customBlock;
48
    }
49
}
50