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 ( b20185...55fb49 )
by
unknown
11s
created

ObjectService::cache()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
ccs 0
cts 0
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 2
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
     * L1 cache for objects. Fills with two levels:
41
     *
42
     * - First level key is the object ID, path or other singular identifier of object(s)
43
     * - Second level key is a hash of context arguments used to retrieve the object(s)
44
     *
45
     * @var array
46
     */
47
    protected $objectCache = array();
48
49
    /**
50
     * Appends the content stream to the content of the document.
51
     *
52
     * The stream in contentStream is consumed but not closed by this method.
53
     *
54
     * @param string $repositoryId the identifier for the repository
55
     * @param string $objectId The identifier for the object. The repository might return a different/new object id
56
     * @param StreamInterface $contentStream The content stream to append
57
     * @param boolean $isLastChunk Indicates if this content stream is the last chunk
58
     * @param string|null $changeToken The last change token of this object that the client received.
59
     *      The repository might return a new change token (default is <code>null</code>)
60
     * @param ExtensionDataInterface|null $extension
61
     */
62
    public function appendContentStream(
63
        $repositoryId,
64
        & $objectId,
65
        StreamInterface $contentStream,
66
        $isLastChunk,
67
        & $changeToken = null,
68
        ExtensionDataInterface $extension = null
69
    ) {
70
        // TODO: Implement appendContentStream() method.
71
    }
72
73
    /**
74
     * Updates properties and secondary types of one or more objects.
75
     *
76
     * @param string $repositoryId the identifier for the repository
77
     * @param BulkUpdateObjectIdAndChangeTokenInterface[] $objectIdsAndChangeTokens
78
     * @param PropertiesInterface $properties
79
     * @param string[] $addSecondaryTypeIds the secondary types to apply
80
     * @param string[] $removeSecondaryTypeIds the secondary types to remove
81
     * @param ExtensionDataInterface|null $extension
82
     * @return BulkUpdateObjectIdAndChangeTokenInterface[]
83
     */
84
    public function bulkUpdateProperties(
85
        $repositoryId,
86
        array $objectIdsAndChangeTokens,
87
        PropertiesInterface $properties,
88
        array $addSecondaryTypeIds,
89
        array $removeSecondaryTypeIds,
90
        ExtensionDataInterface $extension = null
91
    ) {
92
        // TODO: Implement bulkUpdateProperties() method.
93
    }
94 9
95
    /**
96
     * @param string $action
97
     * @param PropertiesInterface $properties
98
     * @param string[] $policies
99
     * @param AclInterface $addAces
0 ignored issues
show
Documentation introduced by
Should the type for parameter $addAces not be null|AclInterface?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
100
     * @param AclInterface $removeAces
0 ignored issues
show
Documentation introduced by
Should the type for parameter $removeAces not be null|AclInterface?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
101
     * @param ExtensionDataInterface $extension
0 ignored issues
show
Documentation introduced by
Should the type for parameter $extension not be null|ExtensionDataInterface?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
102 9
     * @return array
103
     */
104 9
    protected function createQueryArray(
105 9
        $action,
106 9
        PropertiesInterface $properties,
107 9
        array $policies = array(),
108 9
        AclInterface $addAces = null,
109 9
        AclInterface $removeAces = null,
110 9
        ExtensionDataInterface $extension = null
0 ignored issues
show
Unused Code introduced by
The parameter $extension is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
111 5
    ) {
112 5
        $queryArray = array_replace(
113 5
            array(
114
                Constants::CONTROL_CMISACTION => $action,
115 5
                Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false',
116 5
            ),
117 9
            $this->convertPropertiesToQueryArray($properties),
118 5
            $this->convertPolicyIdArrayToQueryArray($policies)
119 5
        );
120 5
        if (!empty($removeAces)) {
121
            $queryArray = array_replace($queryArray, $this->convertAclToQueryArray(
122 5
                $removeAces,
123 5
                Constants::CONTROL_REMOVE_ACE_PRINCIPAL,
124 9
                Constants::CONTROL_REMOVE_ACE_PERMISSION
125
            ));
126
        }
127
        if (!empty($addAces)) {
128
            $queryArray = array_replace($queryArray, $this->convertAclToQueryArray(
129
                $addAces,
130
                Constants::CONTROL_ADD_ACE_PRINCIPAL,
131
                Constants::CONTROL_ADD_ACE_PERMISSION
132
            ));
133
        }
134
        return $queryArray;
135
    }
