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
Pull Request — master (#3)
by
unknown
13:26 queued 03:26
created

ObjectService::createItem()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 34
Code Lines 23

Duplication

Lines 5
Ratio 14.71 %

Code Coverage

Tests 6
CRAP Score 4.0466

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 5
loc 34
ccs 6
cts 7
cp 0.8571
rs 8.5806
cc 4
eloc 23
nc 4
nop 7
crap 4.0466
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 3
        #$this->appendRemoveAcesToUrl($url, $removeAces);
0 ignored issues
show
Unused Code Comprehensibility introduced by
80% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
125 3
        #$this->appendPoliciesToUrl($url, $policies);
0 ignored issues
show
Unused Code Comprehensibility introduced by
80% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
126
        #$this->appendAddAcesToUrl($url, $addAces);
0 ignored issues
show
Unused Code Comprehensibility introduced by
80% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
127 3
128 3
        // Guzzle gets the mime type for a file by the filename extension. Sometimes the filename does not contain
129 3
        // the correct filename extension for example when a file is uploaded in php it gets a temporary name without
130 3
        // a file extension. If the filename does not contain a file extension we use the given 'cmis:name' property
131
        // as filename. See also https://github.com/guzzle/guzzle/issues/571
132 3
        if ($contentStream !== null && pathinfo($contentStream->getMetadata('uri'), PATHINFO_EXTENSION) === '') {
133 2
            $contentStream = new PostFile(
134 2
                'content',
135
                $contentStream,
136 3
                $properties->getProperties()['cmis:name']->getFirstValue()
137 3
            );
138 3
        }
139
140
        $queryArray = array_replace(
141
			array(
142
				Constants::CONTROL_CMISACTION => Constants::CMISACTION_CREATE_DOCUMENT,
143
				Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false',
144 3
				'content' => $contentStream
145 1
			),
146 1
			$this->convertPropertiesToQueryArray($properties),
147 1
			$this->convertPolicyIdArrayToQueryArray($policies)
148 1
		);
149 1 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...
150 1
			$queryArray = array_replace($queryArray, $this->convertAclToQueryArray(
151
				$removeAces,
152 3
				Constants::CONTROL_REMOVE_ACE_PRINCIPAL,
153 3
				Constants::CONTROL_REMOVE_ACE_PERMISSION
154 3
			));
155 3
		}
156 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...
157 3
			$queryArray = array_replace($queryArray, $this->convertAclToQueryArray(
158
				$addAces,
159 3
				Constants::CONTROL_ADD_ACE_PRINCIPAL,
160
				Constants::CONTROL_ADD_ACE_PERMISSION
161
			));
162
		}
163
        if ($versioningState !== null) {
164
            $queryArray[Constants::PARAM_VERSIONING_STATE] = (string) $versioningState;
165
        }
166
        $responseData = $this->post(
167
            $url,
168
            $queryArray
169
        )->json();
170
171
        $newObject = $this->getJsonConverter()->convertObject($responseData);
172
173
        return ($newObject === null) ? null : $newObject->getId();
174
    }
175
176
    /**
177
     * Creates a document object as a copy of the given source document in the (optionally) specified location.
178
     *
179
     * @param string $repositoryId the identifier for the repository
180
     * @param string $sourceId the identifier for the source document
181
     * @param PropertiesInterface $properties the property values that must be applied to the newly
182 2
     *      created document object
183
     * @param string|null $folderId if specified, the identifier for the folder that must be the parent folder for the
184
     *      newly created document object
185
     * @param VersioningState|null $versioningState specifies what the versioning state of the newly created object
186
     *      must be (default is <code>VersioningState::MAJOR</code>)
187
     * @param string[] $policies a list of policy IDs that must be applied to the newly created document object
188
     * @param AclInterface|null $addAces a list of ACEs that must be added to the newly created document object,
189
     *      either using the ACL from folderId if specified, or being applied if no folderId is specified
190
     * @param AclInterface|null $removeAces a list of ACEs that must be removed from the newly created document object,
191
     *      either using the ACL from folderId if specified, or being ignored if no folderId is specified
192
     * @param ExtensionDataInterface|null $extension
193 2
     * @return string|null Returns the new object id or <code>null</code> if the repository sent an empty
194
     *      result (which should not happen)
195
     */
196 2
    public function createDocumentFromSource(
197
        $repositoryId,
198
        $sourceId,
199 2
        PropertiesInterface $properties,
200 2
        $folderId = null,
201
        VersioningState $versioningState = null,
202 2
        array $policies = array(),
203 2
        AclInterface $addAces = null,
204 2
        AclInterface $removeAces = null,
205 2
        ExtensionDataInterface $extension = null
206 2
    ) {
207 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...
208 2
            $url = $this->getRepositoryUrl($repositoryId);
209 1
        } else {
210 1
            $url = $this->getObjectUrl($repositoryId, $folderId);
211
        }
