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

CustomBlockFactory::createNew()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
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