136
137
    /**
138
     * Creates a document object of the specified type (given by the cmis:objectTypeId property)
139
     * in the (optionally) specified location.
140
     *
141
     * @param string $repositoryId the identifier for the repository
142
     * @param PropertiesInterface $properties the property values that must be applied to the newly
143
     *      created document object
144
     * @param string|null $folderId if specified, the identifier for the folder that must be the parent
145
     *      folder for the newly created document object
146
     * @param StreamInterface|null $contentStream the content stream that must be stored for the newly
147
     *      created document object
148
     * @param VersioningState|null $versioningState specifies what the versioning state of the newly created object
149 3
     *      must be (default is <code>VersioningState::MAJOR</code>)
150
     * @param string[] $policies a list of policy IDs that must be applied to the newly created document object
151
     * @param AclInterface|null $addAces a list of ACEs that must be added to the newly created document object,
152
     *      either using the ACL from folderId if specified, or being applied if no folderId is specified
153
     * @param AclInterface|null $removeAces a list of ACEs that must be removed from the newly created document object,
154
     *      either using the ACL from folderId if specified, or being ignored if no folderId is specified
155
     * @param ExtensionDataInterface|null $extension
156
     * @return string|null Returns the new object id or <code>null</code> if the repository sent an empty
157
     *      result (which should not happen)
158
     */
159
    public function createDocument(
160 3
        $repositoryId,
161 1
        PropertiesInterface $properties,
162 1
        $folderId = null,
163 2
        StreamInterface $contentStream = null,
164
        VersioningState $versioningState = null,
165
        array $policies = array(),
166
        AclInterface $addAces = null,
167
        AclInterface $removeAces = null,
168
        ExtensionDataInterface $extension = null
169
    ) {
170 3 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...
171 1
            $url = $this->getRepositoryUrl($repositoryId);
172 1
        } else {
173 1
            $url = $this->getObjectUrl($repositoryId, $folderId);
174 1
        }
175 1
176 1
        // Guzzle gets the mime type for a file by the filename extension. Sometimes the filename does not contain
177
        // the correct filename extension for example when a file is uploaded in php it gets a temporary name without
178 3
        // a file extension. If the filename does not contain a file extension we use the given 'cmis:name' property
179 3
        // as filename. See also https://github.com/guzzle/guzzle/issues/571
180 3
        if ($contentStream !== null && pathinfo($contentStream->getMetadata('uri'), PATHINFO_EXTENSION) === '') {
181 3
            $contentStream = new PostFile(
182 3
                'content',
183 3
                $contentStream,
184
                $properties->getProperties()['cmis:name']->getFirstValue()
185 3
            );
186 3
        }
187 2
188 2
        $queryArray = $this->createQueryArray(
189 3
            Constants::CMISACTION_CREATE_DOCUMENT,
190 2
            $properties,
191 2
            $policies,
192 3
            $addAces,
193 3
            $removeAces,
194
            $extension
195 3
        );
196
        if ($versioningState !== null) {
197 3
            $queryArray[Constants::PARAM_VERSIONING_STATE] = (string) $versioningState;
198
        }
199 3
        if ($contentStream) {
200
            $queryArray['content'] = $contentStream;
201
        }
202
        $responseData = $this->post(
203
            $url,
204
            $queryArray
205
        )->json();
206
207
        $newObject = $this->getJsonConverter()->convertObject($responseData);
208
209
        return ($newObject === null) ? null : $newObject->getId();
210
    }
211
212
    /**
213
     * Creates a document object as a copy of the given source document in the (optionally) specified location.
214
     *
215
     * @param string $repositoryId the identifier for the repository
216
     * @param string $sourceId the identifier for the source document
217
     * @param PropertiesInterface $properties the property values that must be applied to the newly
218
     *      created document object
219
     * @param string|null $folderId if specified, the identifier for the folder that must be the parent folder for the
220
     *      newly created document object
221
     * @param VersioningState|null $versioningState specifies what the versioning state of the newly created object
222 2
     *      must be (default is <code>VersioningState::MAJOR</code>)
223
     * @param string[] $policies a list of policy IDs that must be applied to the newly created document object
224
     * @param AclInterface|null $addAces a list of ACEs that must be added to the newly created document object,
225
     *      either using the ACL from folderId if specified, or being applied if no folderId is specified
226
     * @param AclInterface|null $removeAces a list of ACEs that must be removed from the newly created document object,
227
     *      either using the ACL from folderId if specified, or being ignored if no folderId is specified
228
     * @param ExtensionDataInterface|null $extension
229
     * @return string|null Returns the new object id or <code>null</code> if the repository sent an empty
230
     *      result (which should not happen)
231
     */
