Completed
Push — master ( ca0f2f...6aa6d2 )
by Björn
33:52 queued 15:38
created

Sharing::shared()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 54

Duplication

Lines 14
Ratio 25.93 %

Importance

Changes 0
Metric Value
cc 5
nc 5
nop 1
dl 14
loc 54
rs 8.6925
c 0
b 0
f 0

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 View Code Duplication
		} 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
		}
95
	}
96
97
	/**
98
	 * Logs unsharing of data
99
	 *
100
	 * @param array $params
101
	 */
102
	public function unshare(array $params) {
103
		if($params['shareType'] === Share::SHARE_TYPE_LINK) {
104
			$this->log(
105
				'The %s "%s" with ID "%s" has been unshared (Share ID: %s)',
106
				$params,
107
				[
108
					'itemType',
109
					'fileTarget',
110
					'itemSource',
111
					'id',
112
				]
113
			);
114 View Code Duplication
		} elseif($params['shareType'] === Share::SHARE_TYPE_USER) {
115
			$this->log(
116
				'The %s "%s" with ID "%s" has been unshared from the user "%s" (Share ID: %s)',
117
				$params,
118
				[
119
					'itemType',
120
					'fileTarget',
121
					'itemSource',
122
					'shareWith',
123
					'id',
124
				]
125
			);
126
		} elseif($params['shareType'] === Share::SHARE_TYPE_GROUP) {
127
			$this->log(
128
				'The %s "%s" with ID "%s" has been unshared from the group "%s" (Share ID: %s)',
129
				$params,
130
				[
131
					'itemType',
132
					'fileTarget',
133
					'itemSource',
134
					'shareWith',
135
					'id',
136
				]
137
			);
138 View Code Duplication
		} elseif($params['shareType'] === Share::SHARE_TYPE_ROOM) {
139
			$this->log(
140
				'The %s "%s" with ID "%s" has been unshared from the room "%s" (Share ID: %s)',
141
				$params,
142
				[
143
					'itemType',
144
					'fileTarget',
145
					'itemSource',
146
					'shareWith',
147
					'id',
148
				]
149
			);
150
		}
151
	}
152
153
	/**
154
	 * Logs the updating of permission changes for shares
155
	 *
156
	 * @param array $params
157
	 */
158
	public function updatePermissions(array $params) {
159
		$this->log(
160
			'The permissions of the shared %s "%s" with ID "%s" have been changed to "%s"',
161
			$params,
162
			[
163
				'itemType',
164
				'path',
165
				'itemSource',
166
				'permissions',
167
			]
168
		);
169
	}
170
171
	/**
172
	 * Logs the password changes for a share
173
	 *
174
	 * @param array $params
175
	 */
176
	public function updatePassword(array $params) {
177
		$this->log(
178
			'The password of the publicly shared %s "%s" with ID "%s" has been changed',
179
			$params,
180
			[
181
				'itemType',
182
				'token',
183
				'itemSource',
184
			]
185
		);
186
	}
187
188
	/**
189
	 * Logs the expiration date changes for a share
190
	 *
191
	 * @param array $params
192
	 */
193
	public function updateExpirationDate(array $params) {
194
		$this->log(
195
			'The expiration date of the publicly shared %s with ID "%s" has been changed to "%s"',
196
			$params,
197
			[
198
				'itemType',
199
				'itemSource',
200
				'date',
201
			]
202
		);
203
	}
204
205
	/**
206
	 * Logs access of shared files
207
	 *
208
	 * @param array $params
209
	 */
210
	public function shareAccessed(array $params) {
211
		$this->log(
212
			'The shared %s with the token "%s" by "%s" has been accessed.',
213
			$params,
214
			[
215
				'itemType',
216
				'token',
217
				'uidOwner',
218
			]
219
		);
220
	}
221
}
222