212 2
213 2
		$queryArray = array_replace(
214 2
			array(
215
				Constants::CONTROL_CMISACTION => Constants::CMISACTION_CREATE_DOCUMENT_FROM_SOURCE,
216 2
				Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false',
217
                Constants::PARAM_SOURCE_ID => (string) $sourceId
218 2
			),
219
			$this->convertPropertiesToQueryArray($properties),
220 2
			$this->convertPolicyIdArrayToQueryArray($policies)
221
		);
222 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...
223
			$queryArray = array_replace($queryArray, $this->convertAclToQueryArray(
224
				$removeAces,
225
				Constants::CONTROL_REMOVE_ACE_PRINCIPAL,
226
				Constants::CONTROL_REMOVE_ACE_PERMISSION
227
			));
228
		}
229 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...
230
			$queryArray = array_replace($queryArray, $this->convertAclToQueryArray(
231
				$addAces,
232
				Constants::CONTROL_ADD_ACE_PRINCIPAL,
233
				Constants::CONTROL_ADD_ACE_PERMISSION
234
			));
235
		}
236
		if ($versioningState !== null) {
237
			$queryArray[Constants::PARAM_VERSIONING_STATE] = (string) $versioningState;
238
		}
239
        $responseData = $this->post($url, $queryArray)->json();
240
241 2
        $newObject = $this->getJsonConverter()->convertObject($responseData);
242
243
        return ($newObject === null) ? null : $newObject->getId();
244
    }
245
246
    /**
247
     * Creates a folder object of the specified type (given by the cmis:objectTypeId property) in
248
     * the specified location.
249
     *
250 2
     * @param string $repositoryId the identifier for the repository
251 2
     * @param PropertiesInterface $properties the property values that must be applied to the newly
252
     *      created document object
253 2
     * @param string $folderId if specified, the identifier for the folder that must be the parent folder for the
254 2
     *      newly created document object
255 2
     * @param string[] $policies a list of policy IDs that must be applied to the newly created document object
256 2
     * @param AclInterface|null $addAces a list of ACEs that must be added to the newly created document object,
257
     *      either using the ACL from folderId if specified, or being applied if no folderId is specified
258 2
     * @param AclInterface|null $removeAces a list of ACEs that must be removed from the newly created document object,
259
     *      either using the ACL from folderId if specified, or being ignored if no folderId is specified
260 2
     * @param ExtensionDataInterface|null $extension
261 2
     * @return string|null Returns the new object id or <code>null</code> if the repository sent an empty
262 2
     *      result (which should not happen)
263
     */
264 2 View Code Duplication
    public function createFolder(
265
        $repositoryId,
266 2
        PropertiesInterface $properties,
267
        $folderId,
268 2
        array $policies = array(),
269
        AclInterface $addAces = null,
270
        AclInterface $removeAces = null,
271
        ExtensionDataInterface $extension = null
272
    ) {
273
        $url = $this->getObjectUrl($repositoryId, $folderId);
274
        $url->getQuery()->modify(
275
            array(
276
                Constants::CONTROL_CMISACTION => Constants::CMISACTION_CREATE_FOLDER,
277
                Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false'
278
            )
279
        );
280
281
        $url->getQuery()->modify($this->convertPropertiesToQueryArray($properties));
282
283
        $this->appendPoliciesToUrl($url, $policies);
284
        $this->appendAddAcesToUrl($url, $addAces);
285
        $this->appendRemoveAcesToUrl($url, $removeAces);
286
287
        $responseData = $this->post($url)->json();
288 2
289
        $newObject = $this->getJsonConverter()->convertObject($responseData);
290
291
        return ($newObject === null) ? null : $newObject->getId();
292
    }
293
294
    /**
295
     * Creates an item object of the specified type (given by the cmis:objectTypeId property).
296
     *
297 2
     * @param string $repositoryId The identifier for the repository
298
     * @param PropertiesInterface $properties The property values that must be applied to the newly
299
     *      created document object
300 2
     * @param string|null $folderId If specified, the identifier for the folder that must be the parent folder for the
301
     *      newly created document object
302
     * @param string[] $policies A list of policy IDs that must be applied to the newly created document object
303 2
     * @param AclInterface|null $addAces A list of ACEs that must be added to the newly created document object,
304
     *      either using the ACL from folderId if specified, or being applied if no folderId is specified
305 2
     * @param AclInterface|null $removeAces A list of ACEs that must be removed from the newly created document object,
306 2
     *      either using the ACL from folderId if specified, or being ignored if no folderId is specified
307 2
     * @param ExtensionDataInterface|null $extension
308 2
     * @return string|null Returns the new item id or <code>null</code> if the repository sent an empty
309
     *      result (which should not happen)
310 2
     */