232
    public function createDocumentFromSource(
233 2
        $repositoryId,
234
        $sourceId,
235
        PropertiesInterface $properties,
236 2
        $folderId = null,
237
        VersioningState $versioningState = null,
238
        array $policies = array(),
239 2
        AclInterface $addAces = null,
240 2
        AclInterface $removeAces = null,
241 2
        ExtensionDataInterface $extension = null
242 2
    ) {
243 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...
244 2
            $url = $this->getRepositoryUrl($repositoryId);
245
        } else {
246 2
            $url = $this->getObjectUrl($repositoryId, $folderId);
247 2
        }
248 2
249 1
        $queryArray = $this->createQueryArray(
250 1
            Constants::CMISACTION_CREATE_DOCUMENT_FROM_SOURCE,
251 2
            $properties,
252
            $policies,
253 2
            $addAces,
254
            $removeAces,
255 2
            $extension
256
        );
257
        $queryArray[Constants::PARAM_SOURCE_ID] = (string) $sourceId;
258
        if ($versioningState !== null) {
259
            $queryArray[Constants::PARAM_VERSIONING_STATE] = (string) $versioningState;
260
        }
261
        $responseData = $this->post($url, $queryArray)->json();
262
263
        $newObject = $this->getJsonConverter()->convertObject($responseData);
264
265
        return ($newObject === null) ? null : $newObject->getId();
266
    }
267
268
    /**
269
     * Creates a folder object of the specified type (given by the cmis:objectTypeId property) in
270
     * the specified location.
271
     *
272
     * @param string $repositoryId the identifier for the repository
273
     * @param PropertiesInterface $properties the property values that must be applied to the newly
274
     *      created document object
275
     * @param string $folderId if specified, the identifier for the folder that must be the parent folder for the
276 2
     *      newly created document object
277
     * @param string[] $policies a list of policy IDs that must be applied to the newly created document object
278
     * @param AclInterface|null $addAces a list of ACEs that must be added to the newly created document object,
279
     *      either using the ACL from folderId if specified, or being applied if no folderId is specified
280
     * @param AclInterface|null $removeAces a list of ACEs that must be removed from the newly created document object,
281
     *      either using the ACL from folderId if specified, or being ignored if no folderId is specified
282
     * @param ExtensionDataInterface|null $extension
283
     * @return string|null Returns the new object id or <code>null</code> if the repository sent an empty
284
     *      result (which should not happen)
285 2
     */
286 2 View Code Duplication
    public function createFolder(
287 2
        $repositoryId,
288 2
        PropertiesInterface $properties,
289 2
        $folderId,
290 2
        array $policies = array(),
291 2
        AclInterface $addAces = null,
292
        AclInterface $removeAces = null,
293 2
        ExtensionDataInterface $extension = null
294
    ) {
295 2
        $url = $this->getObjectUrl($repositoryId, $folderId);
296
        $queryArray = $this->createQueryArray(
297 2
            Constants::CMISACTION_CREATE_FOLDER,
298
            $properties,
299 2
            $policies,
300
            $addAces,
301
            $removeAces,
302
            $extension
303
        );
304
305
        $responseData = $this->post($url, $queryArray)->json();
306
307
        $newObject = $this->getJsonConverter()->convertObject($responseData);
308
309
        return ($newObject === null) ? null : $newObject->getId();
310
    }
311
312
    /**
313
     * Creates an item object of the specified type (given by the cmis:objectTypeId property).
314
     *
315
     * @param string $repositoryId The identifier for the repository
316
     * @param PropertiesInterface $properties The property values that must be applied to the newly
317
     *      created document object
318
     * @param string|null $folderId If specified, the identifier for the folder that must be the parent folder for the
319 2
     *      newly created document object
320
     * @param string[] $policies A list of policy IDs that must be applied to the newly created document object
321
     * @param AclInterface|null $addAces A list of ACEs that must be added to the newly created document object,
322
     *      either using the ACL from folderId if specified, or being applied if no folderId is specified
323
     * @param AclInterface|null $removeAces A list of ACEs that must be removed from the newly created document object,
324
     *      either using the ACL from folderId if specified, or being ignored if no folderId is specified
325
     * @param ExtensionDataInterface|null $extension
326
     * @return string|null Returns the new item id or <code>null</code> if the repository sent an empty
327
     *      result (which should not happen)
328 2
     */
