Completed
Push — stable8.2 ( 3eaa45...4ae337 )
by Thomas
13:54
created

Sharing::saveLastShareId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
nc 1
dl 0
loc 4
cc 1
eloc 2
nop 0
rs 10
1
<?php
2
3
use GuzzleHttp\Client;
4
use GuzzleHttp\Message\ResponseInterface;
5
6
require __DIR__ . '/../../vendor/autoload.php';
7
8
9
10
trait Sharing {
11
	use Provisioning;
12
13
	/** @var int */
14
	private $sharingApiVersion = 1;
15
16
	/** @var SimpleXMLElement */
17
	private $lastShareData = null;
18
19
	/** @var int */
20
	private $savedShareId = null;
21
22
	/**
23
	 * @Given /^as "([^"]*)" creating a share with$/
24
	 * @param string $user
25
	 * @param \Behat\Gherkin\Node\TableNode|null $body
26
	 */
27
	public function asCreatingAShareWith($user, $body) {
28
		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares";
29
		$client = new Client();
30
		$options = [];
31
		if ($user === 'admin') {
32
			$options['auth'] = $this->adminUser;
0 ignored issues
show
Bug introduced by
The property adminUser does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
33
		} else {
34
			$options['auth'] = [$user, $this->regularUser];
0 ignored issues
show
Bug introduced by
The property regularUser does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
35
		}
36
37 View Code Duplication
		if ($body instanceof \Behat\Gherkin\Node\TableNode) {
0 ignored issues
show
Bug introduced by
The class Behat\Gherkin\Node\TableNode does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
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...
38
			$fd = $body->getRowsHash();
39
			if (array_key_exists('expireDate', $fd)){
40
				$dateModification = $fd['expireDate'];
41
				$fd['expireDate'] = date('Y-m-d', strtotime($dateModification));
42
			}
43
			$options['body'] = $fd;
44
		}
45
46
		try {
47
			$this->response = $client->send($client->createRequest("POST", $fullUrl, $options));
48
		} catch (\GuzzleHttp\Exception\ClientException $ex) {
0 ignored issues
show
Bug introduced by
The class GuzzleHttp\Exception\ClientException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
49
			$this->response = $ex->getResponse();
50
		}
51
52
		$this->lastShareData = $this->response->xml();
53
	}
54
55
	/**
56
	 * @When /^creating a share with$/
57
	 * @param \Behat\Gherkin\Node\TableNode|null $body
58
	 */
59
	public function creatingShare($body) {
60
		$this->asCreatingAShareWith($this->currentUser, $body);
61
	}
62
63
	/**
64
	 * @Then /^Public shared file "([^"]*)" can be downloaded$/
65
	 */
66
	public function checkPublicSharedFile($filename) {
67
		$client = new Client();
68
		$options = [];
69 View Code Duplication
		if (count($this->lastShareData->data->element) > 0){
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...
70
			$url = $this->lastShareData->data[0]->url;
71
		}
72
		else{
73
			$url = $this->lastShareData->data->url;
74
		}
75
		$fullUrl = $url . "/download";
76
		$options['save_to'] = "./$filename";
77
		$this->response = $client->get($fullUrl, $options);
78
		$finfo = new finfo;
79
		$fileinfo = $finfo->file("./$filename", FILEINFO_MIME_TYPE);
80
		PHPUnit_Framework_Assert::assertEquals($fileinfo, "text/plain");
81
		if (file_exists("./$filename")) {
82
			unlink("./$filename");
83
		}
84
	}
85
86
	/**
87
	 * @Then /^Public shared file "([^"]*)" with password "([^"]*)" can be downloaded$/
88
	 */
89
	public function checkPublicSharedFileWithPassword($filename, $password) {
90
		$client = new Client();
91
		$options = [];
92 View Code Duplication
		if (count($this->lastShareData->data->element) > 0){
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...
93
			$token = $this->lastShareData->data[0]->token;
94
		}
95
		else{
96
			$token = $this->lastShareData->data->token;
97
		}
98
99
		$fullUrl = substr($this->baseUrl, 0, -4) . "public.php/webdav";
100
		$options['auth'] = [$token, $password];
101
		$options['save_to'] = "./$filename";
102
		$this->response = $client->get($fullUrl, $options);
103
		$finfo = new finfo;
104
		$fileinfo = $finfo->file("./$filename", FILEINFO_MIME_TYPE);
105
		PHPUnit_Framework_Assert::assertEquals($fileinfo, "text/plain");
106
		if (file_exists("./$filename")) {
107
			unlink("./$filename");
108
		}
109
	}
110
111
	/**
112
	 * @When /^Adding expiration date to last share$/
113
	 */
114
	public function addingExpirationDate() {
115
		$share_id = (string) $this->lastShareData->data[0]->id;
116
		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/$share_id";
117
		$client = new Client();
118
		$options = [];
119 View Code Duplication
		if ($this->currentUser === 'admin') {
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...
120
			$options['auth'] = $this->adminUser;
121
		} else {
122
			$options['auth'] = [$this->currentUser, $this->regularUser];
123
		}
124
		$date = date('Y-m-d', strtotime("+3 days"));
125
		$options['body'] = ['expireDate' => $date];
126
		$this->response = $client->send($client->createRequest("PUT", $fullUrl, $options));
127
		PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
128
	}
129
130
	/**
131
	 * @When /^Updating last share with$/
132
	 * @param \Behat\Gherkin\Node\TableNode|null $body
133
	 */
134
	public function updatingLastShare($body) {
135
		$share_id = (string) $this->lastShareData->data[0]->id;
136
		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/$share_id";
137
		$client = new Client();
138
		$options = [];
139 View Code Duplication
		if ($this->currentUser === 'admin') {
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...
140
			$options['auth'] = $this->adminUser;
141
		} else {
142
			$options['auth'] = [$this->currentUser, $this->regularUser];
143
		}
144
145 View Code Duplication
		if ($body instanceof \Behat\Gherkin\Node\TableNode) {
0 ignored issues
show
Bug introduced by
The class Behat\Gherkin\Node\TableNode does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
146
			$fd = $body->getRowsHash();
147
			if (array_key_exists('expireDate', $fd)){
148
				$dateModification = $fd['expireDate'];
149
				$fd['expireDate'] = date('Y-m-d', strtotime($dateModification));
150
			}
151
			$options['body'] = $fd;
152
		}
153
154
		try {
155
			$this->response = $client->send($client->createRequest("PUT", $fullUrl, $options));
156
		} catch (\GuzzleHttp\Exception\ClientException $ex) {
0 ignored issues
show
Bug introduced by
The class GuzzleHttp\Exception\ClientException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
157
			$this->response = $ex->getResponse();
158
		}
159
160
		PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
161
	}
162
163
	public function createShare($user,
164
								$path = null,
165
								$shareType = null,
166
								$shareWith = null,
167
								$publicUpload = null,
168
								$password = null,
169
								$permissions = null){
170
		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares";
171
		$client = new Client();
172
		$options = [];
173
174
		if ($user === 'admin') {
175
			$options['auth'] = $this->adminUser;
176
		} else {
177
			$options['auth'] = [$user, $this->regularUser];
178
		}
179
		$fd = [];
180
		if (!is_null($path)){
181
			$fd['path'] = $path;
182
		}
183
		if (!is_null($shareType)){
184
			$fd['shareType'] = $shareType;
185
		}
186
		if (!is_null($shareWith)){
187
			$fd['shareWith'] = $shareWith;
188
		}
189
		if (!is_null($publicUpload)){
190
			$fd['publicUpload'] = $publicUpload;
191
		}
192
		if (!is_null($password)){
193
			$fd['password'] = $password;
194
		}
195
		if (!is_null($permissions)){
196
			$fd['permissions'] = $permissions;
197
		}
198
199
		$options['body'] = $fd;
200
201
		try {
202
			$this->response = $client->send($client->createRequest("POST", $fullUrl, $options));
203
			$this->lastShareData = $this->response->xml();
204
		} catch (\GuzzleHttp\Exception\ClientException $ex) {
0 ignored issues
show
Bug introduced by
The class GuzzleHttp\Exception\ClientException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
205
			$this->response = $ex->getResponse();
206
		}
207
	}
208
209
	public function isFieldInResponse($field, $contentExpected){
210
		$data = $this->response->xml()->data[0];
211
		if ((string)$field == 'expiration'){
212
			$contentExpected = date('Y-m-d', strtotime($contentExpected)) . " 00:00:00";
213
		}
214
215
		if (count($data->element) > 0){
216
			foreach($data as $element) {
217 View Code Duplication
				if ($contentExpected == "A_TOKEN"){
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...
218
					return (strlen((string)$element->$field) == 15);
219
				}
220
				elseif ($contentExpected == "A_NUMBER"){
221
					return is_numeric((string)$element->$field);
222
				}
223
				elseif($contentExpected == "AN_URL"){
224
					return $this->isExpectedUrl((string)$element->$field, "index.php/s/");
225
				}
226
				elseif ((string)$element->$field == $contentExpected){
227
					return True;
228
				}
229
				else{
230
					print($element->$field);
231
				}
232
			}
233
234
			return False;
235
		} else {
236 View Code Duplication
			if ($contentExpected == "A_TOKEN"){
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...
237
					return (strlen((string)$data->$field) == 15);
238
			}
239
			elseif ($contentExpected == "A_NUMBER"){
240
					return is_numeric((string)$data->$field);
241
			}
242
			elseif($contentExpected == "AN_URL"){
243
					return $this->isExpectedUrl((string)$data->$field, "index.php/s/");
244
			}
245
			elseif ($data->$field == $contentExpected){
246
					return True;
247
			}
248
			return False;
249
		}
250
	}
251
252
	/**
253
	 * @Then /^File "([^"]*)" should be included in the response$/
254
	 *
255
	 * @param string $filename
256
	 */
257
	public function checkSharedFileInResponse($filename){
258
		PHPUnit_Framework_Assert::assertEquals(True, $this->isFieldInResponse('file_target', "/$filename"));
259
	}
260
261
	/**
262
	 * @Then /^File "([^"]*)" should not be included in the response$/
263
	 *
264
	 * @param string $filename
265
	 */
266
	public function checkSharedFileNotInResponse($filename){
267
		PHPUnit_Framework_Assert::assertEquals(False, $this->isFieldInResponse('file_target', "/$filename"));
268
	}
269
270
	/**
271
	 * @Then /^User "([^"]*)" should be included in the response$/
272
	 *
273
	 * @param string $user
274
	 */
275
	public function checkSharedUserInResponse($user){
276
		PHPUnit_Framework_Assert::assertEquals(True, $this->isFieldInResponse('share_with', "$user"));
277
	}
278
279
	/**
280
	 * @Then /^User "([^"]*)" should not be included in the response$/
281
	 *
282
	 * @param string $user
283
	 */
284
	public function checkSharedUserNotInResponse($user){
285
		PHPUnit_Framework_Assert::assertEquals(False, $this->isFieldInResponse('share_with', "$user"));
286
	}
287
288
	public function isUserOrGroupInSharedData($userOrGroup){
289
		$data = $this->response->xml()->data[0];
290
		foreach($data as $element) {
291
			if ($element->share_with == $userOrGroup){
292
				return True;
293
			}
294
		}
295
		return False;
296
	}
297
298
	/**
299
	 * @Given /^file "([^"]*)" of user "([^"]*)" is shared with user "([^"]*)"$/
300
	 *
301
	 * @param string $filepath
302
	 * @param string $user1
303
	 * @param string $user2
304
	 */
305 View Code Duplication
	public function assureFileIsShared($filepath, $user1, $user2){
306
		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares" . "?path=$filepath";
307
		$client = new Client();
308
		$options = [];
309
		if ($user1 === 'admin') {
310
			$options['auth'] = $this->adminUser;
311
		} else {
312
			$options['auth'] = [$user1, $this->regularUser];
313
		}
314
		$this->response = $client->get($fullUrl, $options);
315
		if ($this->isUserOrGroupInSharedData($user2)){
316
			return;
317
		} else {
318
			$this->createShare($user1, $filepath, 0, $user2, null, null, null);
319
		}
320
		$this->response = $client->get($fullUrl, $options);
321
		PHPUnit_Framework_Assert::assertEquals(True, $this->isUserOrGroupInSharedData($user2));
322
	}
323
324
	/**
325
	 * @Given /^file "([^"]*)" of user "([^"]*)" is shared with group "([^"]*)"$/
326
	 *
327
	 * @param string $filepath
328
	 * @param string $user
329
	 * @param string $group
330
	 */
331 View Code Duplication
	public function assureFileIsSharedWithGroup($filepath, $user, $group){
332
		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares" . "?path=$filepath";
333
		$client = new Client();
334
		$options = [];
335
		if ($user === 'admin') {
336
			$options['auth'] = $this->adminUser;
337
		} else {
338
			$options['auth'] = [$user, $this->regularUser];
339
		}
340
		$this->response = $client->get($fullUrl, $options);
341
		if ($this->isUserOrGroupInSharedData($group)){
342
			return;
343
		} else {
344
			$this->createShare($user, $filepath, 1, $group, null, null, null);
345
		}
346
		$this->response = $client->get($fullUrl, $options);
347
		PHPUnit_Framework_Assert::assertEquals(True, $this->isUserOrGroupInSharedData($group));
348
	}
349
350
	/**
351
	 * @When /^Deleting last share$/
352
	 */
353
	public function deletingLastShare(){
354
		$share_id = $this->lastShareData->data[0]->id;
355
		$url = "/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/$share_id";
356
		$this->sendingToWith("DELETE", $url, null);
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Behat\Gherkin\Node\TableNode>.

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...
357
	}
358
359
	/**
360
	 * @When /^Getting info of last share$/
361
	 */
362
	public function gettingInfoOfLastShare(){
363
		$share_id = $this->lastShareData->data[0]->id;
364
		$url = "/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/$share_id";
365
		$this->sendingToWith("GET", $url, null);
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Behat\Gherkin\Node\TableNode>.

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...
366
	}
367
368
	/**
369
	 * @Then /^last share_id is included in the answer$/
370
	 */
371
	public function checkingLastShareIDIsIncluded(){
372
		$share_id = $this->lastShareData->data[0]->id;
373
		if (!$this->isFieldInResponse('id', $share_id)){
374
			PHPUnit_Framework_Assert::fail("Share id $share_id not found in response");
375
		}
376
	}
377
378
	/**
379
	 * @Then /^last share_id is included in the answer as parent$/
380
	 */
381 View Code Duplication
	public function checkingLastShareIDIsIncludedAsParent(){
382
		$share_id = $this->lastShareData->data[0]->id;
383
		//This is a problem before 9.0, setupFS is called with every api call so a new share id is created
384
		//we just need to check the parent id to match with the returned id.
385
		if (!$this->isFieldInResponse('parent', $share_id)){
386
			PHPUnit_Framework_Assert::fail("Share id $share_id not found in response as parent");
387
		}
388
	}
389
390
	/**
391
	 * @Then /^last share_id is not included in the answer$/
392
	 */
393
	public function checkingLastShareIDIsNotIncluded(){
394
		$share_id = $this->lastShareData->data[0]->id;
395
		if ($this->isFieldInResponse('id', $share_id)){
396
			PHPUnit_Framework_Assert::fail("Share id $share_id has been found in response");
397
		}
398
	}
399
400
	/**
401
	 * @Then /^last share_id is not included in the answer as parent$/
402
	 */
403 View Code Duplication
	public function checkingLastShareIDIsNotIncludedAsParent(){
404
		$share_id = $this->lastShareData->data[0]->id;
405
		//This is a problem before 9.0, setupFS is called with every api call so a new share id is created
406
		//we just need to check the parent id to match with the returned id.
407
		if ($this->isFieldInResponse('parent', $share_id)){
408
			PHPUnit_Framework_Assert::fail("Share id $share_id has been found in response as parent");
409
		}
410
	}
411
412
	/**
413
	 * @Then /^Share fields of last share match with$/
414
	 * @param \Behat\Gherkin\Node\TableNode|null $body
415
	 */
416
	public function checkShareFields($body){
417
		if ($body instanceof \Behat\Gherkin\Node\TableNode) {
0 ignored issues
show
Bug introduced by
The class Behat\Gherkin\Node\TableNode does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
418
			$fd = $body->getRowsHash();
419
420
			foreach($fd as $field => $value) {
421 View Code Duplication
				if (substr($field, 0, 10 ) === "share_with"){
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...
422
					$value = str_replace("REMOTE", substr($this->remoteBaseUrl, 0, -5), $value);
0 ignored issues
show
Bug introduced by
The property remoteBaseUrl does not seem to exist. Did you mean baseUrl?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
423
					$value = str_replace("LOCAL", substr($this->localBaseUrl, 0, -5), $value);
0 ignored issues
show
Bug introduced by
The property localBaseUrl does not seem to exist. Did you mean baseUrl?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
424
				}
425 View Code Duplication
				if (substr($field, 0, 6 ) === "remote"){
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...
426
					$value = str_replace("REMOTE", substr($this->remoteBaseUrl, 0, -4), $value);
0 ignored issues
show
Bug introduced by
The property remoteBaseUrl does not seem to exist. Did you mean baseUrl?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
427
					$value = str_replace("LOCAL", substr($this->localBaseUrl, 0, -4), $value);
0 ignored issues
show
Bug introduced by
The property localBaseUrl does not seem to exist. Did you mean baseUrl?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
428
				}
429
				if (!$this->isFieldInResponse($field, $value)){
430
					PHPUnit_Framework_Assert::fail("$field" . " doesn't have value " . "$value");
431
				}
432
			}
433
		}
434
	}
435
436
	/**
437
	 * @Then As :user remove all shares from the file named :fileName
438
	 */
439
	public function asRemoveAllSharesFromTheFileNamed($user, $fileName) {
440
		$url = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares?format=json";
441
		$client = new \GuzzleHttp\Client();
442
		$res = $client->get(
443
			$url,
444
			[
445
				'auth' => [
446
					$user,
447
					'123456',
448
				],
449
				'headers' => [
450
					'Content-Type' => 'application/json',
451
				],
452
			]
453
		);
454
		$json = json_decode($res->getBody()->getContents(), true);
455
		$deleted = false;
456
		foreach($json['ocs']['data'] as $data) {
457
			if (stripslashes($data['path']) === $fileName) {
458
				$id = $data['id'];
459
				$client->delete(
460
					$this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/{$id}",
461
					[
462
						'auth' => [
463
							$user,
464
							'123456',
465
						],
466
						'headers' => [
467
							'Content-Type' => 'application/json',
468
						],
469
					]
470
				);
471
				$deleted = true;
472
			}
473
		}
474
475
		if($deleted === false) {
476
			throw new \Exception("Could not delete file $fileName");
477
		}
478
	}
479
480
	/**
481
	 * @When save last share id
482
	 */
483
	public function saveLastShareId()
484
	{
485
		$this->savedShareId = $this->lastShareData['data']['id'];
486
	}
487
488
	/**
489
	 * @Then share ids should match
490
	 */
491
	public function shareIdsShouldMatch()
492
	{
493
		if ($this->savedShareId !== $this->lastShareData['data']['id']) {
494
			throw new \Exception('Expected the same link share to be returned');
495
		}
496
	}
497
}
498
499