Completed
Push — siteaccessaware-layer-only ( 14ffb6 )
by André
15:43
created

ContentService::loadVersions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * ContentService class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Publish\Core\Repository\SiteAccessAware;
10
11
use eZ\Publish\API\Repository\ContentService as ContentServiceInterface;
12
use eZ\Publish\API\Repository\Values\Content\ContentCreateStruct;
13
use eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct;
14
use eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct;
15
use eZ\Publish\API\Repository\Values\Content\LocationCreateStruct;
16
use eZ\Publish\API\Repository\Values\Content\TranslationInfo;
17
use eZ\Publish\API\Repository\Values\Content\TranslationValues;
18
use eZ\Publish\API\Repository\Values\ContentType\ContentType;
19
use eZ\Publish\API\Repository\Values\User\User;
20
use eZ\Publish\API\Repository\Values\Content\VersionInfo as APIVersionInfo;
21
use eZ\Publish\API\Repository\Values\Content\ContentInfo as APIContentInfo;
22
use eZ\Publish\Core\Repository\Helper\LanguageResolver;
23
24
/**
25
 * SiteAccess aware implementation of ContentService injecting languages where needed.
26
 */
27
class ContentService implements ContentServiceInterface
28
{
29
    /**
30
     * Aggregated service.
31
     *
32
     * @var \eZ\Publish\API\Repository\ContentService
33
     */
34
    protected $service;
35
36
    /**
37
     * Language resolver
38
     *
39
     * @var LanguageResolver
40
     */
41
    protected $languageResolver;
42
43
    /**
44
     * Construct service object from aggregated service and LanguageResolver.
45
     *
46
     * @param \eZ\Publish\API\Repository\ContentService $service
47
     * @param LanguageResolver $languageResolver
48
     */
49
    public function __construct(
50
        ContentServiceInterface $service,
51
        LanguageResolver $languageResolver
52
    ) {
53
        $this->service = $service;
54
        $this->languageResolver = $languageResolver;
55
    }
56
57
    public function loadContentInfo($contentId)
58
    {
59
        return $this->service->loadContentInfo($contentId);
60
    }
61
62
    function loadContentInfoByRemoteId($remoteId)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
63
    {
64
        return $this->service->loadContentInfoByRemoteId($remoteId);
65
    }
66
67
    public function loadVersionInfo(APIContentInfo $contentInfo, $versionNo = null)
68
    {
69
        return $this->service->loadVersionInfo($contentInfo, $versionNo);
70
    }
71
72
    public function loadVersionInfoById($contentId, $versionNo = null)
73
    {
74
        return $this->service->loadVersionInfoById($contentId, $versionNo);
75
    }
76
77 View Code Duplication
    public function loadContentByContentInfo(APIContentInfo $contentInfo, array $languages = null, $versionNo = null, $useAlwaysAvailable = true)
78
    {
79
        $languages = $this->languageResolver->getLanguages($languages);
0 ignored issues
show
Bug introduced by
It seems like $languages can also be of type null; however, eZ\Publish\Core\Reposito...esolver::getLanguages() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
80
81
        return $this->service->loadContentByContentInfo(
82
            $contentInfo,
83
            $languages,
84
            $versionNo,
85
            $useAlwaysAvailable
86
        );
87
    }
88
89
    public function loadContentByVersionInfo(APIVersionInfo $versionInfo, array $languages = null, $useAlwaysAvailable = true)
90
    {
91
        $languages = $this->languageResolver->getLanguages($languages);
0 ignored issues
show
Bug introduced by
It seems like $languages can also be of type null; however, eZ\Publish\Core\Reposito...esolver::getLanguages() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
92
93
        return $this->service->loadContentByVersionInfo($versionInfo, $languages, $useAlwaysAvailable);
94
    }
95
96
    public function loadContent($contentId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true)
97
    {
98
        $languages = $this->languageResolver->getLanguages($languages);
0 ignored issues
show
Bug introduced by
It seems like $languages can also be of type null; however, eZ\Publish\Core\Reposito...esolver::getLanguages() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
99
100
        return $this->service->loadContent(
101
            $contentId,
102
            $languages,
103
            $versionNo,
104
            $useAlwaysAvailable
105
        );
106
    }
107
108
    public function loadContentByRemoteId($remoteId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true)
109
    {
110
        $languages = $this->languageResolver->getLanguages($languages);
0 ignored issues
show
Bug introduced by
It seems like $languages can also be of type null; however, eZ\Publish\Core\Reposito...esolver::getLanguages() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
111
112
        return $this->service->loadContentByRemoteId(
113
            $remoteId,
114
            $languages,
115
            $versionNo,
116
            $useAlwaysAvailable
117
        );
118
    }
119
120
    public function createContent(ContentCreateStruct $contentCreateStruct, array $locationCreateStructs = array())
121
    {
122
        return $this->service->createContent($contentCreateStruct, $locationCreateStructs);
123
    }
124
125
    public function updateContentMetadata(APIContentInfo $contentInfo, ContentMetadataUpdateStruct $contentMetadataUpdateStruct)
126
    {
127
        return $this->service->updateContentMetadata($contentInfo, $contentMetadataUpdateStruct);
128
    }
129
130
    public function deleteContent(APIContentInfo $contentInfo)
131
    {
132
        return $this->service->deleteContent($contentInfo);
133
    }
134
135
    public function createContentDraft(APIContentInfo $contentInfo, APIVersionInfo $versionInfo = null, User $user = null)
136
    {
137
        return $this->service->createContentDraft($contentInfo, $versionInfo, $user);
138
    }
139
140
    public function loadContentDrafts(User $user = null)
141
    {
142
        return $this->service->loadContentDrafts($user);
143
    }
144
145
    public function translateVersion(TranslationInfo $translationInfo, TranslationValues $translationValues, User $user = null)
146
    {
147
        return $this->service->translateVersion($translationInfo, $translationValues, $user);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...ice::translateVersion() has been deprecated with message: Never implemented, and might be redesigned if it ever is.

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...
148
    }
149
150
    public function updateContent(APIVersionInfo $versionInfo, ContentUpdateStruct $contentUpdateStruct)
151
    {
152
        return $this->service->updateContent($versionInfo, $contentUpdateStruct);
153
    }
154
155
    public function publishVersion(APIVersionInfo $versionInfo)
156
    {
157
        return $this->service->publishVersion($versionInfo);
158
    }
159
160
    public function deleteVersion(APIVersionInfo $versionInfo)
161
    {
162
        return $this->service->deleteVersion($versionInfo);
163
    }
164
165
    public function loadVersions(APIContentInfo $contentInfo)
166
    {
167
        return $this->service->loadVersions($contentInfo);
168
    }
169
170
    public function copyContent(APIContentInfo $contentInfo, LocationCreateStruct $destinationLocationCreateStruct, APIVersionInfo $versionInfo = null)
171
    {
172
        return $this->service->copyContent($contentInfo, $destinationLocationCreateStruct, $versionInfo);
173
    }
174
175
    public function loadRelations(APIVersionInfo $versionInfo)
176
    {
177
        return $this->service->loadRelations($versionInfo);
178
    }
179
180
    public function loadReverseRelations(APIContentInfo $contentInfo)
181
    {
182
        return $this->service->loadReverseRelations($contentInfo);
183
    }
184
185
    public function addRelation(APIVersionInfo $sourceVersion, APIContentInfo $destinationContent)
186
    {
187
        return $this->service->addRelation($sourceVersion, $destinationContent);
188
    }
189
190
    public function deleteRelation(APIVersionInfo $sourceVersion, APIContentInfo $destinationContent)
191
    {
192
        return $this->service->deleteRelation($sourceVersion, $destinationContent);
193
    }
194
195
    public function addTranslationInfo(TranslationInfo $translationInfo)
196
    {
197
        return $this->service->addTranslationInfo($translationInfo);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...e::addTranslationInfo() has been deprecated with message: Never implemented, and might be redesigned if it ever is.

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...
198
    }
199
200
    public function loadTranslationInfos(APIContentInfo $contentInfo, array $filter = array())
201
    {
202
        return $this->service->loadTranslationInfos($contentInfo, $filter);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...:loadTranslationInfos() has been deprecated with message: Never implemented, and might be redesigned if it ever is.

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...
203
    }
204
205
    public function removeTranslation(APIContentInfo $contentInfo, $languageCode)
206
    {
207
        return $this->service->removeTranslation($contentInfo, $languageCode);
208
    }
209
210
    public function newContentCreateStruct(ContentType $contentType, $mainLanguageCode)
211
    {
212
        return $this->service->newContentCreateStruct($contentType, $mainLanguageCode);
213
    }
214
215
    public function newContentMetadataUpdateStruct()
216
    {
217
        return $this->service->newContentMetadataUpdateStruct();
218
    }
219
220
    public function newContentUpdateStruct()
221
    {
222
        return $this->service->newContentUpdateStruct();
223
    }
224
225
    public function newTranslationInfo()
226
    {
227
        return $this->service->newTranslationInfo();
228
    }
229
230
    public function newTranslationValues()
231
    {
232
        return $this->service->newTranslationValues();
233
    }
234
}
235