329
    public function createItem(
330
        $repositoryId,
331 2
        PropertiesInterface $properties,
332
        $folderId = null,
333
        array $policies = array(),
334 2
        AclInterface $addAces = null,
335 2
        AclInterface $removeAces = null,
336 2
        ExtensionDataInterface $extension = null
337 2
    ) {
338 2
        if ($folderId === null) {
339 2
            $url = $this->getRepositoryUrl($repositoryId);
340
        } else {
341 2
            $url = $this->getObjectUrl($repositoryId, $folderId);
342
        }
343 2
344
        $queryArray = $this->createQueryArray(
345 2
            Constants::CMISACTION_CREATE_ITEM,
346
            $properties,
347 2
            $policies,
348
            $addAces,
349
            $removeAces,
350
            $extension
351
        );
352
353
        $responseData = $this->post($url, $queryArray)->json();
354
355
        $newObject = $this->getJsonConverter()->convertObject($responseData);
356
357
        return ($newObject === null) ? null : $newObject->getId();
358
    }
359
360
    /**
361
     * Creates a policy object of the specified type (given by the cmis:objectTypeId property).
362
     *
363
     * @param string $repositoryId The identifier for the repository
364
     * @param PropertiesInterface $properties The property values that must be applied to the newly
365
     *      created document object
366
     * @param string|null $folderId If specified, the identifier for the folder that must be the parent folder for the
367
     *      newly created document object
368
     * @param string[] $policies A list of policy IDs that must be applied to the newly created document object
369
     * @param AclInterface|null $addAces A list of ACEs that must be added to the newly created document object,
370
     *      either using the ACL from folderId if specified, or being applied if no folderId is specified
371
     * @param AclInterface|null $removeAces A list of ACEs that must be removed from the newly created document object,
372
     *      either using the ACL from folderId if specified, or being ignored if no folderId is specified
373
     * @param ExtensionDataInterface|null $extension
374
     * @return string The id of the newly-created policy.
375
     */
376
    public function createPolicy(
377
        $repositoryId,
378
        PropertiesInterface $properties,
379
        $folderId = null,
380
        array $policies = array(),
381
        AclInterface $addAces = null,
382
        AclInterface $removeAces = null,
383
        ExtensionDataInterface $extension = null
384
    ) {
385
        // TODO: Implement createPolicy() method.
386
    }
387
388
    /**
389
     * Creates a relationship object of the specified type (given by the cmis:objectTypeId property).
390
     *
391
     * @param string $repositoryId the identifier for the repository
392
     * @param PropertiesInterface $properties the property values that must be applied to the newly
393
     *      created document object
394
     * @param string[] $policies a list of policy IDs that must be applied to the newly created document object
395
     * @param AclInterface|null $addAces a list of ACEs that must be added to the newly created document object,
396
     *      either using the ACL from folderId if specified, or being applied if no folderId is specified
397
     * @param AclInterface|null $removeAces a list of ACEs that must be removed from the newly created document object,
398
     *      either using the ACL from folderId if specified, or being ignored if no folderId is specified
399
     * @param ExtensionDataInterface|null $extension
400
     * @return string|null Returns the new item id of the relationship object or <code>null</code> if the repository
401
     *      sent an empty result (which should not happen)
402
     */
403 View Code Duplication
    public function createRelationship(
404
        $repositoryId,
405
        PropertiesInterface $properties,
406
        array $policies = array(),
407
        AclInterface $addAces = null,
408
        AclInterface $removeAces = null,
409
        ExtensionDataInterface $extension = null
410
    ) {
411
        $url = $this->getRepositoryUrl($repositoryId);
412
413
        $queryArray = $this->createQueryArray(
414
            Constants::CMISACTION_CREATE_RELATIONSHIP,
415
            $properties,
416
            $policies,
417
            $addAces,
418
            $removeAces,
419
            $extension
420
        );
421
422
        $responseData = $this->post($url, $queryArray)->json();
423
424
        $newObject = $this->getJsonConverter()->convertObject($responseData);
425
426
        return ($newObject === null) ? null : $newObject->getId();
427
    }
