GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 569a73...1219b2 )
by
unknown
07:18
created

ObjectService::createDocumentFromSource()   C

Complexity

Conditions 7
Paths 32

Size

Total Lines 49
Code Lines 36

Duplication

Lines 19
Ratio 38.78 %

Code Coverage

Tests 29
CRAP Score 7.0131

Importance

Changes 3
Bugs 0 Features 2
Metric Value
c 3
b 0
f 2
dl 19
loc 49
ccs 29
cts 31
cp 0.9355
rs 6.7272
cc 7
eloc 36
nc 32
nop 9
crap 7.0131

How to fix   Many Parameters   

Many Parameters

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

There are several approaches to avoid long parameter lists:

1
<?php
2
namespace Dkd\PhpCmis\Bindings\Browser;
3
4
/**
5
 * This file is part of php-cmis-lib.
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\PhpCmis\Constants;
14
use Dkd\PhpCmis\Data\AclInterface;
15
use Dkd\PhpCmis\Data\AllowableActionsInterface;
16
use Dkd\PhpCmis\Data\BulkUpdateObjectIdAndChangeTokenInterface;
17
use Dkd\PhpCmis\Data\ExtensionDataInterface;
18
use Dkd\PhpCmis\Data\FailedToDeleteDataInterface;
19
use Dkd\PhpCmis\Data\ObjectDataInterface;
20
use Dkd\PhpCmis\Data\PropertiesInterface;
21
use Dkd\PhpCmis\Data\RenditionDataInterface;
22
use Dkd\PhpCmis\Enum\IncludeRelationships;
23
use Dkd\PhpCmis\Enum\UnfileObject;
24
use Dkd\PhpCmis\Enum\VersioningState;
25
use Dkd\PhpCmis\Exception\CmisInvalidArgumentException;
26
use Dkd\PhpCmis\ObjectServiceInterface;
27
use Dkd\PhpCmis\PropertyIds;
28
use Dkd\PhpCmis\SessionParameter;
29
use GuzzleHttp\Post\PostFile;
30
use GuzzleHttp\Stream\LimitStream;
31
use GuzzleHttp\Message\Response;
32
use GuzzleHttp\Stream\StreamInterface;
33
34
/**
35
 * Object Service Browser Binding client.
36
 */
