Completed
Push — master ( 68f942...d69058 )
by Rafał
18:18
created

OrganizationFactory::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * This file is part of the Superdesk Web Publisher MultiTenancy Bundle.
5
 *
6
 * Copyright 2016 Sourcefabric z.ú. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2016 Sourcefabric z.ú.
12
 * @license http://www.superdesk.org/license
13
 */
14
namespace SWP\Bundle\MultiTenancyBundle\Factory;
15
16
use Doctrine\Common\Persistence\ObjectManager;
17
use Doctrine\ODM\PHPCR\HierarchyInterface;
18
use SWP\Component\MultiTenancy\Factory\OrganizationFactoryInterface;
19
20
class OrganizationFactory implements OrganizationFactoryInterface
21
{
22
    /**
23
     * @var OrganizationFactoryInterface
24
     */
25
    protected $decoratedFactory;
26
27
    /**
28
     * @var ObjectManager
29
     */
30
    protected $documentManager;
31
32
    /**
33
     * @var string|null
34
     */
35
    protected $rootPath;
36
37
    /**
38
     * OrganizationFactory constructor.
39
     *
40
     * @param OrganizationFactoryInterface $decoratedFactory
41
     * @param ObjectManager                $documentManager
42
     * @param null                         $rootPath
43
     */
44
    public function __construct(
45
        OrganizationFactoryInterface $decoratedFactory,
46
        ObjectManager $documentManager,
47
        $rootPath = null
48
    ) {
49
        $this->decoratedFactory = $decoratedFactory;
50
        $this->documentManager = $documentManager;
51
        $this->rootPath = $rootPath;
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function create()
58
    {
59
        return $this->decoratedFactory->create();
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function createWithCode()
66
    {
67
        $organization = $this->decoratedFactory->createWithCode();
68
69
        if ($organization instanceof HierarchyInterface) {
70
            $organization->setParentDocument($this->documentManager->find(null, $this->rootPath));
71
        }
72
73
        return $organization;
74
    }
75
}
76