311
    public function createItem(
312 2
        $repositoryId,
313 2
        PropertiesInterface $properties,
314 2
        $folderId = null,
315
        array $policies = array(),
316 2
        AclInterface $addAces = null,
317
        AclInterface $removeAces = null,
318 2
        ExtensionDataInterface $extension = null
319
    ) {
320 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...
321
            $url = $this->getRepositoryUrl($repositoryId);
322
        } else {
323
            $url = $this->getObjectUrl($repositoryId, $folderId);
324
        }
325
326
        $url->getQuery()->modify(
327
            array(
328
                Constants::CONTROL_CMISACTION => Constants::CMISACTION_CREATE_ITEM,
329
                Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false'
330
            )
331
        );
332
333
        $url->getQuery()->modify($this->convertPropertiesToQueryArray($properties));
334
335
        $this->appendPoliciesToUrl($url, $policies);
336
        $this->appendAddAcesToUrl($url, $addAces);
337
        $this->appendRemoveAcesToUrl($url, $removeAces);
338
339
        $responseData = $this->post($url)->json();
340
341
        $newObject = $this->getJsonConverter()->convertObject($responseData);
342
343
        return ($newObject === null) ? null : $newObject->getId();
344
    }
345
346
    /**
347
     * Creates a policy object of the specified type (given by the cmis:objectTypeId property).
348
     *
349
     * @param string $repositoryId The identifier for the repository
350
     * @param PropertiesInterface $properties The property values that must be applied to the newly
351
     *      created document object
352
     * @param string|null $folderId If specified, the identifier for the folder that must be the parent folder for the
353
     *      newly created document object
354
     * @param string[] $policies A list of policy IDs that must be applied to the newly created document object
355
     * @param AclInterface|null $addAces A list of ACEs that must be added to the newly created document object,
356
     *      either using the ACL from folderId if specified, or being applied if no folderId is specified
357
     * @param AclInterface|null $removeAces A list of ACEs that must be removed from the newly created document object,
358
     *      either using the ACL from folderId if specified, or being ignored if no folderId is specified
359
     * @param ExtensionDataInterface|null $extension
360
     * @return string The id of the newly-created policy.
361
     */
362
    public function createPolicy(
363
        $repositoryId,
364
        PropertiesInterface $properties,
365
        $folderId = null,
366
        array $policies = array(),
367
        AclInterface $addAces = null,
368
        AclInterface $removeAces = null,
369
        ExtensionDataInterface $extension = null
370
    ) {
371
        // TODO: Implement createPolicy() method.
372
    }
373
374
    /**
375
     * Creates a relationship object of the specified type (given by the cmis:objectTypeId property).
376
     *
377
     * @param string $repositoryId the identifier for the repository
378
     * @param PropertiesInterface $properties the property values that must be applied to the newly
379
     *      created document object
380
     * @param string[] $policies a list of policy IDs that must be applied to the newly created document object
381
     * @param AclInterface|null $addAces a list of ACEs that must be added to the newly created document object,
382
     *      either using the ACL from folderId if specified, or being applied if no folderId is specified
383
     * @param AclInterface|null $removeAces a list of ACEs that must be removed from the newly created document object,
384
     *      either using the ACL from folderId if specified, or being ignored if no folderId is specified
385
     * @param ExtensionDataInterface|null $extension
386
     * @return string|null Returns the new item id of the relationship object or <code>null</code> if the repository
387
     *      sent an empty result (which should not happen)
388
     */
389 View Code Duplication
    public function createRelationship(
390
        $repositoryId,
391
        PropertiesInterface $properties,
392
        array $policies = array(),
393
        AclInterface $addAces = null,
394
        AclInterface $removeAces = null,
395
        ExtensionDataInterface $extension = null
396
    ) {
397
        $url = $this->getRepositoryUrl($repositoryId);
398
399
        $url->getQuery()->modify(
400
            array(
401
                Constants::CONTROL_CMISACTION => Constants::CMISACTION_CREATE_RELATIONSHIP,
402
                Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false'
403
            )
404
        );
405 3
406
        $url->getQuery()->modify($this->convertPropertiesToQueryArray($properties));
407
        $this->appendPoliciesToUrl($url, $policies);
408
        $this->appendAddAcesToUrl($url, $addAces);
409
        $this->appendRemoveAcesToUrl($url, $removeAces);
410
411 3
        $responseData = $this->post($url)->json();
412
413
        $newObject = $this->getJsonConverter()->convertObject($responseData);
414
415 3
        return ($newObject === null) ? null : $newObject->getId();
416
    }
