This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | namespace Dkd\PhpCmis\Converter; |
||
3 | |||
4 | /* |
||
5 | * This file is part of php-cmis-client. |
||
6 | * |
||
7 | * (c) Sascha Egerer <[email protected]> |
||
8 | * |
||
9 | * For the full copyright and license information, please view the LICENSE |
||
10 | * file that was distributed with this source code. |
||
11 | */ |
||
12 | |||
13 | use Dkd\Enumeration\Exception\InvalidEnumerationValueException; |
||
14 | use Dkd\PhpCmis\Bindings\Browser\JSONConstants; |
||
15 | use Dkd\PhpCmis\Converter\Types\TypeConverterInterface; |
||
16 | use Dkd\PhpCmis\Data\AclCapabilitiesInterface; |
||
17 | use Dkd\PhpCmis\Data\AclInterface; |
||
18 | use Dkd\PhpCmis\Data\AllowableActionsInterface; |
||
19 | use Dkd\PhpCmis\Data\ExtensionFeatureInterface; |
||
20 | use Dkd\PhpCmis\Data\ObjectDataInterface; |
||
21 | use Dkd\PhpCmis\Data\ObjectInFolderContainerInterface; |
||
22 | use Dkd\PhpCmis\Data\ObjectInFolderDataInterface; |
||
23 | use Dkd\PhpCmis\Data\ObjectInFolderListInterface; |
||
24 | use Dkd\PhpCmis\Data\ObjectListInterface; |
||
25 | use Dkd\PhpCmis\Data\ObjectParentDataInterface; |
||
26 | use Dkd\PhpCmis\Data\PropertiesInterface; |
||
27 | use Dkd\PhpCmis\Data\PropertyDataInterface; |
||
28 | use Dkd\PhpCmis\Data\RenditionDataInterface; |
||
29 | use Dkd\PhpCmis\Data\RepositoryCapabilitiesInterface; |
||
30 | use Dkd\PhpCmis\Data\RepositoryInfoInterface; |
||
31 | use Dkd\PhpCmis\DataObjects\AbstractTypeDefinition; |
||
32 | use Dkd\PhpCmis\DataObjects\AccessControlEntry; |
||
33 | use Dkd\PhpCmis\DataObjects\AccessControlList; |
||
34 | use Dkd\PhpCmis\DataObjects\AclCapabilities; |
||
35 | use Dkd\PhpCmis\DataObjects\AllowableActions; |
||
36 | use Dkd\PhpCmis\DataObjects\BindingsObjectFactory; |
||
37 | use Dkd\PhpCmis\DataObjects\ChangeEventInfo; |
||
38 | use Dkd\PhpCmis\DataObjects\CmisExtensionElement; |
||
39 | use Dkd\PhpCmis\DataObjects\CreatablePropertyTypes; |
||
40 | use Dkd\PhpCmis\DataObjects\ExtensionFeature; |
||
41 | use Dkd\PhpCmis\DataObjects\FailedToDeleteData; |
||
42 | use Dkd\PhpCmis\DataObjects\NewTypeSettableAttributes; |
||
43 | use Dkd\PhpCmis\DataObjects\ObjectData; |
||
44 | use Dkd\PhpCmis\DataObjects\ObjectInFolderContainer; |
||
45 | use Dkd\PhpCmis\DataObjects\ObjectInFolderData; |
||
46 | use Dkd\PhpCmis\DataObjects\ObjectInFolderList; |
||
47 | use Dkd\PhpCmis\DataObjects\ObjectList; |
||
48 | use Dkd\PhpCmis\DataObjects\ObjectParentData; |
||
49 | use Dkd\PhpCmis\DataObjects\PermissionDefinition; |
||
50 | use Dkd\PhpCmis\DataObjects\PermissionMapping; |
||
51 | use Dkd\PhpCmis\DataObjects\PolicyIdList; |
||
52 | use Dkd\PhpCmis\DataObjects\Principal; |
||
53 | use Dkd\PhpCmis\DataObjects\Properties; |
||
54 | use Dkd\PhpCmis\DataObjects\PropertyBoolean; |
||
55 | use Dkd\PhpCmis\DataObjects\PropertyBooleanDefinition; |
||
56 | use Dkd\PhpCmis\DataObjects\PropertyDateTime; |
||
57 | use Dkd\PhpCmis\DataObjects\PropertyDateTimeDefinition; |
||
58 | use Dkd\PhpCmis\DataObjects\PropertyDecimal; |
||
59 | use Dkd\PhpCmis\DataObjects\PropertyDecimalDefinition; |
||
60 | use Dkd\PhpCmis\DataObjects\PropertyHtml; |
||
61 | use Dkd\PhpCmis\DataObjects\PropertyHtmlDefinition; |
||
62 | use Dkd\PhpCmis\DataObjects\PropertyId; |
||
63 | use Dkd\PhpCmis\DataObjects\PropertyIdDefinition; |
||
64 | use Dkd\PhpCmis\DataObjects\PropertyInteger; |
||
65 | use Dkd\PhpCmis\DataObjects\PropertyIntegerDefinition; |
||
66 | use Dkd\PhpCmis\DataObjects\PropertyString; |
||
67 | use Dkd\PhpCmis\DataObjects\PropertyStringDefinition; |
||
68 | use Dkd\PhpCmis\DataObjects\PropertyUri; |
||
69 | use Dkd\PhpCmis\DataObjects\PropertyUriDefinition; |
||
70 | use Dkd\PhpCmis\DataObjects\RenditionData; |
||
71 | use Dkd\PhpCmis\DataObjects\RepositoryCapabilities; |
||
72 | use Dkd\PhpCmis\DataObjects\RepositoryInfoBrowserBinding; |
||
73 | use Dkd\PhpCmis\DataObjects\TypeDefinitionContainer; |
||
74 | use Dkd\PhpCmis\DataObjects\TypeDefinitionList; |
||
75 | use Dkd\PhpCmis\DataObjects\TypeMutability; |
||
76 | use Dkd\PhpCmis\Definitions\MutableDocumentTypeDefinitionInterface; |
||
77 | use Dkd\PhpCmis\Definitions\MutableRelationshipTypeDefinitionInterface; |
||
78 | use Dkd\PhpCmis\Definitions\MutableTypeDefinitionInterface; |
||
79 | use Dkd\PhpCmis\Definitions\PropertyDefinitionInterface; |
||
80 | use Dkd\PhpCmis\Definitions\RelationshipTypeDefinitionInterface; |
||
81 | use Dkd\PhpCmis\Definitions\TypeDefinitionContainerInterface; |
||
82 | use Dkd\PhpCmis\Definitions\TypeDefinitionInterface; |
||
83 | use Dkd\PhpCmis\Definitions\TypeDefinitionListInterface; |
||
84 | use Dkd\PhpCmis\Enum\AclPropagation; |
||
85 | use Dkd\PhpCmis\Enum\Action; |
||
86 | use Dkd\PhpCmis\Enum\BaseTypeId; |
||
87 | use Dkd\PhpCmis\Enum\CapabilityAcl; |
||
88 | use Dkd\PhpCmis\Enum\CapabilityChanges; |
||
89 | use Dkd\PhpCmis\Enum\CapabilityContentStreamUpdates; |
||
90 | use Dkd\PhpCmis\Enum\CapabilityJoin; |
||
91 | use Dkd\PhpCmis\Enum\CapabilityOrderBy; |
||
92 | use Dkd\PhpCmis\Enum\CapabilityQuery; |
||
93 | use Dkd\PhpCmis\Enum\CapabilityRenditions; |
||
94 | use Dkd\PhpCmis\Enum\Cardinality; |
||
95 | use Dkd\PhpCmis\Enum\ChangeType; |
||
96 | use Dkd\PhpCmis\Enum\CmisVersion; |
||
97 | use Dkd\PhpCmis\Enum\ContentStreamAllowed; |
||
98 | use Dkd\PhpCmis\Enum\DateTimeResolution; |
||
99 | use Dkd\PhpCmis\Enum\DecimalPrecision; |
||
100 | use Dkd\PhpCmis\Enum\PropertyType; |
||
101 | use Dkd\PhpCmis\Enum\SupportedPermissions; |
||
102 | use Dkd\PhpCmis\Enum\Updatability; |
||
103 | use Dkd\PhpCmis\Exception\CmisInvalidArgumentException; |
||
104 | use Dkd\PhpCmis\Exception\CmisRuntimeException; |
||
105 | use function array_diff_key; |
||
106 | use function array_filter; |
||
107 | use function array_flip; |
||
108 | use function array_map; |
||
109 | use function is_array; |
||
110 | |||
111 | /** |
||
112 | * Convert PHP CMIS Objects to JSON and JSON Responses TO PHP CMIS Objects |
||
113 | * |
||
114 | * @TODO: To reduce the complexity of this class there should be some kind of schema mapping in the future. |
||
115 | */ |
||
116 | class JsonConverter extends AbstractDataConverter |
||
117 | 2 | { |
|
118 | /** |
||
119 | 2 | * @param array|null $data |
|
120 | 1 | * @return AllowableActions|null |
|
121 | */ |
||
122 | public function convertAllowableActions(array $data = null) |
||
123 | 1 | { |
|
124 | 1 | if (empty($data)) { |
|
125 | 1 | return null; |
|
126 | } |
||
127 | 1 | ||
128 | $allowableActions = new AllowableActions(); |
||
129 | 1 | $actions = []; |
|
130 | 1 | $extensions = []; |
|
131 | 1 | ||
132 | 1 | foreach ($data as $key => $value) { |
|
133 | 1 | try { |
|
134 | if ((boolean) $value === true) { |
||
135 | 1 | $actions[] = Action::cast($key); |
|
136 | } |
||
137 | 1 | } catch (InvalidEnumerationValueException $exception) { |
|
138 | 1 | $extensions[$key] = $value; |
|
139 | } |
||
140 | 1 | } |
|
141 | |||
142 | $allowableActions->setAllowableActions($actions); |
||
143 | $allowableActions->setExtensions($this->convertExtension($extensions)); |
||
144 | |||
145 | return $allowableActions; |
||
146 | } |
||
147 | 2 | ||
148 | /** |
||
149 | 2 | * @param array|null $data The JSON that contains the repository info |
|
150 | 1 | * @return null|RepositoryInfoBrowserBinding |
|
151 | */ |
||
152 | public function convertRepositoryInfo(array $data = null) |
||
153 | 1 | { |
|
154 | return empty($data) ? null : $this->setRepositoryInfoValues(new RepositoryInfoBrowserBinding(), $data); |
||
155 | } |
||
156 | |||
157 | /** |
||
158 | * @param RepositoryInfoBrowserBinding $object |
||
159 | * @param array $data |
||
160 | * @return RepositoryInfoBrowserBinding |
||
161 | 1 | */ |
|
162 | protected function setRepositoryInfoValues(RepositoryInfoBrowserBinding $object, $data) |
||
163 | 1 | { |
|
164 | 1 | $data[JSONConstants::JSON_REPINFO_CAPABILITIES] = $this->convertRepositoryCapabilities( |
|
165 | 1 | $data[JSONConstants::JSON_REPINFO_CAPABILITIES] ?? null |
|
166 | 1 | ); |
|
167 | 1 | ||
168 | 1 | $data[JSONConstants::JSON_REPINFO_ACL_CAPABILITIES] = $this->convertAclCapabilities( |
|
169 | 1 | $data[JSONConstants::JSON_REPINFO_ACL_CAPABILITIES] ?? null |
|
0 ignored issues
–
show
|
|||
170 | 1 | ); |
|
171 | 1 | ||
172 | $data[JSONConstants::JSON_REPINFO_CHANGES_ON_TYPE] = array_map( |
||
173 | function ($item) { return BaseTypeId::cast($item); }, |
||
174 | 1 | array_filter( |
|
175 | $data[JSONConstants::JSON_REPINFO_CHANGES_ON_TYPE] ?? [], |
||
176 | 1 | function ($item) { return !empty($item); } |
|
177 | 1 | ) |
|
178 | 1 | ); |
|
179 | 1 | ||
180 | 1 | $data[JSONConstants::JSON_REPINFO_EXTENDED_FEATURES] = $this->convertExtensionFeatures( |
|
181 | 1 | $data[JSONConstants::JSON_REPINFO_EXTENDED_FEATURES] ?? [] |
|
0 ignored issues
–
show
It seems like
$data[\Dkd\PhpCmis\Bindi...ED_FEATURES] ?? array() can also be of type object<Dkd\PhpCmis\DataObjects\AclCapabilities> or object<Dkd\PhpCmis\DataO...RepositoryCapabilities> ; however, Dkd\PhpCmis\Converter\Js...vertExtensionFeatures() does only seem to accept null|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. ![]() |
|||
182 | 1 | ); |
|
183 | |||
184 | if (isset($data[JSONConstants::JSON_REPINFO_CMIS_VERSION_SUPPORTED])) { |
||
185 | 1 | $data[JSONConstants::JSON_REPINFO_CMIS_VERSION_SUPPORTED] = CmisVersion::cast( |
|
186 | $data[JSONConstants::JSON_REPINFO_CMIS_VERSION_SUPPORTED] |
||
187 | 1 | ); |
|
188 | 1 | } |
|
189 | 1 | ||
190 | 1 | $data = array_filter($data, function ($item) { return $item !== null; }); |
|
191 | 1 | ||
192 | 1 | $object->setExtensions($this->convertExtension($data, JSONConstants::getRepositoryInfoKeys())); |
|
193 | 1 | ||
194 | 1 | $object->populate( |
|
195 | 1 | $data, |
|
196 | array_merge( |
||
197 | 1 | array_combine(JSONConstants::getRepositoryInfoKeys(), JSONConstants::getRepositoryInfoKeys()), |
|
198 | 1 | [ |
|
199 | JSONConstants::JSON_REPINFO_DESCRIPTION => 'description', |
||
200 | 1 | JSONConstants::JSON_REPINFO_CMIS_VERSION_SUPPORTED => 'cmisVersion', |
|
201 | 1 | JSONConstants::JSON_REPINFO_ID => 'id', |
|
202 | 1 | JSONConstants::JSON_REPINFO_ROOT_FOLDER_URL => 'rootUrl', |
|
203 | 1 | JSONConstants::JSON_REPINFO_NAME => 'name', |
|
204 | 1 | JSONConstants::JSON_REPINFO_EXTENDED_FEATURES => 'extensionFeatures' |
|
205 | 1 | ] |
|
206 | 1 | ), |
|
207 | true |
||
208 | 1 | ); |
|
209 | 1 | ||
210 | 1 | return $object; |
|
211 | 1 | } |
|
212 | 1 | ||
213 | /** |
||
214 | 1 | * @param array|null $data |
|
215 | * @return RepositoryCapabilities|null |
||
216 | 1 | */ |
|
217 | 1 | public function convertRepositoryCapabilities(array $data = null) |
|
218 | 1 | { |
|
219 | 1 | if (empty($data)) { |
|
220 | return null; |
||
221 | 1 | } |
|
222 | 1 | ||
223 | 1 | if (isset($data[JSONConstants::JSON_CAP_CONTENT_STREAM_UPDATABILITY])) { |
|
224 | 1 | $data[JSONConstants::JSON_CAP_CONTENT_STREAM_UPDATABILITY] = CapabilityContentStreamUpdates::cast( |
|
225 | 1 | $data[JSONConstants::JSON_CAP_CONTENT_STREAM_UPDATABILITY] |
|
226 | 1 | ); |
|
227 | 1 | } |
|
228 | 1 | if (isset($data[JSONConstants::JSON_CAP_CHANGES])) { |
|
229 | $data[JSONConstants::JSON_CAP_CHANGES] = CapabilityChanges::cast($data[JSONConstants::JSON_CAP_CHANGES]); |
||
230 | 1 | } |
|
231 | if (isset($data[JSONConstants::JSON_CAP_RENDITIONS])) { |
||
232 | 1 | $data[JSONConstants::JSON_CAP_RENDITIONS] = CapabilityRenditions::cast( |
|
233 | $data[JSONConstants::JSON_CAP_RENDITIONS] |
||
234 | ); |
||
235 | } |
||
236 | if (isset($data[JSONConstants::JSON_CAP_ORDER_BY])) { |
||
237 | $data[JSONConstants::JSON_CAP_ORDER_BY] = CapabilityOrderBy::cast( |
||
238 | $data[JSONConstants::JSON_CAP_ORDER_BY] |
||
239 | 2 | ); |
|
240 | } |
||
241 | 2 | if (isset($data[JSONConstants::JSON_CAP_QUERY])) { |
|
242 | 1 | $data[JSONConstants::JSON_CAP_QUERY] = CapabilityQuery::cast($data[JSONConstants::JSON_CAP_QUERY]); |
|
243 | } |
||
244 | if (isset($data[JSONConstants::JSON_CAP_JOIN])) { |
||
245 | 1 | $data[JSONConstants::JSON_CAP_JOIN] = CapabilityJoin::cast($data[JSONConstants::JSON_CAP_JOIN]); |
|
246 | 1 | } |
|
247 | 1 | if (isset($data[JSONConstants::JSON_CAP_ACL])) { |
|
248 | 1 | $data[JSONConstants::JSON_CAP_ACL] = CapabilityAcl::cast($data[JSONConstants::JSON_CAP_ACL]); |
|
249 | 1 | } |
|
250 | 1 | ||
251 | 1 | if (isset($data[JSONConstants::JSON_CAP_CREATABLE_PROPERTY_TYPES])) { |
|
252 | 1 | $data[JSONConstants::JSON_CAP_CREATABLE_PROPERTY_TYPES] = $this->convertCreatablePropertyTypes( |
|
253 | 1 | $data[JSONConstants::JSON_CAP_CREATABLE_PROPERTY_TYPES] |
|
254 | 1 | ); |
|
255 | 1 | } |
|
256 | 1 | ||
257 | 1 | if (isset($data[JSONConstants::JSON_CAP_NEW_TYPE_SETTABLE_ATTRIBUTES])) { |
|
258 | 1 | $data[JSONConstants::JSON_CAP_NEW_TYPE_SETTABLE_ATTRIBUTES] = $this->convertNewTypeSettableAttributes( |
|
259 | 1 | $data[JSONConstants::JSON_CAP_NEW_TYPE_SETTABLE_ATTRIBUTES] |
|
260 | 1 | ); |
|
261 | 1 | } |
|
262 | 1 | ||
263 | 1 | $data = array_filter($data, function ($item) { return $item !== null; }); |
|
264 | 1 | ||
265 | 1 | $repositoryCapabilities = new RepositoryCapabilities(); |
|
266 | 1 | $repositoryCapabilities->setExtensions($this->convertExtension($data, JSONConstants::getCapabilityKeys())); |
|
267 | 1 | ||
268 | 1 | $repositoryCapabilities->populate( |
|
269 | 1 | $data, |
|
270 | 1 | array_merge( |
|
271 | 1 | array_combine(JSONConstants::getCapabilityKeys(), JSONConstants::getCapabilityKeys()), |
|
272 | [ |
||
273 | 1 | JSONConstants::JSON_CAP_CONTENT_STREAM_UPDATABILITY => 'contentStreamUpdatesCapability', |
|
274 | 1 | JSONConstants::JSON_CAP_CHANGES => 'changesCapability', |
|
275 | 1 | JSONConstants::JSON_CAP_RENDITIONS => 'renditionsCapability', |
|
276 | 1 | JSONConstants::JSON_CAP_GET_DESCENDANTS => 'supportsGetDescendants', |
|
277 | 1 | JSONConstants::JSON_CAP_GET_FOLDER_TREE => 'supportsGetFolderTree', |
|
278 | JSONConstants::JSON_CAP_MULTIFILING => 'supportsMultifiling', |
||
279 | JSONConstants::JSON_CAP_UNFILING => 'supportsUnfiling', |
||
280 | 1 | JSONConstants::JSON_CAP_VERSION_SPECIFIC_FILING => 'supportsVersionSpecificFiling', |
|
281 | JSONConstants::JSON_CAP_PWC_SEARCHABLE => 'supportsPwcSearchable', |
||
282 | 1 | JSONConstants::JSON_CAP_PWC_UPDATABLE => 'supportsPwcUpdatable', |
|
283 | 1 | JSONConstants::JSON_CAP_ALL_VERSIONS_SEARCHABLE => 'supportsAllVersionsSearchable', |
|
284 | 1 | JSONConstants::JSON_CAP_ORDER_BY => 'orderByCapability', |
|
285 | 1 | JSONConstants::JSON_CAP_QUERY => 'queryCapability', |
|
286 | 1 | JSONConstants::JSON_CAP_JOIN => 'joinCapability', |
|
287 | JSONConstants::JSON_CAP_ACL => 'aclCapability', |
||
288 | JSONConstants::JSON_CAP_CREATABLE_PROPERTY_TYPES => 'creatablePropertyTypes', |
||
289 | 1 | JSONConstants::JSON_CAP_NEW_TYPE_SETTABLE_ATTRIBUTES => 'newTypeSettableAttributes' |
|
290 | ] |
||
291 | 1 | ), |
|
292 | 1 | true |
|
293 | ); |
||
294 | 1 | ||
295 | 1 | return $repositoryCapabilities; |
|
296 | 1 | } |
|
297 | 1 | ||
298 | /** |
||
299 | 1 | * Create NewTypeSettableAttributes object and populate given data to it |
|
300 | 1 | * |
|
301 | 1 | * @param string[]|null $data |
|
302 | 1 | * @return NewTypeSettableAttributes|null Returns object or <code>null</code> if given data is empty |
|
303 | 1 | */ |
|
304 | 1 | View Code Duplication | public function convertNewTypeSettableAttributes(array $data = null) |
0 ignored issues
–
show
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. ![]() |
|||
305 | 1 | { |
|
306 | 1 | if (empty($data)) { |
|
307 | 1 | return null; |
|
308 | 1 | } |
|
309 | 1 | $object = new NewTypeSettableAttributes(); |
|
310 | 1 | ||
311 | 1 | $object->populate( |
|
312 | 1 | $data, |
|
313 | 1 | array_combine( |
|
314 | 1 | JSONConstants::getCapabilityNewTypeSettableAttributeKeys(), |
|
315 | 1 | array_map( |
|
316 | 1 | function ($key) { |
|
317 | 1 | // add a prefix "canSet" to all keys as this are the property names |
|
318 | return 'canSet' . ucfirst($key); |
||
319 | 1 | }, |
|
320 | JSONConstants::getCapabilityNewTypeSettableAttributeKeys() |
||
321 | 1 | ) |
|
322 | ), |
||
323 | true |
||
324 | ); |
||
325 | |||
326 | $object->setExtensions( |
||
327 | $this->convertExtension( |
||
328 | $data, |
||
329 | JSONConstants::getCapabilityNewTypeSettableAttributeKeys() |
||
330 | 1 | ) |
|
331 | ); |
||
332 | 1 | ||
333 | return $object; |
||
334 | } |
||
335 | 1 | ||
336 | /** |
||
337 | 1 | * Create CreatablePropertyTypes object and populate given data to it |
|
338 | 1 | * |
|
339 | 1 | * @param array|null $data The data that should be populated to the CreatablePropertyTypes object |
|
340 | 1 | * @return CreatablePropertyTypes|null Returns a CreatablePropertyTypes object or <code>null</code> if empty data |
|
341 | 1 | * is given. |
|
342 | */ |
||
343 | public function convertCreatablePropertyTypes(array $data = null) |
||
344 | 1 | { |
|
345 | 1 | if (empty($data)) { |
|
346 | 1 | return null; |
|
347 | 1 | } |
|
348 | 1 | ||
349 | $object = new CreatablePropertyTypes(); |
||
350 | 1 | $canCreate = []; |
|
351 | foreach ($data[JSONConstants::JSON_CAP_CREATABLE_PROPERTY_TYPES_CANCREATE] ?? [] as $canCreateItem) { |
||
352 | 1 | try { |
|
353 | 1 | $canCreate[] = PropertyType::cast($canCreateItem); |
|
354 | 1 | } catch (InvalidEnumerationValueException $exception) { |
|
355 | 1 | // ignore invalid types |
|
356 | 1 | } |
|
357 | 1 | } |
|
358 | |||
359 | 1 | $object->setCanCreate($canCreate); |
|
360 | |||
361 | $object->setExtensions( |
||
362 | $this->convertExtension( |
||
363 | $data, |
||
364 | JSONConstants::getCapabilityCreatablePropertyKeys() |
||
365 | ) |
||
366 | ); |
||
367 | |||
368 | return $object; |
||
369 | 1 | } |
|
370 | |||
371 | 1 | /** |
|
372 | * @param array|null $data |
||
373 | * @param boolean $isExact |
||
374 | * @return AccessControlList |
||
375 | 1 | */ |
|
376 | public function convertAcl(array $data = null, $isExact = false) |
||
377 | 1 | { |
|
378 | 1 | if (empty($data)) { |
|
379 | 1 | return null; |
|
380 | 1 | } |
|
381 | |||
382 | 1 | $aces = []; |
|
383 | if (isset($data[JSONConstants::JSON_ACL_ACES]) && is_array($data[JSONConstants::JSON_ACL_ACES])) { |
||
384 | 1 | foreach ($data[JSONConstants::JSON_ACL_ACES] as $aceData) { |
|
385 | 1 | if (empty($aceData[JSONConstants::JSON_ACE_PRINCIPAL][JSONConstants::JSON_ACE_PRINCIPAL_ID])) { |
|
386 | continue; |
||
387 | } |
||
388 | 1 | ||
389 | $permissions = array_filter( |
||
390 | 1 | $aceData[JSONConstants::JSON_ACE_PERMISSIONS] ?? [], |
|
391 | 1 | function($item) { return !empty($item); } |
|
392 | ); |
||
393 | 1 | ||
394 | 1 | $principal = new Principal( |
|
395 | 1 | (string) $aceData[JSONConstants::JSON_ACE_PRINCIPAL][JSONConstants::JSON_ACE_PRINCIPAL_ID] |
|
396 | 1 | ); |
|
397 | 1 | ||
398 | 1 | $principal->setExtensions( |
|
399 | $this->convertExtension( |
||
400 | 1 | $aceData[JSONConstants::JSON_ACE_PRINCIPAL], |
|
401 | JSONConstants::getAcePrincipalKeys() |
||
402 | ) |
||
403 | ); |
||
404 | |||
405 | $ace = new AccessControlEntry($principal, $permissions); |
||
406 | |||
407 | if (isset($aceData[JSONConstants::JSON_ACE_IS_DIRECT])) { |
||
408 | 3 | $ace->setIsDirect((boolean) ($aceData[JSONConstants::JSON_ACE_IS_DIRECT] ?? false)); |
|
409 | } |
||
410 | 3 | ||
411 | 1 | $ace->setExtensions($this->convertExtension($aceData, JSONConstants::getAceKeys())); |
|
412 | |||
413 | $aces[] = $ace; |
||
414 | 2 | } |
|
415 | 2 | } |
|
416 | 2 | ||
417 | 2 | $acl = new AccessControlList($aces); |
|
418 | 2 | $acl->setIsExact($isExact); |
|
419 | $acl->setExtensions($this->convertExtension($data, JSONConstants::getAclKeys())); |
||
420 | |||
421 | 1 | return $acl; |
|
422 | 1 | } |
|
423 | 1 | ||
424 | 1 | /** |
|
425 | 1 | * @param array|null $data |
|
426 | 1 | * @return AclCapabilities|null |
|
427 | 1 | */ |
|
428 | 1 | public function convertAclCapabilities(array $data = null) |
|
429 | 1 | { |
|
430 | 1 | if (empty($data)) { |
|
431 | return null; |
||
432 | 1 | } |
|
433 | 1 | ||
434 | 1 | $aclCapabilities = new AclCapabilities(); |
|
435 | $aclCapabilities->setSupportedPermissions( |
||
436 | 1 | SupportedPermissions::cast($data[JSONConstants::JSON_ACLCAP_SUPPORTED_PERMISSIONS]) |
|
437 | 1 | ); |
|
438 | 1 | $aclCapabilities->setAclPropagation( |
|
439 | 1 | AclPropagation::cast($data[JSONConstants::JSON_ACLCAP_ACL_PROPAGATION]) |
|
440 | 1 | ); |
|
441 | 1 | ||
442 | $permissionDefinitionList = []; |
||
443 | 1 | ||
444 | foreach ($data[JSONConstants::JSON_ACLCAP_PERMISSIONS] ?? [] as $permissionData) { |
||
445 | 1 | $permissionDefinition = new PermissionDefinition(); |
|
446 | 1 | ||
447 | 1 | $permissionDefinition->setId( |
|
448 | (string) $permissionData[JSONConstants::JSON_ACLCAP_PERMISSION_PERMISSION] |
||
449 | 1 | ); |
|
450 | $permissionDefinition->setDescription( |
||
451 | 1 | (string) $permissionData[JSONConstants::JSON_ACLCAP_PERMISSION_DESCRIPTION] |
|
452 | 2 | ); |
|
453 | 2 | ||
454 | // handle extensions |
||
455 | 2 | ||
456 | 2 | $permissionDefinition->setExtensions( |
|
457 | 2 | $this->convertExtension( |
|
458 | $permissionData, |
||
459 | 2 | JSONConstants::getAclCapabilityPermissionKeys() |
|
460 | ) |
||
461 | ); |
||
462 | |||
463 | $permissionDefinitionList[] = $permissionDefinition; |
||
464 | } |
||
465 | |||
466 | 2 | $aclCapabilities->setPermissions($permissionDefinitionList); |
|
467 | |||
468 | 2 | $permissionMappingList = []; |
|
469 | 1 | ||
470 | foreach ($data[JSONConstants::JSON_ACLCAP_PERMISSION_MAPPING] ?? [] as $permissionMapping) { |
||
471 | $mapping = new PermissionMapping(); |
||
472 | 1 | $key = (string) $permissionMapping[JSONConstants::JSON_ACLCAP_MAPPING_KEY]; |
|
473 | 1 | ||
474 | 1 | $mapping->setKey($key); |
|
475 | 1 | ||
476 | 1 | $mapping->setPermissions( |
|
477 | 1 | array_map( |
|
478 | 1 | 'strval', |
|
479 | array_filter( |
||
480 | 1 | $permissionMapping[JSONConstants::JSON_ACLCAP_MAPPING_PERMISSION] ?? [], |
|
481 | 1 | function ($item) { return !empty($item); } |
|
482 | 1 | ) |
|
483 | 1 | ) |
|
484 | 1 | ); |
|
485 | |||
486 | 1 | $mapping->setExtensions( |
|
487 | 1 | $this->convertExtension($permissionMapping, JSONConstants::getAclCapabilityMappingKeys()) |
|
488 | 1 | ); |
|
489 | |||
490 | 1 | $permissionMappingList[$key] = $mapping; |
|
491 | 1 | } |
|
492 | 1 | ||
493 | 1 | $aclCapabilities->setPermissionMapping($permissionMappingList); |
|
494 | 1 | ||
495 | 1 | // handle extensions |
|
496 | $aclCapabilities->setExtensions($this->convertExtension($data, JSONConstants::getAclCapabilityKeys())); |
||
497 | |||
498 | return $aclCapabilities; |
||
499 | 1 | } |
|
500 | 1 | ||
501 | 1 | /** |
|
502 | 1 | * Convert an array to a type definition object |
|
503 | 1 | * |
|
504 | 1 | * @param array|null $data |
|
505 | * @return AbstractTypeDefinition|null |
||
506 | 1 | * @throws CmisInvalidArgumentException |
|
507 | 1 | */ |
|
508 | 1 | public function convertTypeDefinition(array $data = null) |
|
509 | { |
||
510 | 1 | if (empty($data)) { |
|
511 | 1 | return null; |
|
512 | } |
||
513 | 1 | ||
514 | 1 | if (empty($data[JSONConstants::JSON_TYPE_ID])) { |
|
515 | 1 | throw new CmisInvalidArgumentException('Id of type definition is empty but must not be empty!'); |
|
516 | 1 | } |
|
517 | 1 | $typeDefinition = $this->getBindingsObjectFactory()->getTypeDefinitionByBaseTypeId( |
|
518 | $data[JSONConstants::JSON_TYPE_BASE_ID] ?? '', |
||
519 | 1 | $data[JSONConstants::JSON_TYPE_ID] ?? '' |
|
520 | 1 | ); |
|
521 | 1 | ||
522 | $data = $this->convertTypeDefinitionSpecificData($data, $typeDefinition); |
||
523 | 1 | ||
524 | $data[JSONConstants::JSON_TYPE_TYPE_MUTABILITY] = $this->convertTypeMutability( |
||
525 | 1 | $data[JSONConstants::JSON_TYPE_TYPE_MUTABILITY] ?? null |
|
526 | 1 | ); |
|
527 | 1 | ||
528 | 1 | foreach ($data[JSONConstants::JSON_TYPE_PROPERTY_DEFINITIONS] ?? [] as $propertyDefinitionData) { |
|
0 ignored issues
–
show
The expression
$data[\Dkd\PhpCmis\Bindi...DEFINITIONS] ?? array() of type object<Dkd\PhpCmis\DataO...s\TypeMutability>|array is not guaranteed to be traversable. How about adding an additional type check?
There are different options of fixing this problem.
![]() |
|||
529 | 1 | if (is_array($propertyDefinitionData)) { |
|
530 | 1 | $propertyDefinition = $this->convertPropertyDefinition($propertyDefinitionData); |
|
531 | 1 | if ($propertyDefinition !== null) { |
|
532 | 1 | $typeDefinition->addPropertyDefinition($propertyDefinition); |
|
533 | 1 | } |
|
534 | 1 | } |
|
535 | 1 | } |
|
536 | |||
537 | 1 | unset( |
|
538 | 1 | $data[JSONConstants::JSON_TYPE_BASE_ID], |
|
539 | 1 | $data[JSONConstants::JSON_TYPE_ID], |
|
540 | $data[JSONConstants::JSON_TYPE_PROPERTY_DEFINITIONS] |
||
541 | 1 | ); |
|
542 | 1 | ||
543 | $typeDefinition->populate( |
||
544 | 1 | array_filter($data, function ($item) { return !empty($item); }), |
|
545 | 1 | array_merge( |
|
546 | array_combine(JSONConstants::getTypeKeys(), JSONConstants::getTypeKeys()), |
||
547 | [ |
||
548 | 1 | JSONConstants::JSON_TYPE_PARENT_ID => 'parentTypeId', |
|
549 | JSONConstants::JSON_TYPE_ALLOWED_TARGET_TYPES => 'allowedTargetTypeIds', |
||
550 | 1 | JSONConstants::JSON_TYPE_ALLOWED_SOURCE_TYPES => 'allowedSourceTypeIds', |
|
551 | ] |
||
552 | ), |
||
553 | true |
||
554 | ); |
||
555 | |||
556 | $typeDefinition->setExtensions($this->convertExtension($data, JSONConstants::getTypeKeys())); |
||
557 | |||
558 | return $typeDefinition; |
||
559 | } |
||
560 | 15 | ||
561 | /** |
||
562 | 15 | * Convert specific type definition data so it can be populated to the type definition |
|
563 | 1 | * |
|
564 | * @param MutableTypeDefinitionInterface $typeDefinition The type definition to set the data to |
||
565 | * @param array $data The data that contains the values that should be applied to the object |
||
566 | 14 | * @return MutableTypeDefinitionInterface The type definition with the specific data applied |
|
567 | 1 | */ |
|
568 | private function convertTypeDefinitionSpecificData(array $data, MutableTypeDefinitionInterface $typeDefinition) |
||
569 | 13 | { |
|
570 | 13 | if ($typeDefinition instanceof MutableDocumentTypeDefinitionInterface) { |
|
571 | 12 | if (!empty($data[JSONConstants::JSON_TYPE_CONTENTSTREAM_ALLOWED])) { |
|
572 | 12 | $data[JSONConstants::JSON_TYPE_CONTENTSTREAM_ALLOWED] = ContentStreamAllowed::cast( |
|
573 | 12 | $data[JSONConstants::JSON_TYPE_CONTENTSTREAM_ALLOWED] |
|
574 | ); |
||
575 | 13 | } |
|
576 | 13 | } elseif ($typeDefinition instanceof MutableRelationshipTypeDefinitionInterface) { |
|
577 | 13 | ||
578 | 13 | $data[JSONConstants::JSON_TYPE_ALLOWED_SOURCE_TYPES] = array_map( |
|
579 | 'strval', |
||
580 | 12 | array_filter( |
|
581 | $data[JSONConstants::JSON_TYPE_ALLOWED_SOURCE_TYPES] ?? [], |
||
582 | 12 | function ($item) { return !empty($item); } |
|
583 | 2 | ) |
|
584 | 2 | ); |
|
585 | 2 | $data[JSONConstants::JSON_TYPE_ALLOWED_SOURCE_TYPES] = array_map( |
|
586 | 2 | 'strval', |
|
587 | array_filter( |
||
588 | $data[JSONConstants::JSON_TYPE_ALLOWED_SOURCE_TYPES] ?? [], |
||
589 | 2 | function ($item) { return !empty($item); } |
|
590 | ) |
||
591 | 12 | ); |
|
592 | 12 | $data[JSONConstants::JSON_TYPE_ALLOWED_TARGET_TYPES] = array_map( |
|
593 | 12 | 'strval', |
|
594 | 2 | array_filter( |
|
595 | 2 | $data[JSONConstants::JSON_TYPE_ALLOWED_TARGET_TYPES] ?? [], |
|
596 | 2 | function ($item) { return !empty($item); } |
|
597 | 2 | ) |
|
598 | ); |
||
599 | |||
600 | 2 | } |
|
601 | 2 | ||
602 | 2 | return $data; |
|
603 | 12 | } |
|
604 | |||
605 | 12 | /** |
|
606 | 12 | * Convert an array to a type mutability object |
|
607 | 12 | * |
|
608 | 12 | * @param array|null $data The data that should be populated to the object |
|
609 | * @return TypeMutability|null Returns the type mutability object or <code>null</code> if empty array is given |
||
610 | 12 | */ |
|
611 | 12 | View Code Duplication | public function convertTypeMutability(array $data = null) |
0 ignored issues
–
show
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. ![]() |
|||
612 | 12 | { |
|
613 | if (empty($data)) { |
||
614 | 12 | return null; |
|
615 | } |
||
616 | 12 | $typeMutability = new TypeMutability(); |
|
617 | $typeMutability->populate( |
||
618 | 12 | $data, |
|
619 | array_combine( |
||
620 | 12 | JSONConstants::getTypeTypeMutabilityKeys(), |
|
621 | array_map( |
||
622 | function ($key) { |
||
623 | // add a prefix "can" to all keys as this are the property names |
||
624 | return 'can' . ucfirst($key); |
||
625 | }, |
||
626 | JSONConstants::getTypeTypeMutabilityKeys() |
||
627 | ) |
||
628 | ), |
||
629 | true |
||
630 | ); |
||
631 | |||
632 | $typeMutability->setExtensions( |
||
633 | $this->convertExtension($data, JSONConstants::getTypeTypeMutabilityKeys()) |
||
634 | ); |
||
635 | |||
636 | return $typeMutability; |
||
637 | } |
||
638 | |||
639 | /** |
||
640 | * @param array|null $data |
||
641 | * @return PropertyDefinitionInterface|null |
||
642 | */ |
||
643 | public function convertPropertyDefinition(array $data = null) |
||
644 | { |
||
645 | if (empty($data)) { |
||
646 | return null; |
||
647 | } |
||
648 | |||
649 | $data = $this->preparePropertyDefinitionData($data); |
||
650 | |||
651 | $propertyDefinition = $this->getPropertyDefinitionByType( |
||
652 | $data[JSONConstants::JSON_PROPERTY_TYPE_PROPERTY_TYPE], |
||
653 | $data |
||
654 | ); |
||
655 | |||
656 | // remove the id property as it has been already set to the property definition. |
||
657 | unset($data[JSONConstants::JSON_PROPERTY_TYPE_ID]); |
||
658 | |||
659 | // TODO |
||
660 | // $propertyDefinition->setChoices( |
||
661 | // $this->convertChoicesString($data[JSONConstants::JSON_PROPERTY_TYPE_CHOICE]) // TODO |
||
662 | // ); |
||
663 | // |
||
664 | // // default value |
||
665 | // Object defaultValue = json.get(JSON_PROPERTY_TYPE_DEAULT_VALUE); |
||
666 | // if (defaultValue != null) { |
||
667 | // if (defaultValue instanceof List) { |
||
668 | // List values = new ArrayList(); |
||
669 | // for (Object value : (List) defaultValue) { |
||
670 | // values.add(getCMISValue(value, propertyType)); |
||
671 | // } |
||
672 | // result.setDefaultValue(values); |
||
673 | // } else { |
||
674 | // result.setDefaultValue((List) Collections.singletonList(getCMISValue(defaultValue, propertyType))); |
||
675 | // } |
||
676 | // } |
||
677 | |||
678 | $propertyDefinition->populate( |
||
679 | array_intersect_key($data, array_fill_keys(JSONConstants::getPropertyTypeKeys(), 1)), |
||
680 | [JSONConstants::JSON_PROPERTY_TYPE_RESOLUTION => 'dateTimeResolution'] |
||
681 | ); |
||
682 | $propertyDefinition->setExtensions($this->convertExtension($data, JSONConstants::getPropertyTypeKeys())); |
||
683 | |||
684 | return $propertyDefinition; |
||
685 | } |
||
686 | |||
687 | /** |
||
688 | * Cast data values to the expected type |
||
689 | * |
||
690 | * @param array $data |
||
691 | * @return array |
||
692 | */ |
||
693 | protected function preparePropertyDefinitionData(array $data) |
||
694 | { |
||
695 | $data[JSONConstants::JSON_PROPERTY_TYPE_PROPERTY_TYPE] = PropertyType::cast( |
||
696 | $data[JSONConstants::JSON_PROPERTY_TYPE_PROPERTY_TYPE] |
||
697 | ); |
||
698 | |||
699 | View Code Duplication | if (isset($data[JSONConstants::JSON_PROPERTY_TYPE_DEAULT_VALUE])) { |
|
700 | $data[JSONConstants::JSON_PROPERTY_TYPE_DEAULT_VALUE] |
||
701 | = (array) $data[JSONConstants::JSON_PROPERTY_TYPE_DEAULT_VALUE]; |
||
702 | } |
||
703 | |||
704 | if (isset($data[JSONConstants::JSON_PROPERTY_TYPE_RESOLUTION])) { |
||
705 | $data[JSONConstants::JSON_PROPERTY_TYPE_RESOLUTION] = DateTimeResolution::cast( |
||
706 | 9 | $data[JSONConstants::JSON_PROPERTY_TYPE_RESOLUTION] |
|
707 | ); |
||
708 | 9 | } |
|
709 | 1 | ||
710 | if (isset($data[JSONConstants::JSON_PROPERTY_TYPE_PRECISION])) { |
||
711 | $data[JSONConstants::JSON_PROPERTY_TYPE_PRECISION] = DecimalPrecision::cast( |
||
712 | 8 | $data[JSONConstants::JSON_PROPERTY_TYPE_PRECISION] |
|
713 | ); |
||
714 | 8 | } |
|
715 | 8 | ||
716 | if (isset($data[JSONConstants::JSON_PROPERTY_TYPE_CARDINALITY])) { |
||
717 | 8 | $data[JSONConstants::JSON_PROPERTY_TYPE_CARDINALITY] = Cardinality::cast( |
|
718 | $data[JSONConstants::JSON_PROPERTY_TYPE_CARDINALITY] |
||
719 | ); |
||
720 | 8 | } |
|
721 | |||
722 | View Code Duplication | if (isset($data[JSONConstants::JSON_PROPERTY_TYPE_UPDATABILITY])) { |
|
723 | $data[JSONConstants::JSON_PROPERTY_TYPE_UPDATABILITY] = Updatability::cast( |
||
724 | $data[JSONConstants::JSON_PROPERTY_TYPE_UPDATABILITY] |
||
725 | ); |
||
726 | } |
||
727 | |||
728 | return $data; |
||
729 | } |
||
730 | |||
731 | /** |
||
732 | * @param PropertyType $propertyType |
||
733 | * @param array $data |
||
734 | * @return PropertyBooleanDefinition|PropertyDateTimeDefinition|PropertyDecimalDefinition|PropertyHtmlDefinition|PropertyIdDefinition|PropertyIntegerDefinition|PropertyStringDefinition |
||
735 | */ |
||
736 | protected function getPropertyDefinitionByType(PropertyType $propertyType, array $data = []) |
||
737 | { |
||
738 | $id = null; |
||
739 | if (!empty($data[JSONConstants::JSON_PROPERTY_TYPE_ID])) { |
||
740 | $id = $data[JSONConstants::JSON_PROPERTY_TYPE_ID]; |
||
741 | 8 | } |
|
742 | 8 | ||
743 | 8 | if ($propertyType->equals(PropertyType::STRING)) { |
|
744 | 8 | $propertyDefinition = new PropertyStringDefinition($id); |
|
745 | 8 | } elseif ($propertyType->equals(PropertyType::ID)) { |
|
746 | $propertyDefinition = new PropertyIdDefinition($id); |
||
747 | 8 | } elseif ($propertyType->equals(PropertyType::BOOLEAN)) { |
|
748 | $propertyDefinition = new PropertyBooleanDefinition($id); |
||
749 | } elseif ($propertyType->equals(PropertyType::INTEGER)) { |
||
750 | $propertyDefinition = new PropertyIntegerDefinition($id); |
||
751 | } elseif ($propertyType->equals(PropertyType::DATETIME)) { |
||
752 | $propertyDefinition = new PropertyDateTimeDefinition($id); |
||
753 | } elseif ($propertyType->equals(PropertyType::DECIMAL)) { |
||
754 | $propertyDefinition = new PropertyDecimalDefinition($id); |
||
755 | } elseif ($propertyType->equals(PropertyType::HTML)) { |
||
756 | 9 | $propertyDefinition = new PropertyHtmlDefinition($id); |
|
757 | } elseif ($propertyType->equals(PropertyType::URI)) { |
||
758 | 9 | $propertyDefinition = new PropertyUriDefinition($id); |
|
759 | 9 | } else { |
|
760 | 9 | // @codeCoverageIgnoreStart |
|
761 | // this could only happen if a new property type is added to the enumeration and not implemented here. |
||
762 | 9 | throw new CmisInvalidArgumentException( |
|
763 | 1 | sprintf('The given property definition "%s" could not be converted.', $propertyType) |
|
764 | 1 | ); |
|
765 | 1 | // @codeCoverageIgnoreEnd |
|
766 | } |
||
767 | 9 | ||
768 | 2 | $propertyDefinition->setPropertyType($propertyType); |
|
769 | 2 | ||
770 | 2 | return $propertyDefinition; |
|
771 | 2 | } |
|
772 | |||
773 | 9 | /** |
|
774 | 2 | * Converts an object. |
|
775 | 2 | * |
|
776 | 2 | * @param array|null $data |
|
777 | 2 | * @return null|ObjectData |
|
778 | */ |
||
779 | 9 | public function convertObject(array $data = null) |
|
780 | 9 | { |
|
781 | 9 | if (empty($data)) { |
|
782 | 9 | return null; |
|
783 | 9 | } |
|
784 | |||
785 | 9 | $object = new ObjectData(); |
|
786 | 9 | $acl = $this->convertAcl( |
|
787 | 9 | $data[JSONConstants::JSON_OBJECT_ACL] ?? [], |
|
788 | 9 | (boolean) ($data[JSONConstants::JSON_OBJECT_EXACT_ACL] ?? false) |
|
789 | 9 | ); |
|
790 | if ($acl !== null) { |
||
791 | 9 | $object->setAcl($acl); |
|
792 | } |
||
793 | |||
794 | $allowableActions = $this->convertAllowableActions($data[JSONConstants::JSON_OBJECT_ALLOWABLE_ACTIONS] ?? []); |
||
795 | if ($allowableActions !== null) { |
||
796 | $object->setAllowableActions($allowableActions); |
||
797 | } |
||
798 | |||
799 | 8 | if (isset($data[JSONConstants::JSON_OBJECT_CHANGE_EVENT_INFO]) |
|
800 | && is_array($data[JSONConstants::JSON_OBJECT_CHANGE_EVENT_INFO]) |
||
801 | 8 | ) { |
|
802 | 8 | $changeEventInfoData = $data[JSONConstants::JSON_OBJECT_CHANGE_EVENT_INFO]; |
|
803 | 8 | $changeEventInfo = new ChangeEventInfo(); |
|
804 | 8 | $changeEventInfo->setChangeTime( |
|
805 | $this->convertDateTimeValue($changeEventInfoData[JSONConstants::JSON_CHANGE_EVENT_TIME]) |
||
806 | 8 | ); |
|
807 | 1 | $changeEventInfo->setChangeType( |
|
808 | 8 | ChangeType::cast($changeEventInfoData[JSONConstants::JSON_CHANGE_EVENT_TYPE]) |
|
809 | 1 | ); |
|
810 | 7 | ||
811 | 1 | $changeEventInfo->setExtensions( |
|
812 | 6 | $this->convertExtension($changeEventInfoData, JSONConstants::getChangeEventKeys()) |
|
813 | 1 | ); |
|
814 | 5 | ||
815 | 1 | $object->setChangeEventInfo($changeEventInfo); |
|
816 | 4 | } |
|
817 | 1 | ||
818 | 3 | $object->setIsExactAcl((boolean) ($data[JSONConstants::JSON_OBJECT_EXACT_ACL] ?? false)); |
|
819 | 1 | $object->setPolicyIds($this->convertPolicyIdList($data[JSONConstants::JSON_OBJECT_POLICY_IDS] ?? null)); |
|
820 | 2 | ||
821 | 1 | /** |
|
822 | 1 | * A client MAY add the query parameter succinct (HTTP GET) or the control succinct (HTTP POST) with the |
|
823 | * value <code>true</code> to a request. If this is set, the repository MUST return properties in a succinct |
||
824 | * format. That is, whenever the repository renders an object or a query result, it MUST populate the |
||
825 | * succinctProperties value and MUST NOT populate the properties value. |
||
826 | * |
||
827 | * @see http://docs.oasis-open.org/cmis/CMIS/v1.1/os/CMIS-v1.1-os.html#x1-552027r554 |
||
828 | */ |
||
829 | if (isset($data[JSONConstants::JSON_OBJECT_SUCCINCT_PROPERTIES])) { |
||
830 | $properties = $this->convertSuccinctProperties( |
||
831 | 8 | $data[JSONConstants::JSON_OBJECT_SUCCINCT_PROPERTIES] ?? [], |
|
832 | (array) ($data[JSONConstants::JSON_OBJECT_PROPERTIES_EXTENSION] ?? []) |
||
833 | 8 | ); |
|
834 | } else { |
||
835 | $properties = $this->convertProperties( |
||
836 | $data[JSONConstants::JSON_OBJECT_PROPERTIES] ?? [], |
||
837 | (array) ($data[JSONConstants::JSON_OBJECT_PROPERTIES_EXTENSION] ?? []) |
||
838 | ); |
||
839 | } |
||
840 | |||
841 | $object->setProperties($properties ?? []); |
||
0 ignored issues
–
show
It seems like
$properties ?? array() can also be of type array ; however, Dkd\PhpCmis\DataObjects\...ctData::setProperties() does only seem to accept object<Dkd\PhpCmis\Data\PropertiesInterface> , 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. ![]() |
|||
842 | 2 | $object->setRelationships($this->convertObjects($data[JSONConstants::JSON_OBJECT_RELATIONSHIPS] ?? null)); |
|
843 | $object->setRenditions($this->convertRenditions($data[JSONConstants::JSON_OBJECT_RENDITIONS] ?? [])); |
||
844 | 2 | $object->setExtensions($this->convertExtension($data, JSONConstants::getObjectKeys())); |
|
845 | 1 | ||
846 | return $object; |
||
847 | } |
||
848 | 1 | ||
849 | 1 | /** |
|
850 | 1 | * @param array|null $data |
|
851 | 1 | * @return ObjectDataInterface[] |
|
852 | 1 | */ |
|
853 | 1 | View Code Duplication | public function convertObjects(array $data = null) |
0 ignored issues
–
show
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. ![]() |
|||
854 | 1 | { |
|
855 | 1 | return array_filter( |
|
856 | 1 | array_map( |
|
857 | 1 | [$this, 'convertObject'], |
|
858 | 1 | array_filter( |
|
859 | 1 | (array) $data, |
|
860 | 'is_array' |
||
861 | 1 | ) |
|
862 | 1 | ), |
|
863 | 1 | function ($item) { |
|
864 | 1 | // @TODO once a logger is available we should log an INFO message if the object could not be converted |
|
865 | 1 | return !empty($item); |
|
866 | 1 | } |
|
867 | ); |
||
868 | 1 | } |
|
869 | 1 | ||
870 | 1 | /** |
|
871 | 1 | * @param array|null $data |
|
872 | 1 | * @param array $extensions |
|
873 | 1 | * @return null|Properties |
|
874 | 1 | * @throws CmisRuntimeException |
|
875 | 1 | */ |
|
876 | 1 | public function convertProperties(array $data = null, $extensions = []) |
|
877 | 1 | { |
|
878 | 1 | if (empty($data)) { |
|
879 | return null; |
||
880 | 1 | } |
|
881 | 1 | $properties = new Properties(); |
|
882 | 1 | ||
883 | foreach ($data as $propertyData) { |
||
884 | 1 | $id = $propertyData[JSONConstants::JSON_PROPERTY_ID] ?? null; |
|
885 | 1 | $queryName = $propertyData[JSONConstants::JSON_PROPERTY_QUERYNAME] ?? null; |
|
886 | |||
887 | 1 | // A Property must always have an ID except if it used in a query result. |
|
888 | 1 | // In a query result a Property should have an ID and must have a query name. |
|
889 | 1 | if ($id === null && $queryName === null) { |
|
890 | 1 | throw new CmisRuntimeException('Invalid property! Neither a property ID nor a query name is provided!'); |
|
891 | 1 | } |
|
892 | 1 | ||
893 | try { |
||
894 | $propertyType = PropertyType::cast($propertyData[JSONConstants::JSON_PROPERTY_DATATYPE]); |
||
895 | } catch (InvalidEnumerationValueException $exception) { |
||
896 | throw new CmisRuntimeException( |
||
897 | sprintf('Unknown property type "%s"!', $propertyData[JSONConstants::JSON_PROPERTY_DATATYPE]) |
||
898 | ); |
||
899 | } |
||
900 | |||
901 | // get property keys without JSON-response-specific cardinality properties |
||
902 | 1 | $jsonPropertyKeys = JSONConstants::getPropertyKeys(); |
|
903 | 1 | $propertyKeys = array_values( |
|
904 | 1 | array_diff( |
|
905 | $jsonPropertyKeys, |
||
906 | [ |
||
907 | // remove the cardinality property here as this is not a property of a property but only |
||
908 | // required for the other way when converting the property to the JSON object for the |
||
909 | // browser binding. |
||
910 | JSONConstants::JSON_PROPERTY_CARDINALITY, |
||
911 | 1 | JSONConstants::JSON_PROPERTY_VALUE, |
|
912 | 1 | JSONConstants::JSON_PROPERTY_ID, |
|
913 | 1 | JSONConstants::JSON_PROPERTY_DATATYPE |
|
914 | 1 | ] |
|
915 | 1 | ) |
|
916 | 1 | ); |
|
917 | 1 | ||
918 | 1 | $property = $this->getPropertyByPropertyType( |
|
919 | 1 | $propertyType, |
|
920 | 1 | $id, |
|
921 | 1 | (array) ($propertyData[JSONConstants::JSON_PROPERTY_VALUE] ?? []) |
|
922 | 1 | ); |
|
923 | $property->populate( |
||
924 | 1 | $propertyData, |
|
925 | 1 | $propertyKeys, |
|
926 | 1 | true |
|
927 | ); |
||
928 | $property->setExtensions($this->convertExtension($propertyData, $jsonPropertyKeys)); |
||
929 | |||
930 | $properties->addProperty($property); |
||
931 | } |
||
932 | |||
933 | 1 | if (!empty($extensions)) { |
|
934 | 1 | $properties->setExtensions($this->convertExtension($extensions)); |
|
935 | 1 | } |
|
936 | 1 | ||
937 | 1 | return $properties; |
|
938 | } |
||
939 | 1 | ||
940 | /** |
||
941 | 1 | * @param PropertyType $propertyType |
|
942 | * @param string $id |
||
943 | * @param array $propertyValues |
||
944 | * @return PropertyBoolean|PropertyDateTime|PropertyDecimal|PropertyHtml|PropertyId|PropertyInteger|PropertyString |
||
945 | */ |
||
946 | protected function getPropertyByPropertyType(PropertyType $propertyType, $id, array $propertyValues) |
||
947 | { |
||
948 | 2 | if ($propertyType->equals(PropertyType::cast(PropertyType::STRING))) { |
|
949 | $property = new PropertyString($id, $this->convertStringValues($propertyValues)); |
||
950 | 2 | } elseif ($propertyType->equals(PropertyType::cast(PropertyType::ID))) { |
|
951 | $property = new PropertyId($id, $this->convertStringValues($propertyValues)); |
||
952 | 2 | } elseif ($propertyType->equals(PropertyType::cast(PropertyType::BOOLEAN))) { |
|
953 | 1 | $property = new PropertyBoolean($id, $this->convertBooleanValues($propertyValues)); |
|
954 | } elseif ($propertyType->equals(PropertyType::cast(PropertyType::INTEGER))) { |
||
955 | $property = new PropertyInteger($id, $this->convertIntegerValues($propertyValues)); |
||
956 | 1 | } elseif ($propertyType->equals(PropertyType::cast(PropertyType::DATETIME))) { |
|
957 | 1 | $property = new PropertyDateTime($id, $this->convertDateTimeValues($propertyValues)); |
|
958 | 1 | } elseif ($propertyType->equals(PropertyType::cast(PropertyType::DECIMAL))) { |
|
959 | $property = new PropertyDecimal($id, $this->convertDecimalValues($propertyValues)); |
||
960 | 1 | } elseif ($propertyType->equals(PropertyType::cast(PropertyType::HTML))) { |
|
961 | $property = new PropertyHtml($id, $this->convertStringValues($propertyValues)); |
||
962 | } elseif ($propertyType->equals(PropertyType::cast(PropertyType::URI))) { |
||
963 | 1 | $property = new PropertyUri($id, $this->convertStringValues($propertyValues)); |
|
964 | 1 | } else { |
|
965 | 1 | // this could only happen if a new property type is added to the enumeration and not implemented here. |
|
966 | 1 | throw new CmisInvalidArgumentException( |
|
967 | sprintf('The given property type "%s" could not be converted.', $propertyType) |
||
968 | 1 | ); |
|
969 | } |
||
970 | |||
971 | return $property; |
||
972 | } |
||
973 | |||
974 | /** |
||
975 | * TODO Add description |
||
976 | * |
||
977 | 4 | * @param array|null $data |
|
978 | * @param array $extensions |
||
979 | 4 | * @return PropertiesInterface |
|
980 | 1 | * @throws \Exception |
|
981 | */ |
||
982 | 3 | public function convertSuccinctProperties(array $data = null, $extensions = []) |
|
983 | { |
||
984 | 3 | throw new \Exception('Succinct properties are currently not supported.'); |
|
985 | 3 | // TODO IMPLEMENT SUCCINCT PROPERTY SUPPORT |
|
986 | 3 | // if (empty($data)) { |
|
987 | 3 | // return null; |
|
988 | 3 | // } |
|
989 | // if (isset($data[PropertyIds::SECONDARY_OBJECT_TYPE_IDS]) |
||
990 | // && is_array($data[PropertyIds::SECONDARY_OBJECT_TYPE_IDS]) |
||
991 | // ) { |
||
992 | 3 | // $secondaryTypeIds = $data[PropertyIds::SECONDARY_OBJECT_TYPE_IDS]; |
|
993 | 1 | // $secondaryTypeDefinitions = array(); |
|
994 | // foreach($secondaryTypeIds as $secondaryTypeId) { |
||
995 | // if ((string) $secondaryTypeId !== "") { |
||
996 | // $secondaryTypeDefinitions[] = |
||
997 | 2 | // } |
|
998 | 2 | // } |
|
999 | 1 | // } |
|
1000 | 1 | // |
|
1001 | 1 | // $properties = array(); |
|
1002 | // |
||
1003 | // foreach ($data as $propertyId => $propertyData) { |
||
1004 | 1 | // ... |
|
1005 | // } |
||
1006 | 1 | // |
|
1007 | 1 | // return $properties; |
|
1008 | 1 | } |
|
1009 | 1 | ||
1010 | /** |
||
1011 | * Convert given input data to a RenditionData object |
||
1012 | * |
||
1013 | 1 | * @param array|null $data |
|
1014 | 1 | * @return null|RenditionData |
|
1015 | 1 | */ |
|
1016 | 1 | public function convertRendition(array $data = null) |
|
1017 | { |
||
1018 | if (empty($data)) { |
||
1019 | return null; |
||
1020 | } |
||
1021 | 1 | $rendition = new RenditionData(); |
|
1022 | 1 | ||
1023 | 1 | if (isset($data[JSONConstants::JSON_RENDITION_HEIGHT])) { |
|
1024 | $rendition->setHeight((integer) $data[JSONConstants::JSON_RENDITION_HEIGHT]); |
||
1025 | 1 | } |
|
1026 | 1 | if (isset($data[JSONConstants::JSON_RENDITION_KIND])) { |
|
1027 | 1 | $rendition->setKind((string) $data[JSONConstants::JSON_RENDITION_KIND]); |
|
1028 | } |
||
1029 | 1 | if (isset($data[JSONConstants::JSON_RENDITION_LENGTH])) { |
|
1030 | 1 | $rendition->setLength((integer) $data[JSONConstants::JSON_RENDITION_LENGTH]); |
|
1031 | 1 | } |
|
1032 | 1 | if (isset($data[JSONConstants::JSON_RENDITION_MIMETYPE])) { |
|
1033 | $rendition->setMimeType((string) $data[JSONConstants::JSON_RENDITION_MIMETYPE]); |
||
1034 | 1 | } |
|
1035 | 1 | if (isset($data[JSONConstants::JSON_RENDITION_DOCUMENT_ID])) { |
|
1036 | $rendition->setRenditionDocumentId((string) $data[JSONConstants::JSON_RENDITION_DOCUMENT_ID]); |
||
1037 | 1 | } |
|
1038 | 1 | if (isset($data[JSONConstants::JSON_RENDITION_STREAM_ID])) { |
|
1039 | $rendition->setStreamId((string) $data[JSONConstants::JSON_RENDITION_STREAM_ID]); |
||
1040 | 1 | } |
|
1041 | 1 | if (isset($data[JSONConstants::JSON_RENDITION_TITLE])) { |
|
1042 | 1 | $rendition->setTitle((string) $data[JSONConstants::JSON_RENDITION_TITLE]); |
|
1043 | } |
||
1044 | 1 | if (isset($data[JSONConstants::JSON_RENDITION_WIDTH])) { |
|
1045 | $rendition->setWidth((integer) $data[JSONConstants::JSON_RENDITION_WIDTH]); |
||
1046 | } |
||
1047 | |||
1048 | $rendition->setExtensions($this->convertExtension($data, JSONConstants::getRenditionKeys())); |
||
1049 | |||
1050 | return $rendition; |
||
1051 | } |
||
1052 | |||
1053 | 1 | /** |
|
1054 | * Convert given input data to a list of RenditionData objects |
||
1055 | 1 | * |
|
1056 | 1 | * @param array|null $data |
|
1057 | 1 | * @return RenditionData[] |
|
1058 | 1 | */ |
|
1059 | 1 | View Code Duplication | public function convertRenditions(array $data = null) |
0 ignored issues
–
show
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. ![]() |
|||
1060 | 1 | { |
|
1061 | 1 | return array_filter( |
|
1062 | 1 | array_map( |
|
1063 | 1 | [$this, 'convertRendition'], |
|
1064 | 1 | array_filter( |
|
1065 | 1 | $data, |
|
1066 | 1 | 'is_array' |
|
1067 | 1 | ) |
|
1068 | 1 | ), |
|
1069 | 1 | function ($item) { |
|
1070 | 1 | // @TODO once a logger is available we should log an INFO message if the rendition could not be converted |
|
1071 | 1 | return !empty($item); |
|
1072 | } |
||
1073 | ); |
||
1074 | } |
||
1075 | |||
1076 | /** |
||
1077 | * Convert given input data to an Extension object |
||
1078 | 1 | * |
|
1079 | * @param array|null $data |
||
1080 | * @param string[] $cmisKeys |
||
1081 | * @return CmisExtensionElement[] |
||
1082 | */ |
||
1083 | public function convertExtension(array $data = null, array $cmisKeys = []) |
||
1084 | { |
||
1085 | $extensions = []; |
||
1086 | |||
1087 | foreach (array_diff_key((array) $data, array_flip($cmisKeys)) as $key => $value) { |
||
1088 | |||
1089 | if (!is_array($value)) { |
||
1090 | $value = (empty($value)) ? null : (string) $value; |
||
1091 | $extensions[] = new CmisExtensionElement(null, $key, [], $value); |
||
1092 | } else { |
||
1093 | $extension = $this->convertExtension($value, $cmisKeys); |
||
1094 | |||
1095 | if (!empty($extension)) { |
||
1096 | $extensions[] = new CmisExtensionElement( |
||
1097 | null, |
||
1098 | $key, |
||
1099 | [], |
||
1100 | null, |
||
1101 | $extension |
||
1102 | ); |
||
1103 | } |
||
1104 | } |
||
1105 | } |
||
1106 | |||
1107 | return $extensions; |
||
1108 | } |
||
1109 | |||
1110 | /** |
||
1111 | * Convert given input data to an ExtensionFeature object |
||
1112 | * |
||
1113 | * @param array|null $data |
||
1114 | * @return ExtensionFeature[] |
||
1115 | */ |
||
1116 | public function convertExtensionFeatures(array $data = null) |
||
1117 | { |
||
1118 | $features = []; |
||
1119 | $extendedFeatures = array_filter(array_filter((array) $data, 'is_array'), function ($item) { return !empty($item); }); |
||
1120 | |||
1121 | foreach ($extendedFeatures as $extendedFeature) { |
||
1122 | |||
1123 | 3 | $feature = new ExtensionFeature(); |
|
1124 | $feature->setId((string) $extendedFeature[JSONConstants::JSON_FEATURE_ID]); |
||
1125 | 3 | $feature->setUrl((string) $extendedFeature[JSONConstants::JSON_FEATURE_URL]); |
|
1126 | 1 | $feature->setCommonName((string) $extendedFeature[JSONConstants::JSON_FEATURE_COMMON_NAME]); |
|
1127 | $feature->setVersionLabel((string) $extendedFeature[JSONConstants::JSON_FEATURE_VERSION_LABEL]); |
||
1128 | 2 | $feature->setDescription((string) $extendedFeature[JSONConstants::JSON_FEATURE_DESCRIPTION]); |
|
1129 | |||
1130 | 2 | $featureData = []; |
|
1131 | 2 | foreach ($extendedFeature[JSONConstants::JSON_FEATURE_DATA] ?? [] as $key => $value) { |
|
1132 | 2 | $featureData[$key] = $value; |
|
1133 | 2 | } |
|
1134 | 2 | ||
1135 | 2 | $feature->setFeatureData($featureData); |
|
1136 | 2 | ||
1137 | 2 | $feature->setExtensions($this->convertExtension($extendedFeature, JSONConstants::getFeatureKeys())); |
|
1138 | 2 | ||
1139 | 2 | $features[] = $feature; |
|
1140 | 2 | } |
|
1141 | 2 | ||
1142 | 2 | return $features; |
|
1143 | 2 | } |
|
1144 | 2 | ||
1145 | 2 | /** |
|
1146 | 2 | * Converts a list of policy ids. |
|
1147 | 2 | * |
|
1148 | 2 | * @param array|null $data |
|
1149 | 2 | * @return PolicyIdList List of policy ids |
|
1150 | 2 | */ |
|
1151 | 2 | View Code Duplication | public function convertPolicyIdList(array $data = null) |
0 ignored issues
–
show
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. ![]() |
|||
1152 | 2 | { |
|
1153 | 2 | $policyIdsList = new PolicyIdList(); |
|
1154 | $policyIdsList->setPolicyIds( |
||
1155 | 2 | array_filter( |
|
1156 | array_filter( |
||
1157 | 2 | $data[JSONConstants::JSON_OBJECT_POLICY_IDS_IDS] ?? [], |
|
1158 | 'is_string' |
||
1159 | ), |
||
1160 | function ($item) { return !empty($item); } |
||
1161 | ) |
||
1162 | ); |
||
1163 | $policyIdsList->setExtensions($this->convertExtension($data, JSONConstants::getPolicyIdsKeys())); |
||
1164 | |||
1165 | return $policyIdsList; |
||
1166 | 4 | } |
|
1167 | |||
1168 | 4 | /** |
|
1169 | 1 | * Convert an acl object to a custom format |
|
1170 | * |
||
1171 | 3 | * @param AclInterface $acl |
|
1172 | * @return mixed |
||
1173 | 3 | */ |
|
1174 | 3 | public function convertFromAcl(AclInterface $acl) |
|
1175 | 3 | { |
|
1176 | 1 | // TODO: Implement convertFromAcl() method. |
|
1177 | 1 | } |
|
1178 | |||
1179 | /** |
||
1180 | 3 | * Convert an acl capabilities object to a custom format |
|
1181 | 1 | * |
|
1182 | 1 | * @param AclCapabilitiesInterface $aclCapabilities |
|
1183 | 3 | * @return mixed |
|
1184 | */ |
||
1185 | 3 | public function convertFromAclCapabilities(AclCapabilitiesInterface $aclCapabilities) |
|
1186 | { |
||
1187 | // TODO: Implement convertFromAclCapabilities() method. |
||
1188 | } |
||
1189 | |||
1190 | /** |
||
1191 | * Convert an allowable actions object to a custom format |
||
1192 | * |
||
1193 | * @param AllowableActionsInterface $allowableActions |
||
1194 | * @return mixed |
||
1195 | 31 | */ |
|
1196 | public function convertFromAllowableActions(AllowableActionsInterface $allowableActions) |
||
1197 | 31 | { |
|
1198 | 1 | // TODO: Implement convertFromAllowableActions() method. |
|
1199 | } |
||
1200 | |||
1201 | 30 | /** |
|
1202 | * Convert a repository info object to a custom format |
||
1203 | 30 | * |
|
1204 | 30 | * @param RepositoryInfoInterface $repositoryInfo |
|
1205 | 28 | * @return mixed |
|
1206 | */ |
||
1207 | public function convertFromRepositoryInfo(RepositoryInfoInterface $repositoryInfo) |
||
1208 | 11 | { |
|
1209 | 1 | // TODO: Implement convertFromRepositoryInfo() method. |
|
1210 | } |
||
1211 | 1 | ||
1212 | 1 | /** |
|
1213 | 1 | * Convert a repository capabilities object to a custom format |
|
1214 | 1 | * |
|
1215 | 1 | * @param RepositoryCapabilitiesInterface $repositoryCapabilities |
|
1216 | 1 | * @return mixed |
|
1217 | */ |
||
1218 | 1 | public function convertFromRepositoryCapabilities(RepositoryCapabilitiesInterface $repositoryCapabilities) |
|
1219 | 1 | { |
|
1220 | 1 | // TODO: Implement convertFromRepositoryCapabilities() method. |
|
1221 | 11 | } |
|
1222 | 11 | ||
1223 | /** |
||
1224 | 30 | * Convert a rendition data object to a custom format |
|
1225 | * |
||
1226 | 30 | * @param RenditionDataInterface $rendition |
|
1227 | * @return mixed |
||
1228 | */ |
||
1229 | public function convertFromRenditionData(RenditionDataInterface $rendition) |
||
1230 | { |
||
1231 | // TODO: Implement convertFromRenditionData() method. |
||
1232 | } |
||
1233 | |||
1234 | /** |
||
1235 | 1 | * Convert a object data object to a custom format |
|
1236 | * |
||
1237 | 1 | * @param ObjectDataInterface $objectData |
|
1238 | * @return mixed |
||
1239 | 1 | */ |
|
1240 | public function convertFromObjectData(ObjectDataInterface $objectData) |
||
1241 | { |
||
1242 | // TODO: Implement convertFromObjectData() method. |
||
1243 | 1 | } |
|
1244 | 1 | ||
1245 | 1 | /** |
|
1246 | * Convert a properties object to a custom format |
||
1247 | * |
||
1248 | 1 | * @param PropertiesInterface $properties |
|
1249 | 1 | * @return mixed |
|
1250 | 1 | */ |
|
1251 | 1 | public function convertFromProperties(PropertiesInterface $properties) |
|
1252 | 1 | { |
|
1253 | 1 | // TODO: Implement convertFromProperties() method. |
|
1254 | } |
||
1255 | 1 | ||
1256 | 1 | /** |
|
1257 | 1 | * Convert a property data object to a custom format |
|
1258 | 1 | * |
|
1259 | 1 | * @param PropertyDataInterface $propertyData |
|
1260 | 1 | * @return mixed |
|
1261 | 1 | */ |
|
1262 | public function convertFromPropertyData(PropertyDataInterface $propertyData) |
||
1263 | 1 | { |
|
1264 | 1 | // TODO: Implement convertFromPropertyData() method. |
|
1265 | } |
||
1266 | 1 | ||
1267 | /** |
||
1268 | 1 | * Convert a type definition object to a custom format |
|
1269 | 1 | * |
|
1270 | * @param TypeDefinitionInterface $typeDefinition |
||
1271 | 1 | * @return string JSON representation of the type definition |
|
1272 | */ |
||
1273 | public function convertFromTypeDefinition(TypeDefinitionInterface $typeDefinition) |
||
1274 | { |
||
1275 | $propertyList = [ |
||
1276 | 'baseTypeId' => JSONConstants::JSON_TYPE_BASE_ID, |
||
1277 | 'parentTypeId' => JSONConstants::JSON_TYPE_PARENT_ID |
||
1278 | ]; |
||
1279 | |||
1280 | 1 | if ($typeDefinition instanceof RelationshipTypeDefinitionInterface) { |
|
1281 | $propertyList['allowedTargetTypeIds'] = JSONConstants::JSON_TYPE_ALLOWED_TARGET_TYPES; |
||
1282 | 1 | $propertyList['allowedSourceTypeIds'] = JSONConstants::JSON_TYPE_ALLOWED_SOURCE_TYPES; |
|
1283 | 1 | } |
|
1284 | |||
1285 | 1 | $data = $typeDefinition->exportGettableProperties( |
|
1286 | 1 | $propertyList |
|
1287 | 1 | ); |
|
1288 | 1 | $data = $this->castArrayValuesToSimpleTypes($data); |
|
1289 | 1 | ||
1290 | 1 | return json_encode($data, JSON_FORCE_OBJECT); |
|
1291 | 1 | } |
|
1292 | |||
1293 | 1 | /** |
|
1294 | 1 | * Cast values of an array to simple types |
|
1295 | * |
||
1296 | 1 | * @param array $data |
|
1297 | * @return array |
||
1298 | */ |
||
1299 | protected function castArrayValuesToSimpleTypes(array $data) |
||
1300 | { |
||
1301 | foreach ($data as $key => $item) { |
||
1302 | if (is_array($item)) { |
||
1303 | $data[$key] = $this->castArrayValuesToSimpleTypes($item); |
||
1304 | } elseif (is_object($item)) { |
||
1305 | $data[$key] = $this->convertObjectToSimpleType($item); |
||
1306 | } |
||
1307 | } |
||
1308 | |||
1309 | return $data; |
||
1310 | } |
||
1311 | |||
1312 | /** |
||
1313 | * Convert an object to a simple type representation |
||
1314 | * |
||
1315 | * @param mixed $data |
||
1316 | * @return mixed |
||
1317 | * @throws CmisRuntimeException Exception is thrown if no type converter could be found to convert the given data |
||
1318 | * to a simple type |
||
1319 | */ |
||
1320 | protected function convertObjectToSimpleType($data) |
||
1321 | { |
||
1322 | /** @var null|TypeConverterInterface $converterClassName */ |
||
1323 | $converterClassName = null; |
||
1324 | if (class_exists($this->buildConverterClassName(get_class($data)))) { |
||
1325 | $converterClassName = $this->buildConverterClassName(get_class($data)); |
||
1326 | } else { |
||
1327 | $classInterfaces = class_implements($data); |
||
1328 | foreach ((array) $classInterfaces as $classInterface) { |
||
1329 | if (class_exists($this->buildConverterClassName($classInterface))) { |
||
1330 | $converterClassName = $this->buildConverterClassName($classInterface); |
||
1331 | break; |
||
1332 | } |
||
1333 | } |
||
1334 | if ($converterClassName === null) { |
||
1335 | $classParents = class_parents($data); |
||
1336 | foreach ((array) $classParents as $classParent) { |
||
1337 | if (class_exists($this->buildConverterClassName($classParent))) { |
||
1338 | $converterClassName = $this->buildConverterClassName($classParent); |
||
1339 | break; |
||
1340 | } |
||
1341 | } |
||
1342 | } |
||
1343 | } |
||
1344 | |||
1345 | if ($converterClassName === null) { |
||
1346 | throw new CmisRuntimeException( |
||
1347 | 'Could not find a converter that converts "' . get_class($data) . '" to a simple type.' |
||
1348 | ); |
||
1349 | } |
||
1350 | |||
1351 | return $converterClassName::convertToSimpleType($data); |
||
1352 | } |
||
1353 | |||
1354 | /** |
||
1355 | * Build a converter class name with namespace. |
||
1356 | * |
||
1357 | * The Dkd\PhpCmis namespace will be stripped. |
||
1358 | * |
||
1359 | * @param $className |
||
1360 | * @return string |
||
1361 | */ |
||
1362 | protected function buildConverterClassName($className) |
||
1363 | { |
||
1364 | $converterClassName = '\\Dkd\\PhpCmis\\Converter\\Types\\'; |
||
1365 | $converterClassName .= str_replace('Dkd\\PhpCmis\\', '', $className); |
||
1366 | $converterClassName .= 'Converter'; |
||
1367 | return $converterClassName; |
||
1368 | } |
||
1369 | |||
1370 | /** |
||
1371 | * Convert a property definition object to a custom format |
||
1372 | * |
||
1373 | * @param PropertyDefinitionInterface $propertyDefinition |
||
1374 | * @return mixed |
||
1375 | */ |
||
1376 | public function convertFromPropertyDefinition(PropertyDefinitionInterface $propertyDefinition) |
||
1377 | { |
||
1378 | // TODO: Implement convertFromPropertyDefinition() method. |
||
1379 | } |
||
1380 | |||
1381 | /** |
||
1382 | * Convert a type definition list object to a custom format |
||
1383 | * |
||
1384 | * @param TypeDefinitionListInterface $typeDefinitionList |
||
1385 | * @return mixed |
||
1386 | */ |
||
1387 | public function convertFromTypeDefinitionList(TypeDefinitionListInterface $typeDefinitionList) |
||
1388 | { |
||
1389 | // TODO: Implement convertFromTypeDefinitionList() method. |
||
1390 | } |
||
1391 | |||
1392 | /** |
||
1393 | * Convert a type definition container object to a custom format |
||
1394 | * |
||
1395 | * @param TypeDefinitionContainerInterface $typeDefinitionContainer |
||
1396 | * @return mixed |
||
1397 | */ |
||
1398 | public function convertFromTypeDefinitionContainer(TypeDefinitionContainerInterface $typeDefinitionContainer) |
||
1399 | { |
||
1400 | // TODO: Implement convertFromTypeDefinitionContainer() method. |
||
1401 | } |
||
1402 | |||
1403 | /** |
||
1404 | * Convert a object list object to a custom format |
||
1405 | * |
||
1406 | * @param ObjectListInterface $list |
||
1407 | * @return mixed |
||
1408 | */ |
||
1409 | public function convertFromObjectList(ObjectListInterface $list) |
||
1410 | { |
||
1411 | // TODO: Implement convertFromObjectList() method. |
||
1412 | } |
||
1413 | |||
1414 | /** |
||
1415 | * Convert a object in folder data object to a custom format |
||
1416 | * |
||
1417 | * @param ObjectInFolderDataInterface $objectInFolder |
||
1418 | * @return mixed |
||
1419 | */ |
||
1420 | public function convertFromObjectInFolderData(ObjectInFolderDataInterface $objectInFolder) |
||
1421 | { |
||
1422 | // TODO: Implement convertFromObjectInFolderData() method. |
||
1423 | } |
||
1424 | |||
1425 | /** |
||
1426 | * Convert a object in folder list object to a custom format |
||
1427 | * |
||
1428 | * @param ObjectInFolderListInterface $objectInFolder |
||
1429 | * @return mixed |
||
1430 | */ |
||
1431 | public function convertFromObjectInFolderList(ObjectInFolderListInterface $objectInFolder) |
||
1432 | { |
||
1433 | // TODO: Implement convertFromObjectInFolderList() method. |
||
1434 | } |
||
1435 | |||
1436 | /** |
||
1437 | * Convert a object in folder container object to a custom format |
||
1438 | * |
||
1439 | * @param ObjectInFolderContainerInterface $container |
||
1440 | * @return mixed |
||
1441 | */ |
||
1442 | public function convertFromObjectInFolderContainer(ObjectInFolderContainerInterface $container) |
||
1443 | { |
||
1444 | // TODO: Implement convertFromObjectInFolderContainer() method. |
||
1445 | } |
||
1446 | |||
1447 | /** |
||
1448 | * Convert a object in parent data object to a custom format |
||
1449 | * |
||
1450 | * @param ObjectParentDataInterface $container |
||
1451 | * @return mixed |
||
1452 | */ |
||
1453 | public function convertFromObjectParentData(ObjectParentDataInterface $container) |
||
1454 | { |
||
1455 | // TODO: Implement convertFromObjectParentData() method. |
||
1456 | } |
||
1457 | |||
1458 | /** |
||
1459 | * Convert an extension feature object to a custom format |
||
1460 | * |
||
1461 | * @param ExtensionFeatureInterface $extensionFeature |
||
1462 | * @return mixed |
||
1463 | */ |
||
1464 | public function convertFromExtensionFeature(ExtensionFeatureInterface $extensionFeature) |
||
1465 | { |
||
1466 | // TODO: Implement convertFromExtensionFeature() method. |
||
1467 | } |
||
1468 | |||
1469 | /** |
||
1470 | * Convert given input data to a TypeChildren object |
||
1471 | * |
||
1472 | * @param array|null $data |
||
1473 | * @return TypeDefinitionListInterface|null Returns a TypeDefinitionListInterface object or <code>null</code> |
||
1474 | * if empty data is given. |
||
1475 | */ |
||
1476 | public function convertTypeChildren(array $data = null) |
||
1477 | { |
||
1478 | if (empty($data)) { |
||
1479 | return null; |
||
1480 | } |
||
1481 | |||
1482 | $result = new TypeDefinitionList(); |
||
1483 | $types = []; |
||
1484 | |||
1485 | $typesList = $data[JSONConstants::JSON_TYPESLIST_TYPES] ?? []; |
||
1486 | |||
1487 | foreach (array_filter($typesList, 'is_array') as $typeData) { |
||
1488 | $type = $this->convertTypeDefinition($typeData); |
||
1489 | if ($type !== null) { |
||
1490 | $types[] = $type; |
||
1491 | } |
||
1492 | } |
||
1493 | |||
1494 | $result->setList($types); |
||
1495 | $result->setHasMoreItems((boolean) ($data[JSONConstants::JSON_TYPESLIST_HAS_MORE_ITEMS] ?? false)); |
||
1496 | $result->setNumItems($data[JSONConstants::JSON_TYPESLIST_NUM_ITEMS] ?? 0); |
||
1497 | $result->setExtensions($this->convertExtension($data, JSONConstants::getTypesListKeys())); |
||
1498 | |||
1499 | return $result; |
||
1500 | } |
||
1501 | |||
1502 | /** |
||
1503 | * Convert given input data to a TypeDescendants object |
||
1504 | * |
||
1505 | * @param array|null $data |
||
1506 | * @return TypeDefinitionContainerInterface[] Returns an array of TypeDefinitionContainerInterface objects |
||
1507 | */ |
||
1508 | public function convertTypeDescendants(array $data = null) |
||
1509 | { |
||
1510 | $result = []; |
||
1511 | |||
1512 | if (empty($data)) { |
||
1513 | return $result; |
||
1514 | } |
||
1515 | |||
1516 | foreach (array_filter($data, 'is_array') as $itemData) { |
||
1517 | |||
1518 | $container = new TypeDefinitionContainer(); |
||
1519 | |||
1520 | $typeDefinition = $this->convertTypeDefinition($itemData[JSONConstants::JSON_TYPESCONTAINER_TYPE] ?? []); |
||
1521 | if ($typeDefinition !== null) { |
||
1522 | $container->setTypeDefinition($typeDefinition); |
||
1523 | } |
||
1524 | |||
1525 | $container->setChildren( |
||
1526 | $this->convertTypeDescendants($itemData[JSONConstants::JSON_TYPESCONTAINER_CHILDREN] ?? []) |
||
1527 | ); |
||
1528 | |||
1529 | $container->setExtensions($this->convertExtension($data, JSONConstants::getTypesContainerKeys())); |
||
1530 | |||
1531 | $result[] = $container; |
||
1532 | } |
||
1533 | |||
1534 | return $result; |
||
1535 | } |
||
1536 | |||
1537 | /** |
||
1538 | * Convert given input data to a ObjectInFolderList object |
||
1539 | * |
||
1540 | * @param array|null $data |
||
1541 | * @return null|ObjectInFolderList |
||
1542 | */ |
||
1543 | public function convertObjectInFolderList(array $data = null) |
||
1544 | { |
||
1545 | if (empty($data)) { |
||
1546 | return null; |
||
1547 | } |
||
1548 | $objects = array_filter( |
||
1549 | array_map( |
||
1550 | [$this, 'convertObjectInFolder'], |
||
1551 | $data[JSONConstants::JSON_OBJECTINFOLDERLIST_OBJECTS] ?? [] |
||
1552 | ), |
||
1553 | function ($item) { return !empty($item); } |
||
1554 | ); |
||
1555 | $objectInFolderList = new ObjectInFolderList(); |
||
1556 | $objectInFolderList->setObjects($objects); |
||
1557 | $objectInFolderList->setHasMoreItems((boolean) ($data[JSONConstants::JSON_OBJECTINFOLDERLIST_HAS_MORE_ITEMS] ?? false)); |
||
1558 | $objectInFolderList->setNumItems((integer)($data[JSONConstants::JSON_OBJECTINFOLDERLIST_NUM_ITEMS] ?? count($objects))); |
||
1559 | $objectInFolderList->setExtensions($this->convertExtension($data, JSONConstants::getObjectInFolderListKeys())); |
||
1560 | |||
1561 | return $objectInFolderList; |
||
1562 | } |
||
1563 | |||
1564 | /** |
||
1565 | * Convert given input data to a ObjectInFolderData object |
||
1566 | * |
||
1567 | * @param array|null $data |
||
1568 | * @return ObjectInFolderData|null |
||
1569 | */ |
||
1570 | View Code Duplication | public function convertObjectInFolder(array $data = null) |
|
0 ignored issues
–
show
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. ![]() |
|||
1571 | { |
||
1572 | if (empty($data)) { |
||
1573 | return null; |
||
1574 | } |
||
1575 | |||
1576 | $objectInFolderData = new ObjectInFolderData(); |
||
1577 | $object = $this->convertObject($data[JSONConstants::JSON_OBJECTINFOLDER_OBJECT] ?? []); |
||
1578 | |||
1579 | if ($object !== null) { |
||
1580 | $objectInFolderData->setObject($object); |
||
1581 | } |
||
1582 | |||
1583 | $objectInFolderData->setPathSegment((string) $data[JSONConstants::JSON_OBJECTINFOLDER_PATH_SEGMENT] ?? null); |
||
1584 | $objectInFolderData->setExtensions($this->convertExtension($data, JSONConstants::getObjectInFolderKeys())); |
||
1585 | |||
1586 | return $objectInFolderData; |
||
1587 | } |
||
1588 | |||
1589 | /** |
||
1590 | * Convert given input data to a list of ObjectParentData objects |
||
1591 | * |
||
1592 | * @param array|null $data |
||
1593 | * @return ObjectParentData[] |
||
1594 | */ |
||
1595 | View Code Duplication | public function convertObjectParents(array $data = null) |
|
0 ignored issues
–
show
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. ![]() |
|||
1596 | { |
||
1597 | return array_filter( |
||
1598 | array_map( |
||
1599 | [$this, 'convertObjectParentData'], |
||
1600 | (array) ($data ?? []) |
||
1601 | ), |
||
1602 | function ($item) { |
||
1603 | return !empty($item); |
||
1604 | // @TODO once a logger is available we should log an INFO message if the parent data could not be converted |
||
1605 | } |
||
1606 | ); |
||
1607 | } |
||
1608 | |||
1609 | /** |
||
1610 | * Convert given input data to a ObjectParentData object |
||
1611 | * |
||
1612 | * @param array|null $data |
||
1613 | * @return null|ObjectParentData |
||
1614 | */ |
||
1615 | View Code Duplication | public function convertObjectParentData(array $data = null) |
|
0 ignored issues
–
show
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. ![]() |
|||
1616 | { |
||
1617 | if (empty($data)) { |
||
1618 | return null; |
||
1619 | } |
||
1620 | $parent = new ObjectParentData(); |
||
1621 | |||
1622 | $object = $this->convertObject($data[JSONConstants::JSON_OBJECTPARENTS_OBJECT] ?? null); |
||
1623 | if ($object !== null) { |
||
1624 | $parent->setObject($object); |
||
1625 | } |
||
1626 | |||
1627 | $parent->setRelativePathSegment((string) ($data[JSONConstants::JSON_OBJECTPARENTS_RELATIVE_PATH_SEGMENT] ?? '')); |
||
1628 | $parent->setExtensions($this->convertExtension($data, JSONConstants::getObjectParentsKeys())); |
||
1629 | |||
1630 | return $parent; |
||
1631 | } |
||
1632 | |||
1633 | /** |
||
1634 | * Convert given input data array to a ObjectList object |
||
1635 | * |
||
1636 | * @param array|null $data |
||
1637 | * @return null|ObjectList |
||
1638 | */ |
||
1639 | View Code Duplication | public function convertObjectList(array $data = null) |
|
0 ignored issues
–
show
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. ![]() |
|||
1640 | { |
||
1641 | if (empty($data)) { |
||
1642 | return null; |
||
1643 | } |
||
1644 | |||
1645 | $objectList = new ObjectList(); |
||
1646 | $objects = []; |
||
1647 | |||
1648 | foreach ((array) ($data[JSONConstants::JSON_OBJECTLIST_OBJECTS] ?? []) as $objectData) { |
||
1649 | $object = $this->convertObject($objectData); |
||
1650 | |||
1651 | if ($object !== null) { |
||
1652 | $objects[] = $object; |
||
1653 | } |
||
1654 | } |
||
1655 | |||
1656 | $objectList->setObjects($objects); |
||
1657 | |||
1658 | $objectList->setHasMoreItems( |
||
1659 | (boolean) ($data[JSONConstants::JSON_OBJECTLIST_HAS_MORE_ITEMS] ?? false) |
||
1660 | ); |
||
1661 | |||
1662 | if (isset($data[JSONConstants::JSON_OBJECTLIST_NUM_ITEMS])) { |
||
1663 | $objectList->setNumItems((integer) $data[JSONConstants::JSON_OBJECTLIST_NUM_ITEMS]); |
||
1664 | } |
||
1665 | |||
1666 | $objectList->setExtensions($this->convertExtension($data, JSONConstants::getObjectListKeys())); |
||
1667 | |||
1668 | return $objectList; |
||
1669 | } |
||
1670 | |||
1671 | /** |
||
1672 | * Convert given input data array from query result to a ObjectList object |
||
1673 | * |
||
1674 | * @param array|null $data |
||
1675 | * @return null|ObjectList |
||
1676 | */ |
||
1677 | View Code Duplication | public function convertQueryResultList(array $data = null) |
|
0 ignored issues
–
show
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. ![]() |
|||
1678 | { |
||
1679 | if (empty($data)) { |
||
1680 | return null; |
||
1681 | } |
||
1682 | |||
1683 | $objectList = new ObjectList(); |
||
1684 | $objects = []; |
||
1685 | |||
1686 | foreach ((array) ($data[JSONConstants::JSON_QUERYRESULTLIST_RESULTS] ?? []) as $objectData) { |
||
1687 | $object = $this->convertObject($objectData); |
||
1688 | |||
1689 | if ($object !== null) { |
||
1690 | $objects[] = $object; |
||
1691 | } |
||
1692 | } |
||
1693 | 1 | ||
1694 | $objectList->setObjects($objects); |
||
1695 | 1 | $objectList->setHasMoreItems((boolean) ($data[JSONConstants::JSON_QUERYRESULTLIST_HAS_MORE_ITEMS] ?? false)); |
|
1696 | |||
1697 | if (isset($data[JSONConstants::JSON_QUERYRESULTLIST_NUM_ITEMS])) { |
||
1698 | $objectList->setNumItems((integer) $data[JSONConstants::JSON_QUERYRESULTLIST_NUM_ITEMS]); |
||
1699 | 1 | } |
|
1700 | 1 | ||
1701 | $objectList->setExtensions($this->convertExtension($data, JSONConstants::getQueryResultListKeys())); |
||
1702 | 1 | ||
1703 | 1 | return $objectList; |
|
1704 | 1 | } |
|
1705 | 1 | ||
1706 | /** |
||
1707 | 1 | * Convert given input data array to a ObjectList object |
|
1708 | 1 | * |
|
1709 | 1 | * @param array|null $data |
|
1710 | 1 | * @return ObjectInFolderContainer[] |
|
1711 | 1 | */ |
|
1712 | 1 | public function convertDescendants(array $data = null) |
|
1713 | { |
||
1714 | 1 | return array_filter( |
|
1715 | array_map( |
||
1716 | 1 | [$this, 'convertDescendant'], |
|
1717 | 1 | $data ?? [] |
|
1718 | 1 | ), |
|
1719 | 1 | function ($item) { return !empty($item); } |
|
1720 | 1 | ); |
|
1721 | } |
||
1722 | 1 | ||
1723 | 1 | /** |
|
1724 | 1 | * Convert given input data array to a ObjectInFolderContainer object |
|
1725 | * |
||
1726 | 1 | * @param array|null $data |
|
1727 | * @return null|ObjectInFolderContainer |
||
1728 | 1 | * @throws CmisRuntimeException |
|
1729 | */ |
||
1730 | public function convertDescendant(array $data = null) |
||
1731 | { |
||
1732 | if (empty($data)) { |
||
1733 | return null; |
||
1734 | } |
||
1735 | |||
1736 | $object = $this->convertObjectInFolder($data[JSONConstants::JSON_OBJECTINFOLDERCONTAINER_OBJECT] ?? null); |
||
1737 | 2 | ||
1738 | if ($object === null) { |
||
1739 | 2 | throw new CmisRuntimeException('Given data could not be converted to ObjectInFolder!'); |
|
1740 | } |
||
1741 | |||
1742 | $objectInFolderContainer = new ObjectInFolderContainer($object); |
||
1743 | 2 | ||
1744 | $objectInFolderContainer->setChildren( |
||
1745 | 2 | array_filter( |
|
1746 | 2 | array_map( |
|
1747 | [$this, 'convertDescendant'], |
||
1748 | 2 | (array) ($data[JSONConstants::JSON_OBJECTINFOLDERCONTAINER_CHILDREN] ?? []) |
|
1749 | 2 | ), |
|
1750 | 2 | function ($item) { return !empty($item); } |
|
1751 | 2 | ) |
|
1752 | ); |
||
1753 | 2 | ||
1754 | 2 | $objectInFolderContainer->setExtensions( |
|
1755 | 2 | $this->convertExtension($data, JSONConstants::getObjectInFolderContainerKeys()) |
|
1756 | ); |
||
1757 | 2 | ||
1758 | return $objectInFolderContainer; |
||
1759 | 2 | } |
|
1760 | |||
1761 | /** |
||
1762 | * Converts FailedToDelete ids. |
||
1763 | * |
||
1764 | * @param array|null $data |
||
1765 | * @return FailedToDeleteData |
||
1766 | */ |
||
1767 | View Code Duplication | public function convertFailedToDelete(array $data = null) |
|
0 ignored issues
–
show
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. ![]() |
|||
1768 | 1 | { |
|
1769 | $result = new FailedToDeleteData(); |
||
1770 | 1 | ||
1771 | if (empty($data)) { |
||
1772 | return $result; |
||
1773 | 1 | } |
|
1774 | |||
1775 | 1 | $result->setIds(array_map('strval', $data[JSONConstants::JSON_FAILEDTODELETE_ID] ?? [])); |
|
1776 | 1 | $result->setExtensions($this->convertExtension($data, JSONConstants::getFailedToDeleteKeys())); |
|
1777 | |||
1778 | return $result; |
||
1779 | 1 | } |
|
1780 | 1 | ||
1781 | 1 | /** |
|
1782 | 1 | * @return BindingsObjectFactory |
|
1783 | * @codeCoverageIgnore |
||
1784 | 1 | */ |
|
1785 | protected function getBindingsObjectFactory() |
||
1786 | { |
||
1787 | return new BindingsObjectFactory(); |
||
1788 | } |
||
1789 | } |
||
1790 |
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:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.