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 ( a98f71...7edffd )
by
unknown
9s
created

VersioningService::createQueryArray()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
ccs 0
cts 7
cp 0
rs 9.4285
cc 2
eloc 10
nc 1
nop 3
crap 6
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\PropertyIds;
16
use GuzzleHttp\Stream\StreamInterface;
17
use Dkd\PhpCmis\Data\ExtensionDataInterface;
18
use Dkd\PhpCmis\Data\ObjectDataInterface;
19
use Dkd\PhpCmis\Data\PropertiesInterface;
20
use Dkd\PhpCmis\VersioningServiceInterface;
21
use Dkd\PhpCmis\Enum\IncludeRelationships;
22
23
/**
24
 * Versioning Service Browser Binding client.
25
 */
26
class VersioningService extends AbstractBrowserBindingService implements VersioningServiceInterface
27
{
28
    /**
29
     * Reverses the effect of a check-out.
30
     *
31
     * @param string $repositoryId the identifier for the repository
32
     * @param string $objectId the identifier for the PWC
33
     * @param ExtensionDataInterface|null $extension
34
     */
35 View Code Duplication
    public function cancelCheckOut($repositoryId, & $objectId, ExtensionDataInterface $extension = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
36
    {
37
		$objectId = $this->getJsonConverter()->convertObject(
38
			$this->post(
39
				$this->getObjectUrl($repositoryId, $objectId),
40
				$this->createQueryArray(
41
					Constants::CMISACTION_CANCEL_CHECK_OUT,
42
					array(),
43
					$extension
44
				)
45
			)->json()
46
		);
47
    }
48
49
    /**
50
     * Checks-in the private working copy (PWC) document.
51
     *
52
     * @param string $repositoryId the identifier for the repository
53
     * @param string $objectId input: the identifier for the PWC,
54
     *      output: the identifier for the newly created version document
55
     * @param boolean $major indicator if the new version should become a major (<code>true</code>) or minor
56
     *      (<code>false</code>) version
57
     * @param PropertiesInterface|null $properties the property values that must be applied to the
58
     *      newly created document object
59
     * @param StreamInterface|null $contentStream the content stream that must be stored
60
     *      for the newly created document object
61
     * @param string|null $checkinComment a version comment
62
     * @param string[] $policies a list of policy IDs that must be applied to the newly created document object
63
     * @param AclInterface|null $addAces a list of ACEs that must be added to the newly created document object
64
     * @param AclInterface|null $removeAces a list of ACEs that must be removed from the newly created document object
65
     * @param ExtensionDataInterface|null $extension
66
     */
67
    public function checkIn(
68
        $repositoryId,
69
        & $objectId,
70
        $major = true,
71
        PropertiesInterface $properties = null,
72
        StreamInterface $contentStream = null,
73
        $checkinComment = null,
74
        array $policies = array(),
75
        AclInterface $addAces = null,
76
        AclInterface $removeAces = null,
77
        ExtensionDataInterface $extension = null
78
    ) {
79
		$queryArray = $this->createQueryArray(
80
			Constants::CMISACTION_CHECK_IN,
81
			array(
82
				Constants::PARAM_MAJOR => $major ? 'true' : 'false',
83
			),
84
			$extension
85
		);
86
		if ($properties) {
87
			$queryArray = array_replace(
88
				$queryArray,
89
				$this->convertPropertiesToQueryArray($properties)
90
			);
91
		}
92
		if ($checkinComment) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $checkinComment of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
93
			$queryArray[Constants::PARAM_CHECKIN_COMMENT] = $checkinComment;
94
		}
95
		if (!empty($policies)) {
96
			$queryArray = array_replace(
97
				$queryArray,
98
				$this->convertPolicyIdArrayToQueryArray($policies)
99
			);
100
		}
101 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...
102
			$queryArray = array_replace($queryArray, $this->convertAclToQueryArray(
103
				$removeAces,
104
				Constants::CONTROL_REMOVE_ACE_PRINCIPAL,
105
				Constants::CONTROL_REMOVE_ACE_PERMISSION
106
			));
107
		}
108 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...
109
			$queryArray = array_replace($queryArray, $this->convertAclToQueryArray(
110
				$addAces,
111
				Constants::CONTROL_ADD_ACE_PRINCIPAL,
112
				Constants::CONTROL_ADD_ACE_PERMISSION
113
			));
114
		}
115
		if ($contentStream) {
116
			$queryArray['content'] = $contentStream;
117
		}
118
		$objectId = $this->getJsonConverter()->convertObject(
119
			$this->post(
120
				$this->getObjectUrl($repositoryId, $objectId),
121
				$queryArray
122
			)->json()
123
        )->getId();
124
    }
125
126
    /**
127
     * Create a private working copy of the document.
128
     *
129
     * @param string $repositoryId the identifier for the repository
130
     * @param string $objectId input: the identifier for the document that should be checked out,
131
     *      output: the identifier for the newly created PWC
132
     * @param ExtensionDataInterface|null $extension
133
     * @param boolean|null $contentCopied output: indicator if the content of the original
134
     *      document has been copied to the PWC
135
     */
136 View Code Duplication
    public function checkOut(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
137
        $repositoryId,
138
        & $objectId,
139
        ExtensionDataInterface $extension = null,
140
        $contentCopied = null
141
    ) {
142
		$objectData = $this->getJsonConverter()->convertObject(
143
			$this->post(
144
				$this->getObjectUrl($repositoryId, $objectId),
145
				$this->createQueryArray(
146
					Constants::CMISACTION_CHECK_OUT,
147
					array(),
148
					$extension
149
				)
150
			)->json()
151
		);
152
		$objectId = $objectData->getId();
153
    }