417 3
418
    /**
419 3
     * Deletes the content stream for the specified document object.
420 3
     *
421 3
     * @param string $repositoryId the identifier for the repository
422 3
     * @param string $objectId the identifier for the object. The repository might return a different/new object id
423
     * @param string|null $changeToken the last change token of this object that the client received.
424 3
     *      The repository might return a new change token (default is <code>null</code>)
425 1
     * @param ExtensionDataInterface|null $extension
426 1
     * @throws CmisInvalidArgumentException If $objectId is empty
427
     */
428 3
    public function deleteContentStream(
429 3
        $repositoryId,
430
        & $objectId,
431
        & $changeToken = null,
432 3
        ExtensionDataInterface $extension = null
433 3
    ) {
434 3
        if (empty($objectId)) {
435 3
            throw new CmisInvalidArgumentException('Object id must not be empty!');
436 3
        }
437 2
438
        $url = $this->getObjectUrl($repositoryId, $objectId);
439 2
440 2
        $url->getQuery()->modify(
441 3
            array(
442 3
                Constants::CONTROL_CMISACTION => Constants::CMISACTION_DELETE_CONTENT,
443
                Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false'
444
            )
445
        );
446
447 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...
448
            $url->getQuery()->modify(array(Constants::PARAM_CHANGE_TOKEN => $changeToken));
449
        }
450
451
        $responseData = $this->post($url)->json();
452
        $newObject = $this->getJsonConverter()->convertObject($responseData);
453 2
454
        // $objectId was passed by reference. The value is changed here to new object id
455
        $objectId = null;
456 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...
457
            $objectId = $newObject->getId();
458
            $newObjectProperties = $newObject->getProperties()->getProperties();
459 2
            if ($changeToken !== null && count($newObjectProperties) > 0) {
460 2
                $newChangeToken = $newObjectProperties[PropertyIds::CHANGE_TOKEN];
461
                // $changeToken was passed by reference. The value is changed here
462 2
                $changeToken = $newChangeToken === null ? null : $newChangeToken->getFirstValue();
463 2
            }
464
        }
465 2
    }
466
467 2
    /**
468 2
     * Deletes the specified object.
469
     *
470
     * @param string $repositoryId the identifier for the repository
471
     * @param string $objectId the identifier for the object
472
     * @param boolean $allVersions If <code>true</code> then delete all versions of the document, otherwise delete only
473
     *      the document object specified (default is <code>true</code>)
474
     * @param ExtensionDataInterface|null $extension
475
     */
476
    public function deleteObject(
477
        $repositoryId,
478
        $objectId,
479
        $allVersions = true,
480
        ExtensionDataInterface $extension = null
481
    ) {
482
        $url = $this->getObjectUrl($repositoryId, $objectId);
483
        $url->getQuery()->modify(
484
            array(
485 4
                Constants::CONTROL_CMISACTION => Constants::CMISACTION_DELETE,
486
                Constants::PARAM_ALL_VERSIONS => $allVersions ? 'true' : 'false',
487
            )
488
        );
489
490
        $this->post($url);
491
    }
492
493 4
    /**
494 4
     * Deletes the specified folder object and all of its child- and descendant-objects.
495
     *
496 4
     * @param string $repositoryId the identifier for the repository
497 4
     * @param string $folderId the identifier for the folder
498 4
     * @param boolean $allVersions If <code>true</code> then delete all versions of the document, otherwise delete only
499 4
     *      the document object specified (default is <code>true</code>)
500 4
     * @param UnfileObject|null $unfileObjects defines how the repository must process file-able child- or
501 4
     *      descendant-objects (default is <code>UnfileObject::DELETE</code>)
502
     * @param boolean $continueOnFailure If <code>true</code>, then the repository should continue attempting to
503 4
     *      perform this operation even if deletion of a child- or descendant-object in the specified folder cannot
504 1
     *      be deleted
505 1
     * @param ExtensionDataInterface|null $extension
506
     * @return FailedToDeleteDataInterface Returns a list of object ids that could not be deleted
507 4
     */
508
    public function deleteTree(
509 4
        $repositoryId,
510
        $folderId,
511
        $allVersions = true,
512
        UnfileObject $unfileObjects = null,
513
        $continueOnFailure = false,
514
        ExtensionDataInterface $extension = null
515
    ) {
516
        $url = $this->getObjectUrl($repositoryId, $folderId);
517
        $url->getQuery()->modify(
518
            array(
519
                Constants::CONTROL_CMISACTION => Constants::CMISACTION_DELETE_TREE,
520
                Constants::PARAM_FOLDER_ID => $folderId,
521
                Constants::PARAM_ALL_VERSIONS => $allVersions ? 'true' : 'false',
522
                Constants::PARAM_CONTINUE_ON_FAILURE => $continueOnFailure ? 'true' : 'false'
523
            )
524
        );
525
526
        if ($unfileObjects !== null) {
527
            $url->getQuery()->modify(array(Constants::PARAM_UNFILE_OBJECTS => (string) $unfileObjects));
528
        }
529
530
        $response = $this->post($url);
531
532
        return $this->getJsonConverter()->convertFailedToDelete((array) $response->json());
533
    }
