Failed Conditions
Pull Request — master (#6)
by Sander
02:02
created

Ownnotev2ApiController::update()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 11
nc 2
nop 4
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Nextcloud - ownnote
4
 *
5
 * @copyright Copyright (c) 2015, Ben Curtis <[email protected]>
6
 * @copyright Copyright (c) 2017, Sander Brand ([email protected])
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\OwnNote\Controller;
25
26
use OCA\OwnNote\Service\OwnNoteService;
27
use OCA\OwnNote\Utility\NotFoundJSONResponse;
28
use \OCP\AppFramework\ApiController;
29
use OCP\AppFramework\Http\JSONResponse;
30
use OCP\IConfig;
31
use OCP\ILogger;
32
use \OCP\IRequest;
33
use \OCA\OwnNote\Lib\Backend;
34
35
36
class Ownnotev2ApiController extends ApiController {
37
38
	private $backend;
39
	private $config;
40
	private $noteService;
41
42
	public function __construct($appName, IRequest $request, ILogger $logger, IConfig $config, OwnNoteService $noteService) {
43
		parent::__construct($appName, $request);
44
		$this->backend = new Backend($config);
45
		$this->config = $config;
46
		$this->noteService = $noteService;
47
	}
48
49
	/**
50
	 * @NoAdminRequired
51
	 * @NoCSRFRequired
52
	 * @TODO Add etag / lastmodified
53
	 */
54
	public function index() {
55
		$uid = \OC::$server->getUserSession()->getUser()->getUID();
56
		$results = $this->noteService->findNotesFromUser($uid, false);
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
57
		return new JSONResponse($results);
58
	}
59
60
	/**
61
	 * @NoAdminRequired
62
	 * @NoCSRFRequired
63
	 * @TODO Add etag / lastmodified
64
	 */
65 View Code Duplication
	public function get($id) {
66
		$results = $this->noteService->find($id);
67
		if (!$results) {
68
			return new NotFoundJSONResponse();
69
		}
70
		return new JSONResponse($results);
71
	}
72
73
74
	/**
75
	 * @NoAdminRequired
76
	 * @NoCSRFRequired
77
	 */
78
	public function create($title, $group, $note) {
79
		$note = [
80
			'title' => $title,
81
			'group' => $group,
82
			'note' => $note
83
		];
84
		$uid = \OC::$server->getUserSession()->getUser()->getUID();
85
		$result = $this->noteService->create($note, $uid);
86
		return new JSONResponse($result);
87
	}
88
89
	/**
90
	 * @NoAdminRequired
91
	 * @NoCSRFRequired
92
	 */
93
	public function update($id, $title, $group, $content) {
94
95
		$note = [
96
			'id' => $id,
97
			'title' => $title,
98
			'group' => $group,
99
			'note' => $content
100
		];
101
102
		$entity = $this->noteService->find($id);
103
		if (!$entity) {
104
			return new NotFoundJSONResponse();
105
		}
106
107
		$results = $this->noteService->update($note);
108
		return new JSONResponse($results);
109
	}
110
111
	/**
112
	 * @NoAdminRequired
113
	 * @NoCSRFRequired
114
	 */
115 View Code Duplication
	public function delete($id) {
116
		$entity = $this->noteService->find($id);
117
		if (!$entity) {
118
			return new NotFoundJSONResponse();
119
		}
120
121
		$results = $this->noteService->delete($id);
122
		return new JSONResponse($results);
123
	}
124
125
}
126