428
429 3
    /**
430
     * Deletes the content stream for the specified document object.
431
     *
432
     * @param string $repositoryId the identifier for the repository
433
     * @param string $objectId the identifier for the object. The repository might return a different/new object id
434
     * @param string|null $changeToken the last change token of this object that the client received.
435 3
     *      The repository might return a new change token (default is <code>null</code>)
436
     * @param ExtensionDataInterface|null $extension
437
     * @throws CmisInvalidArgumentException If $objectId is empty
438
     */
439 3
    public function deleteContentStream(
440
        $repositoryId,
441 3
        & $objectId,
442
        & $changeToken = null,
443 3
        ExtensionDataInterface $extension = null
444 3
    ) {
445 3
        if (empty($objectId)) {
446 3
            throw new CmisInvalidArgumentException('Object id must not be empty!');
447
        }
448 3
449 1
        $this->flushCached($objectId);
0 ignored issues
show
Unused Code introduced by
The call to ObjectService::flushCached() has too many arguments starting with $objectId.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
450 1
451
        $url = $this->getObjectUrl($repositoryId, $objectId);
452 3
453 3
        $url->getQuery()->modify(
454
            array(
455
                Constants::CONTROL_CMISACTION => Constants::CMISACTION_DELETE_CONTENT,
456 3
                Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false'
457 3
            )
458 3
        );
459 3
460 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...
461 2
            $url->getQuery()->modify(array(Constants::PARAM_CHANGE_TOKEN => $changeToken));
462
        }
463 2
464 2
        $responseData = $this->post($url)->json();
465 3
        $newObject = $this->getJsonConverter()->convertObject($responseData);
466 3
467
        // $objectId was passed by reference. The value is changed here to new object id
468
        $objectId = null;
469 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...
470
            $objectId = $newObject->getId();
471
            $newObjectProperties = $newObject->getProperties()->getProperties();
472
            if ($changeToken !== null && count($newObjectProperties) > 0) {
473
                $newChangeToken = $newObjectProperties[PropertyIds::CHANGE_TOKEN];
474
                // $changeToken was passed by reference. The value is changed here
475
                $changeToken = $newChangeToken === null ? null : $newChangeToken->getFirstValue();
476
            }
477 2
        }
478
    }
479
480
    /**
481
     * Deletes the specified object.
482
     *
483 2
     * @param string $repositoryId the identifier for the repository
484 2
     * @param string $objectId the identifier for the object
485
     * @param boolean $allVersions If <code>true</code> then delete all versions of the document, otherwise delete only
486 2
     *      the document object specified (default is <code>true</code>)
487 2
     * @param ExtensionDataInterface|null $extension
488
     */
489 2
    public function deleteObject(
490
        $repositoryId,
491 2
        $objectId,
492 2
        $allVersions = true,
493
        ExtensionDataInterface $extension = null
494
    ) {
495
        $url = $this->getObjectUrl($repositoryId, $objectId);
496
        $url->getQuery()->modify(
497
            array(
498
                Constants::CONTROL_CMISACTION => Constants::CMISACTION_DELETE,
499
                Constants::PARAM_ALL_VERSIONS => $allVersions ? 'true' : 'false',
500
            )
501
        );
502
503
        $this->post($url);
504
        $this->flushCached($objectId);
0 ignored issues
show
Unused Code introduced by
The call to ObjectService::flushCached() has too many arguments starting with $objectId.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

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

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
889 3
890 3
        $url = $this->getObjectUrl($repositoryId, $objectId);
891 2
        $url->getQuery()->modify(
892
            array(
893 2
                Constants::CONTROL_CMISACTION => Constants::CMISACTION_MOVE,
894 2
                Constants::PARAM_TARGET_FOLDER_ID => $targetFolderId,
895 3
                Constants::PARAM_SOURCE_FOLDER_ID => $sourceFolderId,
896 3
                Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false'
897
            )
898
        );
899
900
        $responseData = $this->post($url)->json();
901
        $newObject = $this->getJsonConverter()->convertObject($responseData);
902
903
        // $objectId was passed by reference. The value is changed here to new object id
904
        $objectId = ($newObject === null) ? null : $newObject->getId();
905
906
        return $newObject;
907
    }