534
535
    /**
536
     * Gets the list of allowable actions for an object.
537
     *
538
     * @param string $repositoryId the identifier for the repository
539
     * @param string $objectId the identifier for the object
540 3
     * @param ExtensionDataInterface|null $extension
541
     * @return AllowableActionsInterface
542
     */
543
    public function getAllowableActions($repositoryId, $objectId, ExtensionDataInterface $extension = null)
544
    {
545
        // TODO: Implement getAllowableActions() method.
546
    }
547
548 3
    /**
549
     * Gets the content stream for the specified document object, or gets a rendition stream for
550
     * a specified rendition of a document or folder object.
551
     *
552 3
     * @param string $repositoryId the identifier for the repository
553
     * @param string $objectId the identifier for the object
554 3
     * @param string|null $streamId The identifier for the rendition stream, when used to get a rendition stream.
555 1
     *      For documents, if not provided then this method returns the content stream. For folders,
556 1
     *      it MUST be provided.
557
     * @param integer|null $offset
558
     * @param integer|null $length
559 3
     * @param ExtensionDataInterface|null $extension
560
     * @return StreamInterface|null
561 3
     * @throws CmisInvalidArgumentException If object id is empty
562 3
     */
563
    public function getContentStream(
564
        $repositoryId,
565
        $objectId,
566 3
        $streamId = null,
567 1
        $offset = null,
568 1
        $length = null,
569
        ExtensionDataInterface $extension = null
570 3
    ) {
571
        if (empty($objectId)) {
572
            throw new CmisInvalidArgumentException('Object id must not be empty!');
573
        }
574
575
        $url = $this->getObjectUrl($repositoryId, $objectId, Constants::SELECTOR_CONTENT);
576
577
        if ($streamId !== null) {
578
            $url->getQuery()->modify(array(Constants::PARAM_STREAM_ID => $streamId));
579
        }
580
581
        /** @var Response $response */
582
        $response = $this->getHttpInvoker()->get($url);
583
584
        $contentStream = $response->getBody();
585
        if (!$contentStream instanceof StreamInterface) {
586
            return null;
587
        }
588
589
        if ($offset !== null) {
590
            $contentStream = new LimitStream($contentStream, $length !== null ? $length : - 1, $offset);
591
        }
592
593
        return $contentStream;
594 3
    }
595
596
    /**
597
     * Gets the specified information for the object specified by id.
598
     *
599
     * @param string $repositoryId the identifier for the repository
600
     * @param string $objectId the identifier for the object
601
     * @param string|null $filter a comma-separated list of query names that defines which properties must be
602
     *      returned by the repository (default is repository specific)
603
     * @param boolean $includeAllowableActions if <code>true</code>, then the repository must return the allowable
604
     *      actions for the object (default is <code>false</code>)
605 3
     * @param IncludeRelationships|null $includeRelationships indicates what relationships in which the objects
606 3
     *      participate must be returned (default is <code>IncludeRelationships::NONE</code>)
607
     * @param string $renditionFilter indicates what set of renditions the repository must return whose kind
608 3
     *      matches this filter (default is "cmis:none")
609 3
     * @param boolean $includePolicyIds if <code>true</code>, then the repository must return the policy ids for
610 3
     *      the object (default is <code>false</code>)
611 3
     * @param boolean $includeAcl if <code>true</code>, then the repository must return the ACL for the object
612 3
     *      (default is <code>false</code>)
613 3
     * @param ExtensionDataInterface|null $extension
614 3
     * @return ObjectDataInterface|null Returns object of type ObjectDataInterface or <code>null</code>
615 3
     *     if the repository response was empty
616
     */
