Failed Conditions
Pull Request — master (#55)
by Sander
03:54
created

ShareApiController   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 8
c 2
b 0
f 0
lcom 0
cbo 0
dl 0
loc 54
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getShares() 0 7 3
A share() 0 11 2
A unshare() 0 5 1
A setpermissions() 0 5 1
1
<?php
2
/**
3
 * ownCloud - nextnote
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Ben Curtis <[email protected]>
9
 * @copyright Ben Curtis 2015
10
 */
11
12
namespace OCA\NextNote\Controller;
13
14
use \OCP\AppFramework\ApiController;
15
use \OCP\IRequest;
16
use OC\Share\Share;
17
use OCA\NextNote\Fixtures\ShareFix;
18
19
20
class ShareApiController extends ApiController {
21
22
	public function __construct($appName, IRequest $request) {
23
		parent::__construct($appName, $request);
24
	}
25
26
	/**
27
	 * @NoAdminRequired
28
	 * @NoCSRFRequired
29
	 */
30
	public function getShares($noteid, $shared_with_me, $reshares) {
31
		if ($shared_with_me) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
32
			//@FIXME return \OCP\Share::getItemSharedWith('nextnote', $noteid, 'shares');
33
		} else if ($reshares) {
34
			return array_values(Share::getItemShared('nextnote', $noteid, 'shares'));
35
		}
36
	}
37
38
	/**
39
	 * @NoAdminRequired
40
	 * @NoCSRFRequired
41
	 */
42
	public function share($noteid, $shareType, $shareWith, $publicUpload, $password, $permissions) {
43
		$shareType = intval($shareType);
44
		//Todo check if resharing is allowed
45
		if($shareType === 1){
46
			$result = ShareFix::shareItem('nextnote', intval($noteid), intval($shareType), $shareWith, intval($permissions));
47
		} else {
48
			$result = Share::shareItem('nextnote', intval($noteid), intval($shareType), $shareWith, intval($permissions));
49
		}
50
		\OC_Hook::emit('OCA\NextNote', 'post_share_note', ['note_id' => $noteid]);
51
		return $result;
52
	}
53
54
	/**
55
	 * @NoAdminRequired
56
	 * @NoCSRFRequired
57
	 */
58
	public function unshare($itemSource, $shareType, $shareWith) {
59
		$result = Share::unshare('nextnote', intval($itemSource), intval($shareType), $shareWith);
60
		\OC_Hook::emit('OCA\NextNote', 'post_unshare_note', ['note_id' => $itemSource]);
61
		return $result;
62
	}
63
64
	/**
65
	 * @NoAdminRequired
66
	 * @NoCSRFRequired
67
	 */
68
	public function setpermissions($itemSource, $shareType, $shareWith, $permissions) {
69
		$result = ShareFix::setPermissions('nextnote', intval($itemSource), intval($shareType), $shareWith, intval($permissions));
70
		\OC_Hook::emit('OCA\NextNote', 'post_update_note_share_permissions', ['note_id' => $itemSource]);
71
		return $result;
72
	}
73
}