Completed
Push — master ( 4f3689...17b456 )
by Maxence
02:12 queued 11s
created

MountManager   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 76
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A renameShare() 0 21 4
A unshare() 0 3 1
A stripPath() 0 5 1
1
<?php declare(strict_types=1);
2
3
4
/**
5
 * Circles - Bring cloud-users closer together.
6
 *
7
 * This file is licensed under the Affero General Public License version 3 or
8
 * later. See the COPYING file.
9
 *
10
 * @author Maxence Lange <[email protected]>
11
 * @copyright 2020
12
 * @license GNU AGPL version 3 or any later version
13
 *
14
 * This program is free software: you can redistribute it and/or modify
15
 * it under the terms of the GNU Affero General Public License as
16
 * published by the Free Software Foundation, either version 3 of the
17
 * License, or (at your option) any later version.
18
 *
19
 * This program is distributed in the hope that it will be useful,
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 * GNU Affero General Public License for more details.
23
 *
24
 * You should have received a copy of the GNU Affero General Public License
25
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
26
 *
27
 */
28
29
30
namespace OCA\Circles\GlobalScale\GSMount;
31
32
33
use OCA\Circles\Db\GSSharesRequest;
34
use OCA\Circles\Model\GlobalScale\GSShareMountpoint;
35
use OCP\Share\Exceptions\ShareNotFound;
36
37
38
/**
39
 * Class MountManager
40
 *
41
 * @package OCA\Circles\GlobalScale\GSMount
42
 */
43
class MountManager {
44
45
46
	/** @var string */
47
	private $userId;
48
49
	/** @var GSSharesRequest */
50
	private $gsSharesRequest;
51
52
53
	/**
54
	 * MountManager constructor.
55
	 *
56
	 * @param string $userId
57
	 * @param GSSharesRequest $gsSharesRequest
58
	 */
59
	public function __construct($userId, GSSharesRequest $gsSharesRequest) {
60
		$this->userId = $userId;
61
		$this->gsSharesRequest = $gsSharesRequest;
62
	}
63
64
65
	/**
66
	 * @param int $gsShareId
67
	 * @param string $target
68
	 *
69
	 * @return bool
70
	 */
71
	public function renameShare(int $gsShareId, string $target) {
72
		try {
73
			if ($target !== '-') {
74
				$target = $this->stripPath($target);
75
				$this->gsSharesRequest->getShareMountPointByPath($this->userId, $target);
76
77
				return false;
78
			}
79
		} catch (ShareNotFound $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
Bug introduced by
The class OCP\Share\Exceptions\ShareNotFound 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...
80
		}
81
82
		$mountPoint = new GSShareMountpoint($gsShareId, $this->userId, $target);
83
		try {
84
			$this->gsSharesRequest->getShareMountPointById($gsShareId, $this->userId);
85
			$this->gsSharesRequest->updateShareMountPoint($mountPoint);
86
		} catch (ShareNotFound $e) {
0 ignored issues
show
Bug introduced by
The class OCP\Share\Exceptions\ShareNotFound 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...
87
			$this->gsSharesRequest->generateShareMountPoint($mountPoint);
88
		}
89
90
		return true;
91
	}
92
93
94
	/**
95
	 * @param int $gsShareId
96
	 *
97
	 * @return bool
98
	 */
99
	public function unshare(int $gsShareId) {
100
		return $this->renameShare($gsShareId, '-');
101
	}
102
103
104
	/**
105
	 * remove '/user/files' from the path and trailing slashes
106
	 *
107
	 * @param string $path
108
	 *
109
	 * @return string
110
	 */
111
	protected function stripPath($path) {
112
		$prefix = '/' . $this->userId . '/files';
113
114
		return rtrim(substr($path, strlen($prefix)), '/');
115
	}
116
117
118
}
119