617 3 View Code Duplication
    public function getObject(
618 2
        $repositoryId,
619 2
        $objectId,
620
        $filter = null,
621 3
        $includeAllowableActions = false,
622 2
        IncludeRelationships $includeRelationships = null,
623 2
        $renditionFilter = Constants::RENDITION_NONE,
624
        $includePolicyIds = false,
625 3
        $includeAcl = false,
626
        ExtensionDataInterface $extension = null
627
    ) {
628 3
        $url = $this->getObjectUrl($repositoryId, $objectId, Constants::SELECTOR_OBJECT);
629
        $url->getQuery()->modify(
630
            array(
631
                Constants::PARAM_ALLOWABLE_ACTIONS => $includeAllowableActions ? 'true' : 'false',
632
                Constants::PARAM_RENDITION_FILTER => $renditionFilter,
633
                Constants::PARAM_POLICY_IDS => $includePolicyIds ? 'true' : 'false',
634
                Constants::PARAM_ACL => $includeAcl ? 'true' : 'false',
635
                Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false',
636
                Constants::PARAM_DATETIME_FORMAT => (string) $this->getDateTimeFormat()
637
            )
638
        );
639
640
        if (!empty($filter)) {
641
            $url->getQuery()->modify(array(Constants::PARAM_FILTER => (string) $filter));
642
        }
643
644
        if ($includeRelationships !== null) {
645
            $url->getQuery()->modify(array(Constants::PARAM_RELATIONSHIPS => (string) $includeRelationships));
646
        }
647
648
        $responseData = $this->read($url)->json();
649
650
        // TODO: Implement Cache
651
        return $this->getJsonConverter()->convertObject($responseData);
652 3
    }
653
654
    /**
655
     * Gets the specified information for the object specified by path.
656
     *
657
     * @param string $repositoryId the identifier for the repository
658
     * @param string $path the path to the object
659
     * @param string|null $filter a comma-separated list of query names that defines which properties must be
660
     *      returned by the repository (default is repository specific)
661
     * @param boolean $includeAllowableActions if <code>true</code>, then the repository must return the allowable
662
     *      actions for the object (default is <code>false</code>)
663 3
     * @param IncludeRelationships|null $includeRelationships indicates what relationships in which the objects
664 3
     *      participate must be returned (default is <code>IncludeRelationships::NONE</code>)
665
     * @param string $renditionFilter indicates what set of renditions the repository must return whose kind
666 3
     *      matches this filter (default is "cmis:none")
667 3
     * @param boolean $includePolicyIds if <code>true</code>, then the repository must return the policy ids for
668 3
     *      the object (default is <code>false</code>)
669 3
     * @param boolean $includeAcl if <code>true</code>, then the repository must return the ACL for the object
670 3
     *      (default is <code>false</code>)
671 3
     * @param ExtensionDataInterface|null $extension
672 3
     * @return ObjectDataInterface|null Returns object of type <code>ObjectDataInterface</code> or <code>null</code>
673 3
     *      if the repository response was empty
674
     */
675 3 View Code Duplication
    public function getObjectByPath(
676 2
        $repositoryId,
677 2
        $path,
678
        $filter = null,
679 3
        $includeAllowableActions = false,
680 2
        IncludeRelationships $includeRelationships = null,
681 2
        $renditionFilter = Constants::RENDITION_NONE,
682
        $includePolicyIds = false,
683 3
        $includeAcl = false,
684
        ExtensionDataInterface $extension = null
685
    ) {
686 3
        $url = $this->getPathUrl($repositoryId, $path, Constants::SELECTOR_OBJECT);
687
        $url->getQuery()->modify(
688
            array(
689
                Constants::PARAM_ALLOWABLE_ACTIONS => $includeAllowableActions ? 'true' : 'false',
690
                Constants::PARAM_RENDITION_FILTER => $renditionFilter,
691
                Constants::PARAM_POLICY_IDS => $includePolicyIds ? 'true' : 'false',
692
                Constants::PARAM_ACL => $includeAcl ? 'true' : 'false',
693
                Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false',
694
                Constants::PARAM_DATETIME_FORMAT => (string) $this->getDateTimeFormat()
695
            )
696
        );
697
698
        if (!empty($filter)) {
699 2
            $url->getQuery()->modify(array(Constants::PARAM_FILTER => (string) $filter));
700
        }
701
702
        if ($includeRelationships !== null) {
703
            $url->getQuery()->modify(array(Constants::PARAM_RELATIONSHIPS => (string) $includeRelationships));
704
        }
705 2
706 2
        $responseData = $this->read($url)->json();
707
708 2
        // TODO Implement Cache
709 2
        return $this->getJsonConverter()->convertObject($responseData);
710 2
    }
711 2
712
    /**
713 2
     * Gets the list of properties for an object.
714 1
     *
715 1
     * @param string $repositoryId the identifier for the repository
716
     * @param string $objectId the identifier for the object
717 2
     * @param string|null $filter a comma-separated list of query names that defines which properties must be
718
     *      returned by the repository (default is repository specific)
719
     * @param ExtensionDataInterface|null $extension
720 2
     * @return PropertiesInterface
721
     */
