Passed
Push — master ( 2e2d1b...edf9de )
by Roeland
13:36
created

Sharing::shared()   C

Complexity

Conditions 9
Paths 9

Size

Total Lines 102
Code Lines 79

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 9
eloc 79
c 2
b 0
f 0
nc 9
nop 1
dl 0
loc 102
rs 6.9026

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
		} elseif($params['shareType'] === Share::SHARE_TYPE_CIRCLE) {
108
			$this->log(
109
				'The %s "%s" with ID "%s" has been shared to the circle "%s" with permissions "%s" (Share ID: %s)',
110
				$params,
111
				[
112
					'itemType',
113
					'itemTarget',
114
					'itemSource',
115
					'shareWith',
116
					'permissions',
117
					'id',
118
				]
119
			);
120
		} elseif($params['shareType'] === Share::SHARE_TYPE_REMOTE) {
121
			$this->log(
122
				'The %s "%s" with ID "%s" has been shared to the remote user "%s" with permissions "%s" (Share ID: %s)',
123
				$params,
124
				[
125
					'itemType',
126
					'itemTarget',
127
					'itemSource',
128
					'shareWith',
129
					'permissions',
130
					'id',
131
				]
132
			);
133
		} elseif($params['shareType'] === Share::SHARE_TYPE_REMOTE_GROUP) {
134
			$this->log(
135
				'The %s "%s" with ID "%s" has been shared to the remote group "%s" with permissions "%s" (Share ID: %s)',
136
				$params,
137
				[
138
					'itemType',
139
					'itemTarget',
140
					'itemSource',
141
					'shareWith',
142
					'permissions',
143
					'id',
144
				]
145
			);
146
		}
147
	}
148
149
	/**
150
	 * Logs unsharing of data
151
	 *
152
	 * @param array $params
153
	 */
154
	public function unshare(array $params) {
155
		if($params['shareType'] === Share::SHARE_TYPE_LINK) {
156
			$this->log(
157
				'The %s "%s" with ID "%s" has been unshared (Share ID: %s)',
158
				$params,
159
				[
160
					'itemType',
161
					'fileTarget',
162
					'itemSource',
163
					'id',
164
				]
165
			);
166
		} elseif($params['shareType'] === Share::SHARE_TYPE_USER) {
167
			$this->log(
168
				'The %s "%s" with ID "%s" has been unshared from the user "%s" (Share ID: %s)',
169
				$params,
170
				[
171
					'itemType',
172
					'fileTarget',
173
					'itemSource',
174
					'shareWith',
175
					'id',
176
				]
177
			);
178
		} elseif($params['shareType'] === Share::SHARE_TYPE_GROUP) {
179
			$this->log(
180
				'The %s "%s" with ID "%s" has been unshared from the group "%s" (Share ID: %s)',
181
				$params,
182
				[
183
					'itemType',
184
					'fileTarget',
185
					'itemSource',
186
					'shareWith',
187
					'id',
188
				]
189
			);
190
		} elseif($params['shareType'] === Share::SHARE_TYPE_ROOM) {
191
			$this->log(
192
				'The %s "%s" with ID "%s" has been unshared from the room "%s" (Share ID: %s)',
193
				$params,
194
				[
195
					'itemType',
196
					'fileTarget',
197
					'itemSource',
198
					'shareWith',
199
					'id',
200
				]
201
			);
202
		} elseif($params['shareType'] === Share::SHARE_TYPE_EMAIL) {
203
			$this->log(
204
				'The %s "%s" with ID "%s" has been unshared from the email recipient "%s" (Share ID: %s)',
205
				$params,
206
				[
207
					'itemType',
208
					'fileTarget',
209
					'itemSource',
210
					'shareWith',
211
					'id',
212
				]
213
			);
214
		} elseif($params['shareType'] === Share::SHARE_TYPE_CIRCLE) {
215
			$this->log(
216
				'The %s "%s" with ID "%s" has been unshared from the circle "%s" (Share ID: %s)',
217
				$params,
218
				[
219
					'itemType',
220
					'fileTarget',
221
					'itemSource',
222
					'shareWith',
223
					'id',
224
				]
225
			);
226
		} elseif($params['shareType'] === Share::SHARE_TYPE_REMOTE) {
227
			$this->log(
228
				'The %s "%s" with ID "%s" has been unshared from the remote user "%s" (Share ID: %s)',
229
				$params,
230
				[
231
					'itemType',
232
					'fileTarget',
233
					'itemSource',
234
					'shareWith',
235
					'id',
236
				]
237
			);
238
		} elseif($params['shareType'] === Share::SHARE_TYPE_REMOTE_GROUP) {
239
			$this->log(
240
				'The %s "%s" with ID "%s" has been unshared from the remote group "%s" (Share ID: %s)',
241
				$params,
242
				[
243
					'itemType',
244
					'fileTarget',
245
					'itemSource',
246
					'shareWith',
247
					'id',
248
				]
249
			);
250
		}
251
	}
252
253
	/**
254
	 * Logs the updating of permission changes for shares
255
	 *
256
	 * @param array $params
257
	 */
258
	public function updatePermissions(array $params) {
259
		$this->log(
260
			'The permissions of the shared %s "%s" with ID "%s" have been changed to "%s"',
261
			$params,
262
			[
263
				'itemType',
264
				'path',
265
				'itemSource',
266
				'permissions',
267
			]
268
		);
269
	}
270
271
	/**
272
	 * Logs the password changes for a share
273
	 *
274
	 * @param array $params
275
	 */
276
	public function updatePassword(array $params) {
277
		$this->log(
278
			'The password of the publicly shared %s "%s" with ID "%s" has been changed',
279
			$params,
280
			[
281
				'itemType',
282
				'token',
283
				'itemSource',
284
			]
285
		);
286
	}
287
288
	/**
289
	 * Logs the expiration date changes for a share
290
	 *
291
	 * @param array $params
292
	 */
293
	public function updateExpirationDate(array $params) {
294
		$this->log(
295
			'The expiration date of the publicly shared %s with ID "%s" has been changed to "%s"',
296
			$params,
297
			[
298
				'itemType',
299
				'itemSource',
300
				'date',
301
			]
302
		);
303
	}
304
305
	/**
306
	 * Logs access of shared files
307
	 *
308
	 * @param array $params
309
	 */
310
	public function shareAccessed(array $params) {
311
		$this->log(
312
			'The shared %s with the token "%s" by "%s" has been accessed.',
313
			$params,
314
			[
315
				'itemType',
316
				'token',
317
				'uidOwner',
318
			]
319
		);
320
	}
321
}
322