NotesController::favorite()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
/**
3
 * ownCloud - Notes
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Bernhard Posselt <[email protected]>
9
 * @copyright Bernhard Posselt 2012, 2014
10
 */
11
12
namespace OCA\Notes\Controller;
13
14
use OCP\AppFramework\Controller;
15
use OCP\IRequest;
16
use OCP\IConfig;
17
use OCP\AppFramework\Http\DataResponse;
18
19
use OCA\Notes\Service\NotesService;
20
21
/**
22
 * Class NotesController
23
 *
24
 * @package OCA\Notes\Controller
25
 */
26
class NotesController extends Controller {
27
	use Errors;
28
29
	/** @var NotesService */
30
	private $notesService;
31
	/** @var IConfig */
32
	private $settings;
33
	/** @var string */
34
	private $userId;
35
36
	/**
37
	 * @param string $AppName
38
	 * @param IRequest $request
39
	 * @param NotesService $service
40
	 * @param IConfig $settings
41
	 * @param string $UserId
42
	 */
43 View Code Duplication
	public function __construct($AppName, IRequest $request,
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44 8
								NotesService $service, IConfig $settings,
45
								$UserId) {
46
		parent::__construct($AppName, $request);
47 8
		$this->notesService = $service;
48 8
		$this->settings = $settings;
49 8
		$this->userId = $UserId;
50 8
	}
51 8
52
	/**
53
	 * @NoAdminRequired
54
	 */
55
	public function index() {
56
		return new DataResponse($this->notesService->getAll($this->userId));
57 1
	}
58 1
59
	/**
60
	 * @NoAdminRequired
61
	 *
62
	 * @param int $id
63
	 * @return DataResponse
64
	 */
65
	public function get($id) {
66
		// save the last viewed note
67
		$this->settings->setUserValue(
68 2
			$this->userId, $this->appName, 'notesLastViewedNote', $id
69
		);
70 2
71 2
		return $this->respond(function () use ($id) {
72 2
			return $this->notesService->get($id, $this->userId);
73
		});
74
	}
75 2
76 2
	/**
77
	 * @NoAdminRequired
78
	 *
79
	 * @param string $content
80
	 */
81
	public function create($content) {
82
		$note = $this->notesService->create($this->userId);
83
		$note = $this->notesService->update(
84
			$note->getId(), $content, $this->userId
85 1
		);
86 1
		return new DataResponse($note);
87 1
	}
88 1
89 1
	/**
90 1
	 * @NoAdminRequired
91
	 *
92
	 * @param int $id
93
	 * @param string $content
94
	 * @return DataResponse
95
	 */
96
	public function update($id, $content) {
97
		return $this->respond(function () use ($id, $content) {
98
			return $this->notesService->update($id, $content, $this->userId);
99
		});
100
	}
101 2
102
	/**
103 2
	 * @NoAdminRequired
104 2
	 *
105
	 * @param int $id
106
	 * @param boolean $favorite
107
	 * @return DataResponse
108
	 */
109
	public function favorite($id, $favorite) {
110
		return $this->respond(function () use ($id, $favorite) {
111
			return $this->notesService->favorite($id, $favorite, $this->userId);
112
		});
113
	}
114
115
	/**
116
	 * @NoAdminRequired
117
	 *
118
	 * @param int $id
119
	 * @return DataResponse
120
	 */
121
	public function destroy($id) {
122
		return $this->respond(function () use ($id) {
123
			$this->notesService->delete($id, $this->userId);
124
			return [];
125
		});
126
	}
127
}
128