722
    public function getProperties(
723 2
        $repositoryId,
724
        $objectId,
725
        $filter = null,
726
        ExtensionDataInterface $extension = null
727
    ) {
728
        $url = $this->getObjectUrl($repositoryId, $objectId, Constants::SELECTOR_PROPERTIES);
729
        $url->getQuery()->modify(
730
            array(
731
                Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false',
732
                Constants::PARAM_DATETIME_FORMAT => (string) $this->getDateTimeFormat()
733
            )
734
        );
735
736
        if (!empty($filter)) {
737
            $url->getQuery()->modify(array(Constants::PARAM_FILTER => (string) $filter));
738
        }
739
740
        $responseData = $this->read($url)->json();
741
742
        // TODO: Implement Cache
743 2
        if ($this->getSuccinct()) {
744
            return $this->getJsonConverter()->convertSuccinctProperties($responseData);
745
        } else {
746
            return $this->getJsonConverter()->convertProperties($responseData);
747
        }
748
    }
749
750
    /**
751 2
     * Gets the list of associated renditions for the specified object.
752
     * Only rendition attributes are returned, not rendition stream.
753
     *
754
     * @param string $repositoryId the identifier for the repository
755 2
     * @param string $objectId the identifier for the object
756
     * @param string $renditionFilter indicates what set of renditions the repository must return whose kind
757
     *      matches this filter (default is "cmis:none")
758
     * @param integer|null $maxItems the maximum number of items to return in a response
759 2
     *       (default is repository specific)
760 2
     * @param integer $skipCount number of potential results that the repository MUST skip/page over before
761
     *      returning any results (default is 0)
762 2
     * @param ExtensionDataInterface|null $extension
763 2
     * @return RenditionDataInterface[]
764
     * @throws CmisInvalidArgumentException If object id is empty or skip count not of type integer
765 2
     */
766
    public function getRenditions(
767 2
        $repositoryId,
768 1
        $objectId,
769 1
        $renditionFilter = Constants::RENDITION_NONE,
770
        $maxItems = null,
771 2
        $skipCount = 0,
772
        ExtensionDataInterface $extension = null
773 2
    ) {
774
        if (empty($objectId)) {
775
            throw new CmisInvalidArgumentException('Object id must not be empty!');
776
        }
777
778
        if (!is_int($skipCount)) {
779
            throw new CmisInvalidArgumentException('Skip count must be of type integer!');
780
        }
781
782
        $url = $this->getObjectUrl($repositoryId, $objectId, Constants::SELECTOR_RENDITIONS);
783
        $url->getQuery()->modify(
784
            array(
785
                Constants::PARAM_RENDITION_FILTER => $renditionFilter,
786
                Constants::PARAM_SKIP_COUNT => (string) $skipCount,
787 1
            )
788
        );
789
790
        if ($maxItems !== null) {
791
            $url->getQuery()->modify(array(Constants::PARAM_MAX_ITEMS => (string) $maxItems));
792
        }
793
794 1
        $responseData = $this->read($url)->json();
795 1
796
        return $this->getJsonConverter()->convertRenditions($responseData);
797 1
    }
798 1
799 1
    /**
800 1
     * Moves the specified file-able object from one folder to another.
801 1
     *
802 1
     * @param string $repositoryId the identifier for the repository
803
     * @param string $objectId the identifier for the object. The repository might return a different/new object id
804 1
     * @param string $targetFolderId the identifier for the target folder
805 1
     * @param string $sourceFolderId the identifier for the source folder
806
     * @param ExtensionDataInterface|null $extension
807
     * @return ObjectDataInterface|null Returns object of type ObjectDataInterface or <code>null</code>
808 1
     *     if the repository response was empty
809
     */
810 1
    public function moveObject(
811
        $repositoryId,
812
        & $objectId,
813
        $targetFolderId,
814
        $sourceFolderId,
815
        ExtensionDataInterface $extension = null
816
    ) {
817
        $url = $this->getObjectUrl($repositoryId, $objectId);
818
        $url->getQuery()->modify(
819
            array(
820
                Constants::CONTROL_CMISACTION => Constants::CMISACTION_MOVE,
821
                Constants::PARAM_TARGET_FOLDER_ID => $targetFolderId,
822
                Constants::PARAM_SOURCE_FOLDER_ID => $sourceFolderId,
823
                Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false'
824
            )
825
        );
826
827
        $responseData = $this->post($url)->json();
828 3
        $newObject = $this->getJsonConverter()->convertObject($responseData);
829
830
        // $objectId was passed by reference. The value is changed here to new object id
831
        $objectId = ($newObject === null) ? null : $newObject->getId();
832
833
        return $newObject;
834
    }
