Passed
Pull Request — master (#966)
by René
04:09
created

OptionController::remove()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 2
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
/**
3
 * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <[email protected]>
4
 *
5
 * @author René Gieling <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 *  This program is free software: you can redistribute it and/or modify
10
 *  it under the terms of the GNU Affero General Public License as
11
 *  published by the Free Software Foundation, either version 3 of the
12
 *  License, or (at your option) any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU Affero General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU Affero General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\Polls\Controller;
25
26
use Exception;
27
28
use OCP\IRequest;
29
use OCP\AppFramework\Controller;
30
use OCP\AppFramework\Http;
31
use OCP\AppFramework\Http\DataResponse;
32
33
use OCA\Polls\Exceptions\NotAuthorizedException;
34
35
use OCA\Polls\Service\OptionService;
36
37
class OptionController extends Controller {
38
39
	private $optionService;
40
41
	/**
42
	 * OptionController constructor.
43
	 * @param string $appName
44
	 * @param IRequest $request
45
	 * @param OptionService $optionService
46
	 */
47
48
	public function __construct(
49
		string $appName,
50
		IRequest $request,
51
		OptionService $optionService
52
	) {
53
		parent::__construct($appName, $request);
54
		$this->optionService = $optionService;
55
	}
56
57
	/**
58
	 * Get all options of given poll
59
	 * @NoAdminRequired
60
	 * @NoCSRFRequired
61
	 * @param integer $pollId
62
	 * @return DataResponse
63
	 */
64
	public function list($pollId) {
65
		return new DataResponse($this->optionService->list($pollId), Http::STATUS_OK);
66
	}
67
68
69
	/**
70
	 * getByToken
71
	 * Read all options of a poll based on a share token and return list as array
72
	 * @NoAdminRequired
73
	 * @PublicPage
74
	 * @NoCSRFRequired
75
	 * @param string $token
76
	 * @return DataResponse
77
	 */
78
	public function getByToken($token) {
79
		return new DataResponse($this->optionService->list(0, $token), Http::STATUS_OK);
80
	}
81
82
	/**
83
	 * Add a new Option to poll
84
	 * @NoAdminRequired
85
	 * @NoCSRFRequired
86
	 * @param Option $option
87
	 * @return DataResponse
88
	 */
89
	public function add($option) {
90
		return new DataResponse($this->optionService->add($option), Http::STATUS_OK);
0 ignored issues
show
Bug introduced by
$option of type OCA\Polls\Controller\Option is incompatible with the type array expected by parameter $option of OCA\Polls\Service\OptionService::add(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

90
		return new DataResponse($this->optionService->add(/** @scrutinizer ignore-type */ $option), Http::STATUS_OK);
Loading history...
91
	}
92
93
	/**
94
	 * Update poll option
95
	 * @NoAdminRequired
96
	 * @NoCSRFRequired
97
	 * @param Option $option
98
	 * @return DataResponse
99
	 */
100
	public function update($option) {
101
		return new DataResponse($this->optionService->update($option), Http::STATUS_OK);
0 ignored issues
show
Bug introduced by
$option of type OCA\Polls\Controller\Option is incompatible with the type array expected by parameter $option of OCA\Polls\Service\OptionService::update(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

101
		return new DataResponse($this->optionService->update(/** @scrutinizer ignore-type */ $option), Http::STATUS_OK);
Loading history...
102
	}
103
104
	/**
105
	 * Remove a single option
106
	 * @NoAdminRequired
107
	 * @NoCSRFRequired
108
	 * @param Option $option
109
	 * @return DataResponse
110
	 */
111
	public function remove($option) {
112
		return new DataResponse($this->optionService->delete($option['id']), Http::STATUS_OK);
113
	}
114
115
	/**
116
	 * Set order by order of the given array
117
	 * @NoAdminRequired
118
	 * @NoCSRFRequired
119
	 * @param integer $pollId
120
	 * @param Array $options
121
	 * @return DataResponse
122
	 */
123
	public function reorder($pollId, $options) {
124
		return new DataResponse($this->optionService->reorder($pollId, $options), Http::STATUS_OK);
125
	}
126
}
127