154
155
    /**
156
     * Returns the list of all document objects in the specified version series,
157
     * sorted by the property "cmis:creationDate" descending.
158
     *
159
     * @param string $repositoryId the identifier for the repository
160
     * @param string $objectId the identifier for the object
161
     * @param string $versionSeriesId the identifier for the object
162
     * @param string|null $filter a comma-separated list of query names that defines which properties must be
163
     *      returned by the repository (default is repository specific)
164
     * @param boolean $includeAllowableActions if <code>true</code>, then the repository must return the allowable
165
     *      actions for the objects (default is <code>false</code>)
166
     * @param ExtensionDataInterface|null $extension
167
     * @return ObjectDataInterface[] the complete version history of the version series
168
     */
169
    public function getAllVersions(
170
        $repositoryId,
171
        $objectId,
172
        $versionSeriesId,
173
        $filter = null,
174
        $includeAllowableActions = false,
175
        ExtensionDataInterface $extension = null
176
    ) {
177
        return $this->getJsonConverter()->convertObjectList(
178
			array(
179
				'objects' => $this->read(
180
					$this->getObjectUrl($repositoryId, $objectId, Constants::SELECTOR_VERSIONS)
181
				)->json()
182
			)
183
		)->getObjects();
184
    }
185
186
    /**
187
     * Get the latest document object in the version series.
188
     *
189
     * @param string $repositoryId the identifier for the repository
190
     * @param string $objectId
191
     * @param string $versionSeriesId
192
     * @param boolean $major
193
     * @param string|null $filter a comma-separated list of query names that defines which properties must be
194
     *      returned by the repository (default is repository specific)
195
     * @param boolean $includeAllowableActions
196
     * @param IncludeRelationships|null $includeRelationships indicates what relationships in which the objects
197
     *      participate must be returned (default is <code>IncludeRelationships::NONE</code>)
198
     * @param string $renditionFilter indicates what set of renditions the repository must return whose kind
199
     *      matches this filter (default is "cmis:none")
200
     * @param boolean $includePolicyIds if <code>true</code>, then the repository must return the policy ids for
201
     *      the object (default is <code>false</code>)
202
     * @param boolean $includeAcl if <code>true</code>, then the repository must return the ACL for the object
203
     *      (default is <code>false</code>)
204
     * @param ExtensionDataInterface|null $extension
205
     * @return ObjectDataInterface
206
     */
207
    public function getObjectOfLatestVersion(
208
        $repositoryId,
209
        $objectId,
210
        $versionSeriesId,
211
        $major = false,
212
        $filter = null,
213
        $includeAllowableActions = false,
214
        IncludeRelationships $includeRelationships = null,
215
        $renditionFilter = Constants::RENDITION_NONE,
216
        $includePolicyIds = false,
217
        $includeAcl = false,
218
        ExtensionDataInterface $extension = null
219
    ) {
220
		return $this->getJsonConverter()->convertObject(
221
			reset(
222
				$this->read(
0 ignored issues
show
Bug introduced by
$this->read($this->getOb...CTOR_VERSIONS))->json() cannot be passed to reset() as the parameter $array expects a reference.
Loading history...
223
					$this->getObjectUrl($repositoryId, $objectId, Constants::SELECTOR_VERSIONS)
224
				)->json()
225
			)
226
		);
227
    }
228
229
    /**
230
     * Get a subset of the properties for the latest document object in the version series.
231
     *
232
     * @param string $repositoryId the identifier for the repository
233
     * @param string $objectId The identifier for the object
234
     * @param string $versionSeriesId The identifier for the version series.
235
     * @param boolean $major If <code>true</code>, then the repository MUST return the properties for the latest
236
     *      major version object in the version series.
237
     *      If <code>false</code>, the repository MUST return the properties for the latest
238
     *      (major or non-major) version object in the version series.
239
     * @param string|null $filter a comma-separated list of query names that defines which properties must be
240
     *      returned by the repository (default is repository specific)
241
     * @param ExtensionDataInterface|null $extension
242
     * @return PropertiesInterface
243
     */
244
    public function getPropertiesOfLatestVersion(
245
        $repositoryId,
246
        $objectId,
247
        $versionSeriesId,
248
        $major = false,
249
        $filter = null,
250
        ExtensionDataInterface $extension = null
251
    ) {
252
        return $this->getObjectOfLatestVersion(
253
			$repositoryId,
254
			$objectId,
255
			$versionSeriesId,
256
			$major,
257
			$filter,
258
			$extension
0 ignored issues
show
Documentation introduced by
$extension is of type null|object<Dkd\PhpCmis\...ExtensionDataInterface>, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
259
		)->getProperties();
260
    }
261
262
	/**
263
	 * @param string $action
264
	 * @param array $parameters
265
	 * @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...
266
	 * @return array
267
	 */
268
	protected function createQueryArray(
269
		$action,
270
		array $parameters = array(),
271
		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...
272
	) {
273
		$queryArray = array_replace(
274
			$parameters,
275
			array(
276
				Constants::CONTROL_CMISACTION => $action,
277
				Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false',
278
			)
279
		);
280
		return $queryArray;
281
	}
282
283
}
284