Passed
Push — master ( 3ba33c...498624 )
by Morris
10:48 queued 12s
created

Sharing::unshare()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 58
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 44
c 1
b 0
f 0
nc 6
nop 1
dl 0
loc 58
rs 8.5937

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
declare(strict_types=1);
3
/**
4
 * @copyright Copyright (c) 2016 Lukas Reschke <[email protected]>
5
 *
6
 * @author Joas Schilling <[email protected]>
7
 * @author Lukas Reschke <[email protected]>
8
 *
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
26
namespace OCA\AdminAudit\Actions;
27
28
29
use OCP\Share;
30
31
/**
32
 * Class Sharing logs the sharing actions
33
 *
34
 * @package OCA\AdminAudit\Actions
35
 */
36
class Sharing extends Action {
37
	/**
38
	 * Logs sharing of data
39
	 *
40
	 * @param array $params
41
	 */
42
	public function shared(array $params) {
43
		if($params['shareType'] === Share::SHARE_TYPE_LINK) {
44
			$this->log(
45
				'The %s "%s" with ID "%s" has been shared via link with permissions "%s" (Share ID: %s)',
46
				$params,
47
				[
48
					'itemType',
49
					'itemTarget',
50
					'itemSource',
51
					'permissions',
52
					'id',
53
				]
54
			);
55
		} elseif($params['shareType'] === Share::SHARE_TYPE_USER) {
56
			$this->log(
57
				'The %s "%s" with ID "%s" has been shared to the user "%s" with permissions "%s"  (Share ID: %s)',
58
				$params,
59
				[
60
					'itemType',
61
					'itemTarget',
62
					'itemSource',
63
					'shareWith',
64
					'permissions',
65
					'id',
66
				]
67
			);
68
		} elseif($params['shareType'] === Share::SHARE_TYPE_GROUP) {
69
			$this->log(
70
				'The %s "%s" with ID "%s" has been shared to the group "%s" with permissions "%s"  (Share ID: %s)',
71
				$params,
72
				[
73
					'itemType',
74
					'itemTarget',
75
					'itemSource',
76
					'shareWith',
77
					'permissions',
78
					'id',
79
				]
80
			);
81
		} elseif($params['shareType'] === Share::SHARE_TYPE_ROOM) {
82
			$this->log(
83
				'The %s "%s" with ID "%s" has been shared to the room "%s" with permissions "%s" (Share ID: %s)',
84
				$params,
85
				[
86
					'itemType',
87
					'itemTarget',
88
					'itemSource',
89
					'shareWith',
90
					'permissions',
91
					'id',
92
				]
93
			);
94
		} elseif($params['shareType'] === Share::SHARE_TYPE_EMAIL) {
95
			$this->log(
96
				'The %s "%s" with ID "%s" has been shared to the email recipient "%s" with permissions "%s" (Share ID: %s)',
97
				$params,
98
				[
99
					'itemType',
100
					'itemTarget',
101
					'itemSource',
102
					'shareWith',
103
					'permissions',
104
					'id',
105
				]
106
			);			
107
		}
108
	}
109
110
	/**
111
	 * Logs unsharing of data
112
	 *
113
	 * @param array $params
114
	 */
115
	public function unshare(array $params) {
116
		if($params['shareType'] === Share::SHARE_TYPE_LINK) {
117
			$this->log(
118
				'The %s "%s" with ID "%s" has been unshared (Share ID: %s)',
119
				$params,
120
				[
121
					'itemType',
122
					'fileTarget',
123
					'itemSource',
124
					'id',
125
				]
126
			);
127
		} elseif($params['shareType'] === Share::SHARE_TYPE_USER) {
128
			$this->log(
129
				'The %s "%s" with ID "%s" has been unshared from the user "%s" (Share ID: %s)',
130
				$params,
131
				[
132
					'itemType',
133
					'fileTarget',
134
					'itemSource',
135
					'shareWith',
136
					'id',
137
				]
138
			);
139
		} elseif($params['shareType'] === Share::SHARE_TYPE_GROUP) {
140
			$this->log(
141
				'The %s "%s" with ID "%s" has been unshared from the group "%s" (Share ID: %s)',
142
				$params,
143
				[
144
					'itemType',
145
					'fileTarget',
146
					'itemSource',
147
					'shareWith',
148
					'id',
149
				]
150
			);
151
		} elseif($params['shareType'] === Share::SHARE_TYPE_ROOM) {
152
			$this->log(
153
				'The %s "%s" with ID "%s" has been unshared from the room "%s" (Share ID: %s)',
154
				$params,
155
				[
156
					'itemType',
157
					'fileTarget',
158
					'itemSource',
159
					'shareWith',
160
					'id',
161
				]
162
			);
163
		} elseif($params['shareType'] === Share::SHARE_TYPE_EMAIL) {
164
			$this->log(
165
				'The %s "%s" with ID "%s" has been unshared from the email recipient "%s" (Share ID: %s)',
166
				$params,
167
				[
168
					'itemType',
169
					'fileTarget',
170
					'itemSource',
171
					'shareWith',
172
					'id',
173
				]
174
			);			
175
		}
176
	}
177
178
	/**
179
	 * Logs the updating of permission changes for shares
180
	 *
181
	 * @param array $params
182
	 */
183
	public function updatePermissions(array $params) {
184
		$this->log(
185
			'The permissions of the shared %s "%s" with ID "%s" have been changed to "%s"',
186
			$params,
187
			[
188
				'itemType',
189
				'path',
190
				'itemSource',
191
				'permissions',
192
			]
193
		);
194
	}
195
196
	/**
197
	 * Logs the password changes for a share
198
	 *
199
	 * @param array $params
200
	 */
201
	public function updatePassword(array $params) {
202
		$this->log(
203
			'The password of the publicly shared %s "%s" with ID "%s" has been changed',
204
			$params,
205
			[
206
				'itemType',
207
				'token',
208
				'itemSource',
209
			]
210
		);
211
	}
212
213
	/**
214
	 * Logs the expiration date changes for a share
215
	 *
216
	 * @param array $params
217
	 */
218
	public function updateExpirationDate(array $params) {
219
		$this->log(
220
			'The expiration date of the publicly shared %s with ID "%s" has been changed to "%s"',
221
			$params,
222
			[
223
				'itemType',
224
				'itemSource',
225
				'date',
226
			]
227
		);
228
	}
229
230
	/**
231
	 * Logs access of shared files
232
	 *
233
	 * @param array $params
234
	 */
235
	public function shareAccessed(array $params) {
236
		$this->log(
237
			'The shared %s with the token "%s" by "%s" has been accessed.',
238
			$params,
239
			[
240
				'itemType',
241
				'token',
242
				'uidOwner',
243
			]
244
		);
245
	}
246
}
247