908
909 3
    /**
910
     * Sets the content stream for the specified document object.
911
     *
912
     * @param string $repositoryId The identifier for the repository
913
     * @param string $objectId The identifier for the object. The repository might return a different/new object id
914
     * @param StreamInterface $contentStream The content stream
915
     * @param boolean $overwriteFlag If <code>true</code>, then the repository must replace the existing content stream
916 3
     *      for the object (if any) with the input content stream. If <code>false</code>, then the repository must
917
     *      only set the input content stream for the object if the object currently does not have a content stream
918
     *      (default is <code>true</code>)
919
     * @param string|null $changeToken The last change token of this object that the client received.
920 3
     *      The repository might return a new change token (default is <code>null</code>)
921
     * @param ExtensionDataInterface|null $extension
922 3
     * @throws CmisInvalidArgumentException If object id is empty
923 1
     */
924 1
    public function setContentStream(
925
        $repositoryId,
926 3
        & $objectId,
927 3
        StreamInterface $contentStream,
928 3
        $overwriteFlag = true,
929 3
        & $changeToken = null,
930 3
        ExtensionDataInterface $extension = null
931
    ) {
932
        if (empty($objectId)) {
933 3
            throw new CmisInvalidArgumentException('Object id must not be empty!');
934 3
        }
935 3
936 3
        $this->flushCached($objectId);
0 ignored issues
show
Unused Code introduced by
The call to ObjectService::flushCached() has too many arguments starting with $objectId.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
937 3
938 2
        $url = $this->getObjectUrl($repositoryId, $objectId);
939
940 2
        $url->getQuery()->modify(
941 2
            array(
942 3
                Constants::CONTROL_CMISACTION => Constants::CMISACTION_SET_CONTENT,
943 3
                Constants::PARAM_OVERWRITE_FLAG => $overwriteFlag ? 'true' : 'false',
944
                Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false'
945
            )
946
        );
947
948 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...
949
            $url->getQuery()->modify(array(Constants::PARAM_CHANGE_TOKEN => $changeToken));
950
        }
951
952
        $responseData = $this->post(
953
            $url,
954
            array('content' => $contentStream)
955
        )->json();
956
957
        $newObject = $this->getJsonConverter()->convertObject($responseData);
958
959
        // $objectId was passed by reference. The value is changed here to new object id
960
        $objectId = null;
961 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...
962
            $objectId = $newObject->getId();
963
            $newObjectProperties = $newObject->getProperties()->getProperties();
964
            if ($changeToken !== null && count($newObjectProperties) > 0) {
965
                $newChangeToken = $newObjectProperties[PropertyIds::CHANGE_TOKEN];
966
                // $changeToken was passed by reference. The value is changed here
967
                $changeToken = $newChangeToken === null ? null : $newChangeToken->getFirstValue();
968
            }
969
        }
970
    }
971
972
    /**
973
     * Updates properties of the specified object.
974
     *
975
     * @param string $repositoryId The identifier for the repository
976
     * @param string $objectId The identifier for the object. The repository might return a different/new object id
977
     * @param PropertiesInterface $properties The updated property values that must be applied to the object
978
     * @param string|null $changeToken The last change token of this object that the client received.
979
     *      The repository might return a new change token (default is <code>null</code>)
980
     * @param ExtensionDataInterface|null $extension
981
     * @throws CmisInvalidArgumentException If $objectId is empty
982
     */
983
    public function updateProperties(
984
        $repositoryId,
985
        & $objectId,
986
        PropertiesInterface $properties,
987
        & $changeToken = null,
988
        ExtensionDataInterface $extension = null
989
    ) {
990
        if (empty($objectId)) {
991
            throw new CmisInvalidArgumentException('Object id must not be empty!');
992
        }
993
994
        $this->flushCached($objectId);
0 ignored issues
show
Unused Code introduced by
The call to ObjectService::flushCached() has too many arguments starting with $objectId.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
995
996
        $url = $this->getObjectUrl($repositoryId, $objectId);
997
998 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...
999
            $url->getQuery()->modify(array(Constants::PARAM_CHANGE_TOKEN => $changeToken));
1000
        }
1001
1002
        $queryArray = $this->convertPropertiesToQueryArray($properties);
