Completed
Push — ezp-30616 ( 4b2db3...187c28 )
by
unknown
17:38
created

Repository::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 39

Duplication

Lines 39
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 18
dl 39
loc 39
rs 9.296
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace eZ\Publish\Core\Event;
4
5
use eZ\Publish\API\Repository\PermissionResolver;
6
use eZ\Publish\API\Repository\Repository as RepositoryInterface;
7
use eZ\Publish\API\Repository\Values\User\User;
8
use eZ\Publish\API\Repository\Values\User\UserReference;
9
use eZ\Publish\API\Repository\Values\ValueObject;
10
use eZ\Publish\API\Repository\BookmarkService as BookmarkServiceInterface;
11
use eZ\Publish\API\Repository\ContentService as ContentServiceInterface;
12
use eZ\Publish\API\Repository\ContentTypeService as ContentTypeServiceInterface;
13
use eZ\Publish\API\Repository\FieldTypeService as FieldTypeServiceInterface;
14
use eZ\Publish\API\Repository\LanguageService as LanguageServiceInterface;
15
use eZ\Publish\API\Repository\LocationService as LocationServiceInterface;
16
use eZ\Publish\API\Repository\NotificationService as NotificationServiceInterface;
17
use eZ\Publish\API\Repository\ObjectStateService as ObjectStateServiceInterface;
18
use eZ\Publish\API\Repository\RoleService as RoleServiceInterface;
19
use eZ\Publish\API\Repository\SearchService as SearchServiceInterface;
20
use eZ\Publish\API\Repository\SectionService as SectionServiceInterface;
21
use eZ\Publish\API\Repository\TrashService as TrashServiceInterface;
22
use eZ\Publish\API\Repository\URLAliasService as URLAliasServiceInterface;
23
use eZ\Publish\API\Repository\URLService as URLServiceInterface;
24
use eZ\Publish\API\Repository\URLWildcardService as URLWildcardServiceInterface;
25
use eZ\Publish\API\Repository\UserPreferenceService as UserPreferenceServiceInterface;
26
use eZ\Publish\API\Repository\UserService as UserServiceInterface;
27
28
final class Repository implements RepositoryInterface
29
{
30
    /**
31
     * @var \eZ\Publish\API\Repository\Repository
32
     */
33
    private $repository;
34
35
    /**
36
     * @var \eZ\Publish\API\Repository\BookmarkService
37
     */
38
    private $bookmarkService;
39
40
    /**
41
     * @var \eZ\Publish\API\Repository\ContentService
42
     */
43
    private $contentService;
44
45
    /**
46
     * @var \eZ\Publish\API\Repository\ContentTypeService
47
     */
48
    private $contentTypeService;
49
50
    /**
51
     * @var \eZ\Publish\API\Repository\FieldTypeService
52
     */
53
    private $fieldTypeService;
54
55
    /**
56
     * @var \eZ\Publish\API\Repository\LanguageService
57
     */
58
    private $languageService;
59
60
    /**
61
     * @var \eZ\Publish\API\Repository\LocationService
62
     */
63
    private $locationService;
64
65
    /**
66
     * @var \eZ\Publish\API\Repository\NotificationService
67
     */
68
    private $notificationService;
69
70
    /**
71
     * @var \eZ\Publish\API\Repository\ObjectStateService
72
     */
73
    private $objectStateService;
74
75
    /**
76
     * @var \eZ\Publish\API\Repository\RoleService
77
     */
78
    private $roleService;
79
80
    /**
81
     * @var \eZ\Publish\API\Repository\SearchService
82
     */
83
    private $searchService;
84
85
    /**
86
     * @var \eZ\Publish\API\Repository\SectionService
87
     */
88
    private $sectionService;
89
90
    /**
91
     * @var \eZ\Publish\API\Repository\TrashService
92
     */
93
    private $trashService;
94
95
    /**
96
     * @var \eZ\Publish\API\Repository\URLAliasService
97
     */
98
    private $urlAliasService;
99
100
    /**
101
     * @var \eZ\Publish\API\Repository\URLService
102
     */
103
    private $urlService;
104
105
    /**
106
     * @var \eZ\Publish\API\Repository\URLWildcardService
107
     */
108
    private $urlWildcardService;
109
110
    /**
111
     * @var \eZ\Publish\API\Repository\UserPreferenceService
112
     */
113
    private $userPreferenceService;
114
115
    /**
116
     * @var \eZ\Publish\API\Repository\UserService
117
     */
118
    private $userService;
119
120 View Code Duplication
    public function __construct(
121
        RepositoryInterface $repository,
122
        BookmarkServiceInterface $bookmarkService,
123
        ContentServiceInterface $contentService,
124
        ContentTypeServiceInterface $contentTypeService,
125
        FieldTypeServiceInterface $fieldTypeService,
126
        LanguageServiceInterface $languageService,
127
        LocationServiceInterface $locationService,
128
        NotificationServiceInterface $notificationService,
129
        ObjectStateServiceInterface $objectStateService,
130
        RoleServiceInterface $roleService,
131
        SearchServiceInterface $searchService,
132
        SectionServiceInterface $sectionService,
133
        TrashServiceInterface $trashService,
134
        URLAliasServiceInterface $urlAliasService,
135
        URLServiceInterface $urlService,
136
        URLWildcardServiceInterface $urlWildcardService,
137
        UserPreferenceServiceInterface $userPreferenceService,
138
        UserServiceInterface $userService
139
    ) {
140
        $this->repository = $repository;
141
        $this->bookmarkService = $bookmarkService;
142
        $this->contentService = $contentService;
143
        $this->contentTypeService = $contentTypeService;
144
        $this->fieldTypeService = $fieldTypeService;
145
        $this->languageService = $languageService;
146
        $this->locationService = $locationService;
147
        $this->notificationService = $notificationService;
148
        $this->objectStateService = $objectStateService;
149
        $this->roleService = $roleService;
150
        $this->searchService = $searchService;
151
        $this->sectionService = $sectionService;
152
        $this->trashService = $trashService;
153
        $this->urlAliasService = $urlAliasService;
154
        $this->urlService = $urlService;
155
        $this->urlWildcardService = $urlWildcardService;
156
        $this->userPreferenceService = $userPreferenceService;
157
        $this->userService = $userService;
158
    }
159
160
    public function getCurrentUser(): User
161
    {
162
        return $this->repository->getCurrentUser();
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...itory::getCurrentUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::getCurrentUserReference() instead. Get current user. Loads the full user object if not already loaded, if you only need to know user id use {@see getCurrentUserReference()}

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
163
    }
164
165
    public function getCurrentUserReference(): UserReference
166
    {
167
        return $this->repository->getCurrentUserReference();
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...tCurrentUserReference() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::getCurrentUserReference() instead. Get current user reference.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
168
    }
169
170
    public function setCurrentUser(UserReference $user): void
171
    {
172
        $this->repository->setCurrentUser($user);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...itory::setCurrentUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::setCurrentUserReference() instead. Sets the current user to the given $user.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
173
    }
174
175
    public function hasAccess($module, $function, UserReference $user = null)
176
    {
177
        return $this->repository->hasAccess($module, $function, $user);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repository\Repository::hasAccess() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::hasAccess() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
178
    }
179
180
    public function canUser($module, $function, ValueObject $object, $targets = null): bool
181
    {
182
        return $this->repository->canUser($module, $function, $object, $targets);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repository\Repository::canUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::canUser() instead. Indicates if the current user is allowed to perform an action given by the function on the given
objects. Example: canUser( 'content', 'edit', $content, $location ); This will check edit permission on content given the specific location, if skipped if will check on all locations. Example2: canUser( 'section', 'assign', $content, $section ); Check if user has access to assign $content to $section.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
183
    }
184
185
    public function sudo(callable $callback, RepositoryInterface $outerRepository = null)
186
    {
187
        return $this->repository->sudo($callback, $outerRepository);
0 ignored issues
show
Bug introduced by
It seems like $outerRepository defined by parameter $outerRepository on line 185 can also be of type object<eZ\Publish\API\Repository\Repository>; however, eZ\Publish\API\Repository\Repository::sudo() does only seem to accept null|object<self>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
188
    }
189
190
    public function beginTransaction(): void
191
    {
192
        $this->repository->beginTransaction();
193
    }
194
195
    public function commit(): void
196
    {
197
        $this->repository->commit();
198
    }
199
200
    public function rollback(): void
201
    {
202
        $this->repository->rollback();
203
    }
204
205
    public function getPermissionResolver(): PermissionResolver
206
    {
207
        return $this->repository->getPermissionResolver();
208
    }
209
210
    public function getBookmarkService(): BookmarkServiceInterface
211
    {
212
        return $this->bookmarkService;
213
    }
214
215
    public function getContentService(): ContentServiceInterface
216
    {
217
        return $this->contentService;
218
    }
219
220
    public function getContentTypeService(): ContentTypeServiceInterface
221
    {
222
        return $this->contentTypeService;
223
    }
224
225
    public function getFieldTypeService(): FieldTypeServiceInterface
226
    {
227
        return $this->fieldTypeService;
228
    }
229
230
    public function getContentLanguageService(): LanguageServiceInterface
231
    {
232
        return $this->languageService;
233
    }
234
235
    public function getLocationService(): LocationServiceInterface
236
    {
237
        return $this->locationService;
238
    }
239
240
    public function getNotificationService(): NotificationServiceInterface
241
    {
242
        return $this->notificationService;
243
    }
244
245
    public function getObjectStateService(): ObjectStateServiceInterface
246
    {
247
        return $this->objectStateService;
248
    }
249
250
    public function getRoleService(): RoleServiceInterface
251
    {
252
        return $this->roleService;
253
    }
254
255
    public function getSearchService(): SearchServiceInterface
256
    {
257
        return $this->searchService;
258
    }
259
260
    public function getSectionService(): SectionServiceInterface
261
    {
262
        return $this->sectionService;
263
    }
264
265
    public function getTrashService(): TrashServiceInterface
266
    {
267
        return $this->trashService;
268
    }
269
270
    public function getURLAliasService(): URLAliasServiceInterface
271
    {
272
        return $this->urlAliasService;
273
    }
274
275
    public function getURLService(): URLServiceInterface
276
    {
277
        return $this->urlService;
278
    }
279
280
    public function getURLWildcardService(): URLWildcardServiceInterface
281
    {
282
        return $this->urlWildcardService;
283
    }
284
285
    public function getUserPreferenceService(): UserPreferenceServiceInterface
286
    {
287
        return $this->userPreferenceService;
288
    }
289
290
    public function getUserService(): UserServiceInterface
291
    {
292
        return $this->userService;
293
    }
294
}