Completed
Push — 1.0 ( 19670d...450ed0 )
by Valentin
09:36
created

ObjectService::getUserManager()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 13
ccs 8
cts 8
cp 1
rs 9.4285
cc 3
eloc 7
nc 3
nop 0
crap 3
1
<?php
2
3
/*
4
 * This file is part of Transfer.
5
 *
6
 * For the full copyright and license information, please view the LICENSE file located
7
 * in the root directory.
8
 */
9
10
namespace Transfer\EzPlatform\Repository;
11
12
use Transfer\EzPlatform\Repository\Manager\ContentManager;
13
use Transfer\EzPlatform\Repository\Manager\ContentTypeManager;
14
use Transfer\EzPlatform\Repository\Manager\LanguageManager;
15
use Transfer\EzPlatform\Repository\Manager\LocationManager;
16
use Transfer\EzPlatform\Repository\Manager\UserGroupManager;
17
use Transfer\EzPlatform\Repository\Manager\UserManager;
18
19
/**
20
 * Object service.
21
 */
22
class ObjectService extends AbstractRepositoryService
23
{
24
    /**
25
     * @var ContentManager Content manager.
26
     */
27
    private $contentManager;
28
29
    /**
30
     * @var LocationManager Location manager.
31
     */
32
    private $locationManager;
33
34
    /**
35
     * @var ContentTypeManager
36
     */
37
    private $contentTypeManager;
38
39
    /**
40
     * @var LanguageManager
41
     */
42
    private $languageManager;
43
44
    /**
45
     * @var UserGroupManager
46
     */
47
    private $userGroupManager;
48
49
    /**
50
     * @var UserManager
51
     */
52
    private $userManager;
53
54
    /**
55
     * Returns content manager.
56
     *
57
     * @return Manager\ContentManager
58
     */
59 4 View Code Duplication
    public function getContentManager()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
60
    {
61 4
        if ($this->contentManager != null) {
62 2
            return $this->contentManager;
63
        }
64
65 4
        $this->contentManager = new Manager\ContentManager($this->repository);
66
67 4
        if ($this->logger) {
68 1
            $this->contentManager->setLogger($this->logger);
69 1
        }
70
71 4
        return $this->contentManager;
72
    }
73
74
    /**
75
     * Returns location manager.
76
     *
77
     * @return Manager\LocationManager
78
     */
79 2 View Code Duplication
    public function getLocationManager()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
80
    {
81 2
        if ($this->locationManager != null) {
82 1
            return $this->locationManager;
83
        }
84
85 2
        $this->locationManager = new Manager\LocationManager($this->repository);
86 2
        if ($this->logger) {
87 1
            $this->locationManager->setLogger($this->logger);
88 1
        }
89
90 2
        return $this->locationManager;
91
    }
92
93
    /**
94
     * Returns contenttype manager.
95
     *
96
     * @return ContentTypeManager
97
     */
98 3
    public function getContentTypeManager()
99
    {
100 3
        if ($this->contentTypeManager != null) {
101 1
            return $this->contentTypeManager;
102
        }
103
104 3
        $this->contentTypeManager = new Manager\ContentTypeManager($this->repository, $this->getLanguageManager());
105 3
        if ($this->logger) {
106 2
            $this->contentTypeManager->setLogger($this->logger);
107 2
        }
108
109 3
        return $this->contentTypeManager;
110
    }
111
112
    /**
113
     * Returns language manager.
114
     *
115
     * @return LanguageManager
116
     */
117 3 View Code Duplication
    public function getLanguageManager()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
118
    {
119 3
        if ($this->languageManager != null) {
120 1
            return $this->languageManager;
121
        }
122
123 3
        $this->languageManager = new Manager\LanguageManager($this->repository);
124 3
        if ($this->logger) {
125 2
            $this->languageManager->setLogger($this->logger);
126 2
        }
127
128 3
        return $this->languageManager;
129
    }
130
131
    /**
132
     * Returns user group manager.
133
     *
134
     * @return UserGroupManager
135
     */
136 3 View Code Duplication
    public function getUserGroupManager()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
137
    {
138 3
        if ($this->userGroupManager != null) {
139 1
            return $this->userGroupManager;
140
        }
141
142 3
        $this->userGroupManager = new Manager\UserGroupManager($this->repository);
143 3
        if ($this->logger) {
144 3
            $this->userGroupManager->setLogger($this->logger);
145 3
        }
146
147 3
        return $this->userGroupManager;
148
    }
149
150
    /**
151
     * Returns user manager.
152
     *
153
     * @return UserManager
154
     */
155 2
    public function getUserManager()
156
    {
157 2
        if ($this->userManager != null) {
158 1
            return $this->userManager;
159
        }
160
161 2
        $this->userManager = new Manager\UserManager($this->repository, $this->getUserGroupManager());
162 2
        if ($this->logger) {
163 2
            $this->userManager->setLogger($this->logger);
164 2
        }
165
166 2
        return $this->userManager;
167
    }
168
169
    /**
170
     * {@inheritdoc}
171
     */
172 8
    public function create($object)
173
    {
174
        $map = array(
175 8
            'Transfer\EzPlatform\Data\ContentObject' => array($this, 'getContentManager'),
176 8
            'Transfer\EzPlatform\Data\ContentTypeObject' => array($this, 'getContentTypeManager'),
177 8
            'Transfer\EzPlatform\Data\LanguageObject' => array($this, 'getLanguageManager'),
178 8
            'Transfer\EzPlatform\Data\UserObject' => array($this, 'getUserManager'),
179 8
            'Transfer\EzPlatform\Data\UserGroupObject' => array($this, 'getUserGroupManager'),
180 8
        );
181
182 8
        foreach ($map as $class => $callable) {
183 8
            if ($object instanceof $class) {
184 7
                $manager = call_user_func($callable);
185
186 7
                return $manager->createOrUpdate($object);
187
            }
188 5
        }
189
190 1
        throw new \InvalidArgumentException('Object is not supported for creation.');
191
    }
192
}
193