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

Ownnotev2ApiController::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 7
loc 7
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
	 * MOBILE FUNCTIONS
51
	 */
52
53
	/**
54
	 * @NoAdminRequired
55
	 * @NoCSRFRequired
56
	 */
57
	public function index() {
58
		$uid = \OC::$server->getUserSession()->getUser()->getUID();
59
		$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...
60
		return new JSONResponse($results);
61
	}
62
63
	/**
64
	 * @NoAdminRequired
65
	 * @NoCSRFRequired
66
	 */
67 View Code Duplication
	public function get($id) {
68
		$results = $this->noteService->find($id);
69
		if (!$results) {
70
			return new NotFoundJSONResponse();
71
		}
72
		return new JSONResponse($results);
73
	}
74
75
76
	/**
77
	 * @NoAdminRequired
78
	 * @NoCSRFRequired
79
	 */
80
	public function create($title, $group, $note) {
81
		$note = [
82
			'title' => $title,
83
			'group' => $group,
84
			'note' => $note
85
		];
86
		$uid = \OC::$server->getUserSession()->getUser()->getUID();
87
		$result = $this->noteService->create($note, $uid);
88
		return new JSONResponse($result);
89
	}
90
91
	/**
92
	 * @NoAdminRequired
93
	 * @NoCSRFRequired
94
	 */
95
	public function update($id, $title, $group, $content) {
96
97
		$note = [
98
			'id' => $id,
99
			'title' => $title,
100
			'group' => $group,
101
			'note' => $content
102
		];
103
104
		$entity = $this->noteService->find($id);
105
		if (!$entity) {
106
			return new NotFoundJSONResponse();
107
		}
108
109
		$results = $this->noteService->update($note);
110
		return new JSONResponse($results);
111
	}
112
113
	/**
114
	 * @NoAdminRequired
115
	 * @NoCSRFRequired
116
	 */
117 View Code Duplication
	public function delete($id) {
118
		$entity = $this->noteService->find($id);
119
		if (!$entity) {
120
			return new NotFoundJSONResponse();
121
		}
122
123
		$results = $this->noteService->delete($id);
124
		return new JSONResponse($results);
125
	}
126
127
}
128