Completed
Push — master ( c77917...12b0e9 )
by Jörn Friedrich
57:44
created

Apps   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 77.14%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
c 1
b 0
f 0
lcom 2
cbo 4
dl 0
loc 81
ccs 27
cts 35
cp 0.7714
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B getApps() 0 26 6
A getAppInfo() 0 9 2
A enable() 0 5 1
A disable() 0 5 1
1
<?php
2
/**
3
 * @author Joas Schilling <[email protected]>
4
 * @author Lukas Reschke <[email protected]>
5
 * @author Morris Jobke <[email protected]>
6
 * @author Roeland Jago Douma <[email protected]>
7
 * @author Tom Needham <[email protected]>
8
 *
9
 * @copyright Copyright (c) 2015, ownCloud, Inc.
10
 * @license AGPL-3.0
11
 *
12
 * This code is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License, version 3,
14
 * as published by the Free Software Foundation.
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, version 3,
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
23
 *
24
 */
25
26
namespace OCA\Provisioning_API;
27
28
use OC\OCSClient;
29
use \OC_OCS_Result;
30
use \OC_App;
31
32
class Apps {
33
	/** @var \OCP\App\IAppManager */
34
	private $appManager;
35
	/** @var OCSClient */
36
	private $ocsClient;
37
38
	/**
39
	 * @param \OCP\App\IAppManager $appManager
40
	 */
41 7
	public function __construct(\OCP\App\IAppManager $appManager,
42
								OCSClient $ocsClient) {
43 7
		$this->appManager = $appManager;
44 7
		$this->ocsClient = $ocsClient;
45 7
	}
46
47
	/**
48
	 * @param array $parameters
49
	 * @return OC_OCS_Result
50
	 */
51 4
	public function getApps($parameters) {
0 ignored issues
show
Unused Code introduced by
The parameter $parameters is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
52 4
		$apps = OC_App::listAllApps(false, true, $this->ocsClient);
53 4
		$list = [];
54 4
		foreach($apps as $app) {
55 4
			$list[] = $app['id'];
56 4
		}
57 4
		$filter = isset($_GET['filter']) ? $_GET['filter'] : false;
58 4
		if($filter){
59
			switch($filter){
60 3
				case 'enabled':
61 1
					return new OC_OCS_Result(array('apps' => \OC_App::getEnabledApps()));
62
					break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
63 2
				case 'disabled':
64 1
					$enabled = OC_App::getEnabledApps();
65 1
					return new OC_OCS_Result(array('apps' => array_diff($list, $enabled)));
66
					break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
67 1
				default:
68
					// Invalid filter variable
69 1
					return new OC_OCS_Result(null, 101);
70
					break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
71 1
			}
72
73
		} else {
74 1
			return new OC_OCS_Result(array('apps' => $list));
75
		}
76
	}
77
78
	/**
79
	 * @param array $parameters
80
	 * @return OC_OCS_Result
81
	 */
82 2
	public function getAppInfo($parameters) {
83 2
		$app = $parameters['appid'];
84 2
		$info = \OCP\App::getAppInfo($app);
85 2
		if(!is_null($info)) {
86 1
			return new OC_OCS_Result(OC_App::getAppInfo($app));
87
		} else {
88 1
			return new OC_OCS_Result(null, \OCP\API::RESPOND_NOT_FOUND, 'The request app was not found');
89
		}
90
	}
91
92
	/**
93
	 * @param array $parameters
94
	 * @return OC_OCS_Result
95
	 */
96
	public function enable($parameters) {
97
		$app = $parameters['appid'];
98
		$this->appManager->enableApp($app);
99
		return new OC_OCS_Result(null, 100);
100
	}
101
102
	/**
103
	 * @param array $parameters
104
	 * @return OC_OCS_Result
105
	 */
106
	public function disable($parameters) {
107
		$app = $parameters['appid'];
108
		$this->appManager->disableApp($app);
109
		return new OC_OCS_Result(null, 100);
110
	}
111
112
}
113