37
class ObjectService extends AbstractBrowserBindingService implements ObjectServiceInterface
38
{
39
    /**
40
     * Appends the content stream to the content of the document.
41
     *
42
     * The stream in contentStream is consumed but not closed by this method.
43
     *
44
     * @param string $repositoryId the identifier for the repository
45
     * @param string $objectId The identifier for the object. The repository might return a different/new object id
46
     * @param StreamInterface $contentStream The content stream to append
47
     * @param boolean $isLastChunk Indicates if this content stream is the last chunk
48
     * @param string|null $changeToken The last change token of this object that the client received.
49
     *      The repository might return a new change token (default is <code>null</code>)
50
     * @param ExtensionDataInterface|null $extension
51
     */
52
    public function appendContentStream(
53
        $repositoryId,
54
        & $objectId,
55
        StreamInterface $contentStream,
56
        $isLastChunk,
57
        & $changeToken = null,
58
        ExtensionDataInterface $extension = null
59
    ) {
60
        // TODO: Implement appendContentStream() method.
61
    }
62
63
    /**
64
     * Updates properties and secondary types of one or more objects.
65
     *
66
     * @param string $repositoryId the identifier for the repository
67
     * @param BulkUpdateObjectIdAndChangeTokenInterface[] $objectIdsAndChangeTokens
68
     * @param PropertiesInterface $properties
69
     * @param string[] $addSecondaryTypeIds the secondary types to apply
70
     * @param string[] $removeSecondaryTypeIds the secondary types to remove
71
     * @param ExtensionDataInterface|null $extension
72
     * @return BulkUpdateObjectIdAndChangeTokenInterface[]
73
     */
74
    public function bulkUpdateProperties(
75
        $repositoryId,
76
        array $objectIdsAndChangeTokens,
77
        PropertiesInterface $properties,
78
        array $addSecondaryTypeIds,
79
        array $removeSecondaryTypeIds,
80
        ExtensionDataInterface $extension = null
81
    ) {
82
        // TODO: Implement bulkUpdateProperties() method.
83
    }
84
85
    /**
86
     * Creates a document object of the specified type (given by the cmis:objectTypeId property)
87
     * in the (optionally) specified location.
88
     *
89
     * @param string $repositoryId the identifier for the repository
90
     * @param PropertiesInterface $properties the property values that must be applied to the newly
91
     *      created document object
92
     * @param string|null $folderId if specified, the identifier for the folder that must be the parent
93
     *      folder for the newly created document object
94
     * @param StreamInterface|null $contentStream the content stream that must be stored for the newly
95
     *      created document object
96
     * @param VersioningState|null $versioningState specifies what the versioning state of the newly created object
97
     *      must be (default is <code>VersioningState::MAJOR</code>)
98
     * @param string[] $policies a list of policy IDs that must be applied to the newly created document object
99
     * @param AclInterface|null $addAces a list of ACEs that must be added to the newly created document object,
100
     *      either using the ACL from folderId if specified, or being applied if no folderId is specified
101
     * @param AclInterface|null $removeAces a list of ACEs that must be removed from the newly created document object,
102
     *      either using the ACL from folderId if specified, or being ignored if no folderId is specified
103
     * @param ExtensionDataInterface|null $extension
104
     * @return string|null Returns the new object id or <code>null</code> if the repository sent an empty
105
     *      result (which should not happen)
106
     */
107 3
    public function createDocument(
108
        $repositoryId,
109
        PropertiesInterface $properties,
110
        $folderId = null,
111
        StreamInterface $contentStream = null,
112
        VersioningState $versioningState = null,
113
        array $policies = array(),
114
        AclInterface $addAces = null,
115
        AclInterface $removeAces = null,
116
        ExtensionDataInterface $extension = null
117
    ) {
118 3 View Code Duplication
        if ($folderId === null) {
119 1
            $url = $this->getRepositoryUrl($repositoryId);
120 1
        } else {
121 2
            $url = $this->getObjectUrl($repositoryId, $folderId);
122
        }
123
124
        // Guzzle gets the mime type for a file by the filename extension. Sometimes the filename does not contain
125
        // the correct filename extension for example when a file is uploaded in php it gets a temporary name without
126
        // a file extension. If the filename does not contain a file extension we use the given 'cmis:name' property
127
        // as filename. See also https://github.com/guzzle/guzzle/issues/571
128 3
        if ($contentStream !== null && pathinfo($contentStream->getMetadata('uri'), PATHINFO_EXTENSION) === '') {
129 1
            $contentStream = new PostFile(
130 1
                'content',
131 1
                $contentStream,
132 1
                $properties->getProperties()['cmis:name']->getFirstValue()
133 1
            );
134 1
        }
135
136 3
        $queryArray = array_replace(
137
			array(
138 3
				Constants::CONTROL_CMISACTION => Constants::CMISACTION_CREATE_DOCUMENT,
139 3
				Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false',
140
				'content' => $contentStream
141 3
			),
142 3
			$this->convertPropertiesToQueryArray($properties),
143 3
			$this->convertPolicyIdArrayToQueryArray($policies)
144 3
		);
145 3 View Code Duplication
		if (!empty($removeAces)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
146 2
			$queryArray = array_replace($queryArray, $this->convertAclToQueryArray(
147 2
				$removeAces,
148 2
				Constants::CONTROL_REMOVE_ACE_PRINCIPAL,
149
				Constants::CONTROL_REMOVE_ACE_PERMISSION
150 2
			));
151 2
		}
152 3 View Code Duplication
		if (!empty($addAces)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
153 2
			$queryArray = array_replace($queryArray, $this->convertAclToQueryArray(
154 2
				$addAces,
155 2
				Constants::CONTROL_ADD_ACE_PRINCIPAL,
156
				Constants::CONTROL_ADD_ACE_PERMISSION
157 2
			));
158 2
		}
159 3
        if ($versioningState !== null) {
160 2
            $queryArray[Constants::PARAM_VERSIONING_STATE] = (string) $versioningState;
161 2
        }
162 3
        $responseData = $this->post(
163 3
            $url,
164
            $queryArray
165 3
        )->json();
166
167 3
        $newObject = $this->getJsonConverter()->convertObject($responseData);
168
169 3
        return ($newObject === null) ? null : $newObject->getId();
170
    }
171
172
    /**
173
     * Creates a document object as a copy of the given source document in the (optionally) specified location.
174
     *
175
     * @param string $repositoryId the identifier for the repository
176
     * @param string $sourceId the identifier for the source document
177
     * @param PropertiesInterface $properties the property values that must be applied to the newly
178
     *      created document object
179
     * @param string|null $folderId if specified, the identifier for the folder that must be the parent folder for the
180
     *      newly created document object
181
     * @param VersioningState|null $versioningState specifies what the versioning state of the newly created object
182
     *      must be (default is <code>VersioningState::MAJOR</code>)
183
     * @param string[] $policies a list of policy IDs that must be applied to the newly created document object
184
     * @param AclInterface|null $addAces a list of ACEs that must be added to the newly created document object,
185
     *      either using the ACL from folderId if specified, or being applied if no folderId is specified
186
     * @param AclInterface|null $removeAces a list of ACEs that must be removed from the newly created document object,
187
     *      either using the ACL from folderId if specified, or being ignored if no folderId is specified
188
     * @param ExtensionDataInterface|null $extension
189
     * @return string|null Returns the new object id or <code>null</code> if the repository sent an empty
190
     *      result (which should not happen)
191
     */
192 2
    public function createDocumentFromSource(
193
        $repositoryId,
194
        $sourceId,
195
        PropertiesInterface $properties,
196
        $folderId = null,
197
        VersioningState $versioningState = null,
198
        array $policies = array(),
199
        AclInterface $addAces = null,
200
        AclInterface $removeAces = null,
201
        ExtensionDataInterface $extension = null
202
    ) {
203 2 View Code Duplication
        if ($folderId === null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
204
            $url = $this->getRepositoryUrl($repositoryId);
205
        } else {
206 2
            $url = $this->getObjectUrl($repositoryId, $folderId);
207
        }
208
209 2
		$queryArray = array_replace(
210
			array(
211 2
				Constants::CONTROL_CMISACTION => Constants::CMISACTION_CREATE_DOCUMENT_FROM_SOURCE,
212 2
				Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false',
213 2
                Constants::PARAM_SOURCE_ID => (string) $sourceId
214 2
			),
215 2
			$this->convertPropertiesToQueryArray($properties),
216 2
			$this->convertPolicyIdArrayToQueryArray($policies)
217 2
		);
218 2 View Code Duplication
		if (!empty($removeAces)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
219 1
			$queryArray = array_replace($queryArray, $this->convertAclToQueryArray(
220 1
				$removeAces,
221 1
				Constants::CONTROL_REMOVE_ACE_PRINCIPAL,
222
				Constants::CONTROL_REMOVE_ACE_PERMISSION
223 1
			));
224 1
		}
225 2 View Code Duplication
		if (!empty($addAces)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
226 1
			$queryArray = array_replace($queryArray, $this->convertAclToQueryArray(
227 1
				$addAces,
228 1
				Constants::CONTROL_ADD_ACE_PRINCIPAL,
229
				Constants::CONTROL_ADD_ACE_PERMISSION
230 1
			));
231 1
		}
232 2
		if ($versioningState !== null) {
233 1
			$queryArray[Constants::PARAM_VERSIONING_STATE] = (string) $versioningState;
234 1
		}
235 2
        $responseData = $this->post($url, $queryArray)->json();
236
237 2
        $newObject = $this->getJsonConverter()->convertObject($responseData);
238
239 2
        return ($newObject === null) ? null : $newObject->getId();
240
    }
241
242
    /**
243
     * Creates a folder object of the specified type (given by the cmis:objectTypeId property) in
244
     * the specified location.
245
     *
246
     * @param string $repositoryId the identifier for the repository
247
     * @param PropertiesInterface $properties the property values that must be applied to the newly
248
     *      created document object
249
     * @param string $folderId if specified, the identifier for the folder that must be the parent folder for the
250
     *      newly created document object
251
     * @param string[] $policies a list of policy IDs that must be applied to the newly created document object
252
     * @param AclInterface|null $addAces a list of ACEs that must be added to the newly created document object,
253
     *      either using the ACL from folderId if specified, or being applied if no folderId is specified
254
     * @param AclInterface|null $removeAces a list of ACEs that must be removed from the newly created document object,
255
     *      either using the ACL from folderId if specified, or being ignored if no folderId is specified
256
     * @param ExtensionDataInterface|null $extension
257
     * @return string|null Returns the new object id or <code>null</code> if the repository sent an empty
258
     *      result (which should not happen)
259
     */
260 2 View Code Duplication
    public function createFolder(
261
        $repositoryId,
262
        PropertiesInterface $properties,
263
        $folderId,
264
        array $policies = array(),
265
        AclInterface $addAces = null,
266
        AclInterface $removeAces = null,
267
        ExtensionDataInterface $extension = null
268
    ) {
269 2
        $url = $this->getObjectUrl($repositoryId, $folderId);
270 2
        $url->getQuery()->modify(
271
            array(
272 2
                Constants::CONTROL_CMISACTION => Constants::CMISACTION_CREATE_FOLDER,
273 2
                Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false'
274 2
            )
275 2
        );
276
277 2
        $url->getQuery()->modify($this->convertPropertiesToQueryArray($properties));
278
279 2
        $this->appendPoliciesToUrl($url, $policies);
280 2
        $this->appendAddAcesToUrl($url, $addAces);
281 2
        $this->appendRemoveAcesToUrl($url, $removeAces);
282
283 2
        $responseData = $this->post($url)->json();
284
285 2
        $newObject = $this->getJsonConverter()->convertObject($responseData);
286
287 2
        return ($newObject === null) ? null : $newObject->getId();
288
    }
289
290
    /**
291
     * Creates an item object of the specified type (given by the cmis:objectTypeId property).
292
     *
293
     * @param string $repositoryId The identifier for the repository
294
     * @param PropertiesInterface $properties The property values that must be applied to the newly
295
     *      created document object
296
     * @param string|null $folderId If specified, the identifier for the folder that must be the parent folder for the
297
     *      newly created document object
298
     * @param string[] $policies A list of policy IDs that must be applied to the newly created document object
299
     * @param AclInterface|null $addAces A list of ACEs that must be added to the newly created document object,
300
     *      either using the ACL from folderId if specified, or being applied if no folderId is specified
301
     * @param AclInterface|null $removeAces A list of ACEs that must be removed from the newly created document object,
302
     *      either using the ACL from folderId if specified, or being ignored if no folderId is specified
303
     * @param ExtensionDataInterface|null $extension
304
     * @return string|null Returns the new item id or <code>null</code> if the repository sent an empty
305
     *      result (which should not happen)
306
     */
307 2
    public function createItem(
308
        $repositoryId,
309
        PropertiesInterface $properties,
310
        $folderId = null,
311
        array $policies = array(),
312
        AclInterface $addAces = null,
313
        AclInterface $removeAces = null,
314
        ExtensionDataInterface $extension = null
315
    ) {
316 2 View Code Duplication
        if ($folderId === null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
317
            $url = $this->getRepositoryUrl($repositoryId);
318
        } else {
319 2
            $url = $this->getObjectUrl($repositoryId, $folderId);
320
        }
321
322 2
        $url->getQuery()->modify(
323
            array(
324 2
                Constants::CONTROL_CMISACTION => Constants::CMISACTION_CREATE_ITEM,
325 2
                Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false'
326 2
            )
327 2
        );
328
329 2
        $url->getQuery()->modify($this->convertPropertiesToQueryArray($properties));
330
331 2
        $this->appendPoliciesToUrl($url, $policies);
332 2
        $this->appendAddAcesToUrl($url, $addAces);
333 2
        $this->appendRemoveAcesToUrl($url, $removeAces);
334
335 2
        $responseData = $this->post($url)->json();
336
337 2
        $newObject = $this->getJsonConverter()->convertObject($responseData);
338
339 2
        return ($newObject === null) ? null : $newObject->getId();
340
    }
341
342
    /**
343
     * Creates a policy object of the specified type (given by the cmis:objectTypeId property).
344
     *
345
     * @param string $repositoryId The identifier for the repository
346
     * @param PropertiesInterface $properties The property values that must be applied to the newly
347
     *      created document object
348
     * @param string|null $folderId If specified, the identifier for the folder that must be the parent folder for the
349
     *      newly created document object
350
     * @param string[] $policies A list of policy IDs that must be applied to the newly created document object
351
     * @param AclInterface|null $addAces A list of ACEs that must be added to the newly created document object,
352
     *      either using the ACL from folderId if specified, or being applied if no folderId is specified
353
     * @param AclInterface|null $removeAces A list of ACEs that must be removed from the newly created document object,
354
     *      either using the ACL from folderId if specified, or being ignored if no folderId is specified
355
     * @param ExtensionDataInterface|null $extension
356
     * @return string The id of the newly-created policy.
357
     */
358
    public function createPolicy(
359
        $repositoryId,
360
        PropertiesInterface $properties,
361
        $folderId = null,
362
        array $policies = array(),
363
        AclInterface $addAces = null,
364
        AclInterface $removeAces = null,
365
        ExtensionDataInterface $extension = null
366
    ) {
367
        // TODO: Implement createPolicy() method.
368
    }
369
370
    /**
371
     * Creates a relationship object of the specified type (given by the cmis:objectTypeId property).
372
     *
373
     * @param string $repositoryId the identifier for the repository
374
     * @param PropertiesInterface $properties the property values that must be applied to the newly
375
     *      created document object
376
     * @param string[] $policies a list of policy IDs that must be applied to the newly created document object
377
     * @param AclInterface|null $addAces a list of ACEs that must be added to the newly created document object,
378
     *      either using the ACL from folderId if specified, or being applied if no folderId is specified
379
     * @param AclInterface|null $removeAces a list of ACEs that must be removed from the newly created document object,
380
     *      either using the ACL from folderId if specified, or being ignored if no folderId is specified
381
     * @param ExtensionDataInterface|null $extension
382
     * @return string|null Returns the new item id of the relationship object or <code>null</code> if the repository
383
     *      sent an empty result (which should not happen)
384
     */
385 View Code Duplication
    public function createRelationship(
386
        $repositoryId,
387
        PropertiesInterface $properties,
388
        array $policies = array(),
389
        AclInterface $addAces = null,
390
        AclInterface $removeAces = null,
391
        ExtensionDataInterface $extension = null
392
    ) {
393
        $url = $this->getRepositoryUrl($repositoryId);
394
395
        $url->getQuery()->modify(
396
            array(
397
                Constants::CONTROL_CMISACTION => Constants::CMISACTION_CREATE_RELATIONSHIP,
398
                Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false'
399
            )
400
        );
401
402
        $url->getQuery()->modify($this->convertPropertiesToQueryArray($properties));
403
        $this->appendPoliciesToUrl($url, $policies);
404
        $this->appendAddAcesToUrl($url, $addAces);
405
        $this->appendRemoveAcesToUrl($url, $removeAces);
406
407
        $responseData = $this->post($url)->json();
408
409
        $newObject = $this->getJsonConverter()->convertObject($responseData);
410
411
        return ($newObject === null) ? null : $newObject->getId();
412
    }
413
414
    /**
415
     * Deletes the content stream for the specified document object.
416
     *
417
     * @param string $repositoryId the identifier for the repository
418
     * @param string $objectId the identifier for the object. The repository might return a different/new object id
419
     * @param string|null $changeToken the last change token of this object that the client received.
420
     *      The repository might return a new change token (default is <code>null</code>)
421
     * @param ExtensionDataInterface|null $extension
422
     * @throws CmisInvalidArgumentException If $objectId is empty
423
     */
424 3
    public function deleteContentStream(
425
        $repositoryId,
426
        & $objectId,
427
        & $changeToken = null,
428
        ExtensionDataInterface $extension = null
429
    ) {
430 3
        if (empty($objectId)) {
431
            throw new CmisInvalidArgumentException('Object id must not be empty!');
432
        }
433
434 3
        $url = $this->getObjectUrl($repositoryId, $objectId);
435
436 3
        $url->getQuery()->modify(
437
            array(
438 3
                Constants::CONTROL_CMISACTION => Constants::CMISACTION_DELETE_CONTENT,
439 3
                Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false'
440 3
            )
441 3
        );
442
443 3 View Code Duplication
        if ($changeToken !== null && !$this->getSession()->get(SessionParameter::OMIT_CHANGE_TOKENS, false)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
444 1
            $url->getQuery()->modify(array(Constants::PARAM_CHANGE_TOKEN => $changeToken));
445 1
        }
446
447 3
        $responseData = $this->post($url)->json();
448 3
        $newObject = $this->getJsonConverter()->convertObject($responseData);
449
450
        // $objectId was passed by reference. The value is changed here to new object id
451 3
        $objectId = null;
452 3 View Code Duplication
        if ($newObject !== null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
453 3
            $objectId = $newObject->getId();
454 3
            $newObjectProperties = $newObject->getProperties()->getProperties();
455 3
            if ($changeToken !== null && count($newObjectProperties) > 0) {
456 2
                $newChangeToken = $newObjectProperties[PropertyIds::CHANGE_TOKEN];
457
                // $changeToken was passed by reference. The value is changed here
458 2
                $changeToken = $newChangeToken === null ? null : $newChangeToken->getFirstValue();
459 2
            }
460 3
        }
461 3
    }
462
463
    /**
464
     * Deletes the specified object.
465
     *
466
     * @param string $repositoryId the identifier for the repository
467
     * @param string $objectId the identifier for the object
468
     * @param boolean $allVersions If <code>true</code> then delete all versions of the document, otherwise delete only
469
     *      the document object specified (default is <code>true</code>)
470
     * @param ExtensionDataInterface|null $extension
471
     */
472 2
    public function deleteObject(
473
        $repositoryId,
474
        $objectId,
475
        $allVersions = true,
476
        ExtensionDataInterface $extension = null
477
    ) {
478 2
        $url = $this->getObjectUrl($repositoryId, $objectId);
479 2
        $url->getQuery()->modify(
480
            array(
481 2
                Constants::CONTROL_CMISACTION => Constants::CMISACTION_DELETE,
482 2
                Constants::PARAM_ALL_VERSIONS => $allVersions ? 'true' : 'false',
483
            )
484 2
        );
485
486 2
        $this->post($url);
487 2
    }
488
489
    /**
490
     * Deletes the specified folder object and all of its child- and descendant-objects.
491
     *
492
     * @param string $repositoryId the identifier for the repository
493
     * @param string $folderId the identifier for the folder
494
     * @param boolean $allVersions If <code>true</code> then delete all versions of the document, otherwise delete only
495
     *      the document object specified (default is <code>true</code>)
496
     * @param UnfileObject|null $unfileObjects defines how the repository must process file-able child- or
497
     *      descendant-objects (default is <code>UnfileObject::DELETE</code>)
498
     * @param boolean $continueOnFailure If <code>true</code>, then the repository should continue attempting to
499
     *      perform this operation even if deletion of a child- or descendant-object in the specified folder cannot
500
     *      be deleted
501
     * @param ExtensionDataInterface|null $extension
502
     * @return FailedToDeleteDataInterface Returns a list of object ids that could not be deleted
503
     */
504 4
    public function deleteTree(
505
        $repositoryId,
506
        $folderId,
507
        $allVersions = true,
508
        UnfileObject $unfileObjects = null,
509
        $continueOnFailure = false,
510
        ExtensionDataInterface $extension = null
511
    ) {
512 4
        $url = $this->getObjectUrl($repositoryId, $folderId);
513 4
        $url->getQuery()->modify(
514
            array(
515 4
                Constants::CONTROL_CMISACTION => Constants::CMISACTION_DELETE_TREE,
516 4
                Constants::PARAM_FOLDER_ID => $folderId,
517 4
                Constants::PARAM_ALL_VERSIONS => $allVersions ? 'true' : 'false',
518 4
                Constants::PARAM_CONTINUE_ON_FAILURE => $continueOnFailure ? 'true' : 'false'
519 4
            )
520 4
        );
521
522 4
        if ($unfileObjects !== null) {
523 1
            $url->getQuery()->modify(array(Constants::PARAM_UNFILE_OBJECTS => (string) $unfileObjects));
524 1
        }
525
526 4
        $response = $this->post($url);
527
528 4
        return $this->getJsonConverter()->convertFailedToDelete((array) $response->json());
529
    }
530
531
    /**
532
     * Gets the list of allowable actions for an object.
533
     *
534
     * @param string $repositoryId the identifier for the repository
535
     * @param string $objectId the identifier for the object
536
     * @param ExtensionDataInterface|null $extension
537
     * @return AllowableActionsInterface
538
     */
539
    public function getAllowableActions($repositoryId, $objectId, ExtensionDataInterface $extension = null)
540
    {
541
        // TODO: Implement getAllowableActions() method.
542
    }
543
544
    /**
545
     * Gets the content stream for the specified document object, or gets a rendition stream for
546
     * a specified rendition of a document or folder object.
547
     *
548
     * @param string $repositoryId the identifier for the repository
549
     * @param string $objectId the identifier for the object
550
     * @param string|null $streamId The identifier for the rendition stream, when used to get a rendition stream.
551
     *      For documents, if not provided then this method returns the content stream. For folders,
552
     *      it MUST be provided.
553
     * @param integer|null $offset
554
     * @param integer|null $length
555
     * @param ExtensionDataInterface|null $extension
556
     * @return StreamInterface|null
557
     * @throws CmisInvalidArgumentException If object id is empty
558
     */
559 3
    public function getContentStream(
560
        $repositoryId,
561
        $objectId,
562
        $streamId = null,
563
        $offset = null,
564
        $length = null,
565
        ExtensionDataInterface $extension = null
566
    ) {
567 3
        if (empty($objectId)) {
568
            throw new CmisInvalidArgumentException('Object id must not be empty!');
569
        }
570
571 3
        $url = $this->getObjectUrl($repositoryId, $objectId, Constants::SELECTOR_CONTENT);
572
573 3
        if ($streamId !== null) {
574 1
            $url->getQuery()->modify(array(Constants::PARAM_STREAM_ID => $streamId));
575 1
        }
576
577
        /** @var Response $response */
578 3
        $response = $this->getHttpInvoker()->get($url);
579
580 3
        $contentStream = $response->getBody();
581 3
        if (!$contentStream instanceof StreamInterface) {
582
            return null;
583
        }
584
585 3
        if ($offset !== null) {
586 1
            $contentStream = new LimitStream($contentStream, $length !== null ? $length : - 1, $offset);
587 1
        }
588
589 3
        return $contentStream;
590
    }
591
592
    /**
593
     * Gets the specified information for the object specified by id.
594
     *
595
     * @param string $repositoryId the identifier for the repository
596
     * @param string $objectId the identifier for the object
597
     * @param string|null $filter a comma-separated list of query names that defines which properties must be
598
     *      returned by the repository (default is repository specific)
599
     * @param boolean $includeAllowableActions if <code>true</code>, then the repository must return the allowable
600
     *      actions for the object (default is <code>false</code>)
601
     * @param IncludeRelationships|null $includeRelationships indicates what relationships in which the objects
602
     *      participate must be returned (default is <code>IncludeRelationships::NONE</code>)
603
     * @param string $renditionFilter indicates what set of renditions the repository must return whose kind
604
     *      matches this filter (default is "cmis:none")
605
     * @param boolean $includePolicyIds if <code>true</code>, then the repository must return the policy ids for
606
     *      the object (default is <code>false</code>)
607
     * @param boolean $includeAcl if <code>true</code>, then the repository must return the ACL for the object
608
     *      (default is <code>false</code>)
609
     * @param ExtensionDataInterface|null $extension
610
     * @return ObjectDataInterface|null Returns object of type ObjectDataInterface or <code>null</code>
611
     *     if the repository response was empty
612
     */
613 3 View Code Duplication
    public function getObject(
614
        $repositoryId,
615
        $objectId,
616
        $filter = null,
617
        $includeAllowableActions = false,
618
        IncludeRelationships $includeRelationships = null,
619
        $renditionFilter = Constants::RENDITION_NONE,
620
        $includePolicyIds = false,
621
        $includeAcl = false,
622
        ExtensionDataInterface $extension = null
623
    ) {
624 3
        $url = $this->getObjectUrl($repositoryId, $objectId, Constants::SELECTOR_OBJECT);
625 3
        $url->getQuery()->modify(
626
            array(
627 3
                Constants::PARAM_ALLOWABLE_ACTIONS => $includeAllowableActions ? 'true' : 'false',
628 3
                Constants::PARAM_RENDITION_FILTER => $renditionFilter,
629 3
                Constants::PARAM_POLICY_IDS => $includePolicyIds ? 'true' : 'false',
630 3
                Constants::PARAM_ACL => $includeAcl ? 'true' : 'false',
631 3
                Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false',
632 3
                Constants::PARAM_DATETIME_FORMAT => (string) $this->getDateTimeFormat()
633 3
            )
634 3
        );
635
636 3
        if (!empty($filter)) {
637 2
            $url->getQuery()->modify(array(Constants::PARAM_FILTER => (string) $filter));
638 2
        }
639
640 3
        if ($includeRelationships !== null) {
641 2
            $url->getQuery()->modify(array(Constants::PARAM_RELATIONSHIPS => (string) $includeRelationships));
642 2
        }
643
644 3
        $responseData = $this->read($url)->json();
645
646
        // TODO: Implement Cache
647 3
        return $this->getJsonConverter()->convertObject($responseData);
648
    }
649
650
    /**
651
     * Gets the specified information for the object specified by path.
652
     *
653
     * @param string $repositoryId the identifier for the repository
654
     * @param string $path the path to the object
655
     * @param string|null $filter a comma-separated list of query names that defines which properties must be
656
     *      returned by the repository (default is repository specific)
657
     * @param boolean $includeAllowableActions if <code>true</code>, then the repository must return the allowable
658
     *      actions for the object (default is <code>false</code>)
659
     * @param IncludeRelationships|null $includeRelationships indicates what relationships in which the objects
660
     *      participate must be returned (default is <code>IncludeRelationships::NONE</code>)
661
     * @param string $renditionFilter indicates what set of renditions the repository must return whose kind
662
     *      matches this filter (default is "cmis:none")
663
     * @param boolean $includePolicyIds if <code>true</code>, then the repository must return the policy ids for
664
     *      the object (default is <code>false</code>)
665
     * @param boolean $includeAcl if <code>true</code>, then the repository must return the ACL for the object
666
     *      (default is <code>false</code>)
667
     * @param ExtensionDataInterface|null $extension
668
     * @return ObjectDataInterface|null Returns object of type <code>ObjectDataInterface</code> or <code>null</code>
669
     *      if the repository response was empty
670
     */
671 3 View Code Duplication
    public function getObjectByPath(
672
        $repositoryId,
673
        $path,
674
        $filter = null,
675
        $includeAllowableActions = false,
676
        IncludeRelationships $includeRelationships = null,
677
        $renditionFilter = Constants::RENDITION_NONE,
678
        $includePolicyIds = false,
679
        $includeAcl = false,
680
        ExtensionDataInterface $extension = null
681
    ) {
682 3
        $url = $this->getPathUrl($repositoryId, $path, Constants::SELECTOR_OBJECT);
683 3
        $url->getQuery()->modify(
684
            array(
685 3
                Constants::PARAM_ALLOWABLE_ACTIONS => $includeAllowableActions ? 'true' : 'false',
686 3
                Constants::PARAM_RENDITION_FILTER => $renditionFilter,
687 3
                Constants::PARAM_POLICY_IDS => $includePolicyIds ? 'true' : 'false',
688 3
                Constants::PARAM_ACL => $includeAcl ? 'true' : 'false',
689 3
                Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false',
690 3
                Constants::PARAM_DATETIME_FORMAT => (string) $this->getDateTimeFormat()
691 3
            )
692 3
        );
693
694 3
        if (!empty($filter)) {
695 2
            $url->getQuery()->modify(array(Constants::PARAM_FILTER => (string) $filter));
696 2
        }
697
698 3
        if ($includeRelationships !== null) {
699 2
            $url->getQuery()->modify(array(Constants::PARAM_RELATIONSHIPS => (string) $includeRelationships));
700 2
        }
701
702 3
        $responseData = $this->read($url)->json();
703
704
        // TODO Implement Cache
705 3
        return $this->getJsonConverter()->convertObject($responseData);
706
    }
707
708
    /**
709
     * Gets the list of properties for an object.
710
     *
711
     * @param string $repositoryId the identifier for the repository
712
     * @param string $objectId the identifier for the object
713
     * @param string|null $filter a comma-separated list of query names that defines which properties must be
714
     *      returned by the repository (default is repository specific)
715
     * @param ExtensionDataInterface|null $extension
716
     * @return PropertiesInterface
717
     */
718 2
    public function getProperties(
719
        $repositoryId,
720
        $objectId,
721
        $filter = null,
722
        ExtensionDataInterface $extension = null
723
    ) {
724 2
        $url = $this->getObjectUrl($repositoryId, $objectId, Constants::SELECTOR_PROPERTIES);
725 2
        $url->getQuery()->modify(
726
            array(
727 2
                Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false',
728 2
                Constants::PARAM_DATETIME_FORMAT => (string) $this->getDateTimeFormat()
729 2
            )
730 2
        );
731
732 2
        if (!empty($filter)) {
733 1
            $url->getQuery()->modify(array(Constants::PARAM_FILTER => (string) $filter));
734 1
        }
735
736 2
        $responseData = $this->read($url)->json();
737
738
        // TODO: Implement Cache
739 2
        if ($this->getSuccinct()) {
740
            return $this->getJsonConverter()->convertSuccinctProperties($responseData);
741
        } else {
742 2
            return $this->getJsonConverter()->convertProperties($responseData);
743
        }
744
    }
745
746
    /**
747
     * Gets the list of associated renditions for the specified object.
748
     * Only rendition attributes are returned, not rendition stream.
749
     *
750
     * @param string $repositoryId the identifier for the repository
751
     * @param string $objectId the identifier for the object
752
     * @param string $renditionFilter indicates what set of renditions the repository must return whose kind
753
     *      matches this filter (default is "cmis:none")
754
     * @param integer|null $maxItems the maximum number of items to return in a response
755
     *       (default is repository specific)
756
     * @param integer $skipCount number of potential results that the repository MUST skip/page over before
757
     *      returning any results (default is 0)
758
     * @param ExtensionDataInterface|null $extension
759
     * @return RenditionDataInterface[]
760
     * @throws CmisInvalidArgumentException If object id is empty or skip count not of type integer
761
     */
762 2
    public function getRenditions(
763
        $repositoryId,
764
        $objectId,
765
        $renditionFilter = Constants::RENDITION_NONE,
766
        $maxItems = null,
767
        $skipCount = 0,
768
        ExtensionDataInterface $extension = null
769
    ) {
770 2
        if (empty($objectId)) {
771
            throw new CmisInvalidArgumentException('Object id must not be empty!');
772
        }
773
774 2
        if (!is_int($skipCount)) {
775
            throw new CmisInvalidArgumentException('Skip count must be of type integer!');
776
        }
777
778 2
        $url = $this->getObjectUrl($repositoryId, $objectId, Constants::SELECTOR_RENDITIONS);
779 2
        $url->getQuery()->modify(
780
            array(
781 2
                Constants::PARAM_RENDITION_FILTER => $renditionFilter,
782 2
                Constants::PARAM_SKIP_COUNT => (string) $skipCount,
783
            )
784 2
        );
785
786 2
        if ($maxItems !== null) {
787 1
            $url->getQuery()->modify(array(Constants::PARAM_MAX_ITEMS => (string) $maxItems));
788 1
        }
789
790 2
        $responseData = $this->read($url)->json();
791
792 2
        return $this->getJsonConverter()->convertRenditions($responseData);
793
    }
794
795
    /**
796
     * Moves the specified file-able object from one folder to another.
797
     *
798
     * @param string $repositoryId the identifier for the repository
799
     * @param string $objectId the identifier for the object. The repository might return a different/new object id
800
     * @param string $targetFolderId the identifier for the target folder
801
     * @param string $sourceFolderId the identifier for the source folder
802
     * @param ExtensionDataInterface|null $extension
803
     * @return ObjectDataInterface|null Returns object of type ObjectDataInterface or <code>null</code>
804
     *     if the repository response was empty
805
     */
806 1
    public function moveObject(
807
        $repositoryId,
808
        & $objectId,
809
        $targetFolderId,
810
        $sourceFolderId,
811
        ExtensionDataInterface $extension = null
812
    ) {
813 1
        $url = $this->getObjectUrl($repositoryId, $objectId);
814 1
        $url->getQuery()->modify(
815
            array(
816 1
                Constants::CONTROL_CMISACTION => Constants::CMISACTION_MOVE,
817 1
                Constants::PARAM_TARGET_FOLDER_ID => $targetFolderId,
818 1
                Constants::PARAM_SOURCE_FOLDER_ID => $sourceFolderId,
819 1
                Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false'
820 1
            )
821 1
        );
822
823 1
        $responseData = $this->post($url)->json();
824 1
        $newObject = $this->getJsonConverter()->convertObject($responseData);
825
826
        // $objectId was passed by reference. The value is changed here to new object id
827 1
        $objectId = ($newObject === null) ? null : $newObject->getId();
828
829 1
        return $newObject;
830
    }
831
832
    /**
833
     * Sets the content stream for the specified document object.
834
     *
835
     * @param string $repositoryId The identifier for the repository
836
     * @param string $objectId The identifier for the object. The repository might return a different/new object id
837
     * @param StreamInterface $contentStream The content stream
838
     * @param boolean $overwriteFlag If <code>true</code>, then the repository must replace the existing content stream
839
     *      for the object (if any) with the input content stream. If <code>false</code>, then the repository must
840
     *      only set the input content stream for the object if the object currently does not have a content stream
841
     *      (default is <code>true</code>)
842
     * @param string|null $changeToken The last change token of this object that the client received.
843
     *      The repository might return a new change token (default is <code>null</code>)
844
     * @param ExtensionDataInterface|null $extension
845
     * @throws CmisInvalidArgumentException If object id is empty
846
     */
847 3
    public function setContentStream(
848
        $repositoryId,
849
        & $objectId,
850
        StreamInterface $contentStream,
851
        $overwriteFlag = true,
852
        & $changeToken = null,
853
        ExtensionDataInterface $extension = null
854
    ) {
855 3
        if (empty($objectId)) {
856
            throw new CmisInvalidArgumentException('Object id must not be empty!');
857
        }
858
859 3
        $url = $this->getObjectUrl($repositoryId, $objectId);
860
861 3
        $url->getQuery()->modify(
862
            array(
863 3
                Constants::CONTROL_CMISACTION => Constants::CMISACTION_SET_CONTENT,
864 3
                Constants::PARAM_OVERWRITE_FLAG => $overwriteFlag ? 'true' : 'false',
865 3
                Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false'
866 3
            )
867 3
        );
868
869 3 View Code Duplication
        if ($changeToken !== null && !$this->getSession()->get(SessionParameter::OMIT_CHANGE_TOKENS, false)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
870 1
            $url->getQuery()->modify(array(Constants::PARAM_CHANGE_TOKEN => $changeToken));
871 1
        }
872
873 3
        $responseData = $this->post(
874 3
            $url,
875
            $contentStream
876 3
        )->json();
877
878 3
        $newObject = $this->getJsonConverter()->convertObject($responseData);
879
880
        // $objectId was passed by reference. The value is changed here to new object id
881 3
        $objectId = null;
882 3 View Code Duplication
        if ($newObject !== null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
883 3
            $objectId = $newObject->getId();
884 3
            $newObjectProperties = $newObject->getProperties()->getProperties();
885 3
            if ($changeToken !== null && count($newObjectProperties) > 0) {
886 2
                $newChangeToken = $newObjectProperties[PropertyIds::CHANGE_TOKEN];
887
                // $changeToken was passed by reference. The value is changed here
888 2
                $changeToken = $newChangeToken === null ? null : $newChangeToken->getFirstValue();
889 2
            }
890 3
        }
891 3
    }
892
893
    /**
894
     * Updates properties of the specified object.
895
     *
896
     * @param string $repositoryId The identifier for the repository
897
     * @param string $objectId The identifier for the object. The repository might return a different/new object id
898
     * @param PropertiesInterface $properties The updated property values that must be applied to the object
899
     * @param string|null $changeToken The last change token of this object that the client received.
900
     *      The repository might return a new change token (default is <code>null</code>)
901
     * @param ExtensionDataInterface|null $extension
902
     * @throws CmisInvalidArgumentException If $objectId is empty
903
     */
904 3
    public function updateProperties(
905
        $repositoryId,
906
        & $objectId,
907
        PropertiesInterface $properties,
908
        & $changeToken = null,
909
        ExtensionDataInterface $extension = null
910
    ) {
911 3
        if (empty($objectId)) {
912
            throw new CmisInvalidArgumentException('Object id must not be empty!');
913
        }
914
915 3
        $url = $this->getObjectUrl($repositoryId, $objectId);
916
917 3 View Code Duplication
        if ($changeToken !== null && !$this->getSession()->get(SessionParameter::OMIT_CHANGE_TOKENS, false)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
918 1
            $url->getQuery()->modify(array(Constants::PARAM_CHANGE_TOKEN => $changeToken));
919 1
        }
920
921 3
        $queryArray = $this->convertPropertiesToQueryArray($properties);
922 3
        $queryArray[Constants::CONTROL_CMISACTION] = Constants::CMISACTION_UPDATE_PROPERTIES;
923 3
        $queryArray[Constants::PARAM_SUCCINCT] = $this->getSuccinct() ? 'true' : 'false';
924 3
        $responseData = $this->post($url, $queryArray)->json();
925 3
        $newObject = $this->getJsonConverter()->convertObject($responseData);
926
927
        // $objectId was passed by reference. The value is changed here to new object id
928 3
        $objectId = null;
929 3 View Code Duplication
        if ($newObject !== null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
930 3
            $objectId = $newObject->getId();
931 3
            $newObjectProperties = $newObject->getProperties()->getProperties();
932 3
            if ($changeToken !== null && count($newObjectProperties) > 0) {
933 2
                $newChangeToken = $newObjectProperties[PropertyIds::CHANGE_TOKEN];
934
                // $changeToken was passed by reference. The value is changed here
935 2
                $changeToken = $newChangeToken === null ? null : $newChangeToken->getFirstValue();
936 2
            }
937 3
        }
938 3
    }
939
}
940