1003
        $queryArray[Constants::CONTROL_CMISACTION] = Constants::CMISACTION_UPDATE_PROPERTIES;
1004
        $queryArray[Constants::PARAM_SUCCINCT] = $this->getSuccinct() ? 'true' : 'false';
1005
        $responseData = $this->post($url, $queryArray)->json();
1006
        $newObject = $this->getJsonConverter()->convertObject($responseData);
1007
1008
        // $objectId was passed by reference. The value is changed here to new object id
1009
        $objectId = null;
1010 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...
1011
            $objectId = $newObject->getId();
1012
            $newObjectProperties = $newObject->getProperties()->getProperties();
1013
            if ($changeToken !== null && count($newObjectProperties) > 0) {
1014
                $newChangeToken = $newObjectProperties[PropertyIds::CHANGE_TOKEN];
1015
                // $changeToken was passed by reference. The value is changed here
1016
                $changeToken = $newChangeToken === null ? null : $newChangeToken->getFirstValue();
1017
            }
1018
        }
1019
    }
1020
1021
    /**
1022
     * @param string $identifier
1023
     * @param mixed $additionalHashValues
1024
     * @return array
1025
     */
1026
    protected function createCacheKey($identifier, $additionalHashValues)
1027
    {
1028
        return array(
1029
            $identifier,
1030
            sha1(is_array($additionalHashValues) ? serialize($additionalHashValues) : $additionalHashValues)
1031
        );
1032
    }
1033
1034
    /**
1035
     * Returns TRUE if an object with cache key $identifier is currently cached.
1036
     *
1037
     * @param array $identifier
1038
     * @return boolean
1039
     */
1040
    protected function isCached(array $identifier)
1041
    {
1042
        if (is_array($identifier)) {
1043
            return isset($this->objectCache[$identifier[0]][$identifier[1]]);
1044
        } elseif (isset($this->objectCache[$identifier])) {
1045
            return $this->objectCache[$identifier];
1046
        }
1047
        return false;
1048
    }
1049
1050
    /**
1051
     * Gets the cached object with cache key $identifier.
1052
     *
1053
     * @param string $identifier
0 ignored issues
show
Documentation introduced by
Should the type for parameter $identifier not be array? Also, consider making the array more specific, something like array<String>, or String[].

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive. In addition it looks for parameters that have the generic type array and suggests a stricter type like array<String>.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
1054
     * @return mixed
1055
     */
1056
    protected function getCached(array $identifier)
1057
    {
1058
        if ($this->isCached($identifier)) {
1059
            return $this->objectCache[$identifier];
1060
        }
1061
        return null;
1062
    }
1063
1064
	/**
1065
     * Gets the cached object with cache key $identifier.
1066
     *
1067
     * @param string $identifier
0 ignored issues
show
Documentation introduced by
Should the type for parameter $identifier not be array? Also, consider making the array more specific, something like array<String>, or String[].

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive. In addition it looks for parameters that have the generic type array and suggests a stricter type like array<String>.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
1068
     * @param mixed $object
1069
     * @return mixed
1070
     */
1071
    protected function cache(array $identifier, $object)
1072
    {
1073
        $this->objectCache[$identifier[0]][$identifier[1]] = $object;
1074
        return $object;
1075
    }
1076
1077
	/**
1078
	 * Flushes all cached entries. This is implemented as a flush-all with
1079
	 * no way to flush individual entries due to the way CMIS object data
1080
	 * gets returned from CMIS. Two widely different object data sets may
1081
	 * contain a reference to the same item and even with extensive cross
1082
	 * referencing it would be technically unfeasible to selectively clear
1083
	 * or reload an object by identifier. Such flushing would be inevitably
1084
	 * flawed with edge cases of incomplete flushing or become so complex
1085
	 * that it defeats the purpose of caching in the first place.
1086
	 *
1087
	 * Note that cache flushing only happens when modifying the repository
1088
	 * contents - which should limit the negative impact. The cache is also
1089
	 * not persistent and will only affect the current request. As such, it
1090
	 * is implemented to optimise requests where the same object, type,
1091
	 * policy etc. gets accessed multiple times.
1092
	 *
1093
	 * @return void
1094
	 */
1095
	protected function flushCached()
1096
	{
1097
		$this->objectCache = array();
1098
	}
1099
}
1100