835
836 3
    /**
837
     * Sets the content stream for the specified document object.
838
     *
839
     * @param string $repositoryId The identifier for the repository
840 3
     * @param string $objectId The identifier for the object. The repository might return a different/new object id
841
     * @param StreamInterface $contentStream The content stream
842 3
     * @param boolean $overwriteFlag If <code>true</code>, then the repository must replace the existing content stream
843
     *      for the object (if any) with the input content stream. If <code>false</code>, then the repository must
844 3
     *      only set the input content stream for the object if the object currently does not have a content stream
845 3
     *      (default is <code>true</code>)
846 3
     * @param string|null $changeToken The last change token of this object that the client received.
847 3
     *      The repository might return a new change token (default is <code>null</code>)
848 3
     * @param ExtensionDataInterface|null $extension
849
     * @throws CmisInvalidArgumentException If object id is empty
850 3
     */
851 1
    public function setContentStream(
852 1
        $repositoryId,
853
        & $objectId,
854 3
        StreamInterface $contentStream,
855 3
        $overwriteFlag = true,
856 3
        & $changeToken = null,
857 3
        ExtensionDataInterface $extension = null
858
    ) {
859 3
        if (empty($objectId)) {
860
            throw new CmisInvalidArgumentException('Object id must not be empty!');
861
        }
862 3
863 3
        $url = $this->getObjectUrl($repositoryId, $objectId);
864 3
865 3
        $url->getQuery()->modify(
866 3
            array(
867 2
                Constants::CONTROL_CMISACTION => Constants::CMISACTION_SET_CONTENT,
868
                Constants::PARAM_OVERWRITE_FLAG => $overwriteFlag ? 'true' : 'false',
869 2
                Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false'
870 2
            )
871 3
        );
872 3
873 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...
874
            $url->getQuery()->modify(array(Constants::PARAM_CHANGE_TOKEN => $changeToken));
875
        }
876
877
        $responseData = $this->post(
878
            $url,
879
            $contentStream
880
        )->json();
881
882
        $newObject = $this->getJsonConverter()->convertObject($responseData);
883
884
        // $objectId was passed by reference. The value is changed here to new object id
885 3
        $objectId = null;
886 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...
887
            $objectId = $newObject->getId();
888
            $newObjectProperties = $newObject->getProperties()->getProperties();
889
            if ($changeToken !== null && count($newObjectProperties) > 0) {
890
                $newChangeToken = $newObjectProperties[PropertyIds::CHANGE_TOKEN];
891
                // $changeToken was passed by reference. The value is changed here
892 3
                $changeToken = $newChangeToken === null ? null : $newChangeToken->getFirstValue();
893
            }
894
        }
895
    }
896 3
897
    /**
898 3
     * Updates properties of the specified object.
899 3
     *
900
     * @param string $repositoryId The identifier for the repository
901 3
     * @param string $objectId The identifier for the object. The repository might return a different/new object id
902 3
     * @param PropertiesInterface $properties The updated property values that must be applied to the object
903 3
     * @param string|null $changeToken The last change token of this object that the client received.
904 3
     *      The repository might return a new change token (default is <code>null</code>)
905
     * @param ExtensionDataInterface|null $extension
906 3
     * @throws CmisInvalidArgumentException If $objectId is empty
907 1
     */
908 1
    public function updateProperties(
909
        $repositoryId,
910 3
        & $objectId,
911 3
        PropertiesInterface $properties,
912
        & $changeToken = null,
913
        ExtensionDataInterface $extension = null
914 3
    ) {
915 3
        if (empty($objectId)) {
916 3
            throw new CmisInvalidArgumentException('Object id must not be empty!');
917 3
        }
918 3
919 2
        $url = $this->getObjectUrl($repositoryId, $objectId);
920
921 2 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...
922 2
            $url->getQuery()->modify(array(Constants::PARAM_CHANGE_TOKEN => $changeToken));
923 3
        }
924 3
925
        $queryArray = $this->convertPropertiesToQueryArray($properties);
926
        $queryArray[Constants::CONTROL_CMISACTION] = Constants::CMISACTION_UPDATE_PROPERTIES;
927
        $queryArray[Constants::PARAM_SUCCINCT] = $this->getSuccinct() ? 'true' : 'false';
928
        $responseData = $this->post($url, $queryArray)->json();
929
        $newObject = $this->getJsonConverter()->convertObject($responseData);
930
931
        // $objectId was passed by reference. The value is changed here to new object id
932
        $objectId = null;
933 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...
934
            $objectId = $newObject->getId();
935
            $newObjectProperties = $newObject->getProperties()->getProperties();
936
            if ($changeToken !== null && count($newObjectProperties) > 0) {
937
                $newChangeToken = $newObjectProperties[PropertyIds::CHANGE_TOKEN];
938
                // $changeToken was passed by reference. The value is changed here
939
                $changeToken = $newChangeToken === null ? null : $newChangeToken->getFirstValue();
940
            }
941
        }
942
    }
943
}
944