These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 OC\User\Manager; |
||
27 | use OCA\OwnNote\Service\OwnNoteService; |
||
28 | use OCA\OwnNote\Utility\NotFoundJSONResponse; |
||
29 | use \OCP\AppFramework\ApiController; |
||
30 | use OCP\AppFramework\Http\JSONResponse; |
||
31 | use OCP\IConfig; |
||
32 | use OCP\ILogger; |
||
33 | use \OCP\IRequest; |
||
34 | use \OCA\OwnNote\Lib\Backend; |
||
35 | |||
36 | |||
37 | class Ownnotev2ApiController extends ApiController { |
||
38 | |||
39 | private $backend; |
||
40 | private $config; |
||
41 | private $noteService; |
||
42 | |||
43 | public function __construct($appName, IRequest $request, ILogger $logger, IConfig $config, OwnNoteService $noteService){ |
||
44 | parent::__construct($appName, $request); |
||
45 | $this->backend = new Backend($config); |
||
46 | $this->config = $config; |
||
47 | $this->noteService = $noteService; |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * MOBILE FUNCTIONS |
||
52 | */ |
||
53 | |||
54 | /** |
||
55 | * @NoAdminRequired |
||
56 | * @NoCSRFRequired |
||
57 | */ |
||
58 | public function index() { |
||
59 | $uid = \OC::$server->getUserSession()->getUser()->getUID(); |
||
60 | $results = $this->noteService->getListing('', false); |
||
61 | return new JSONResponse($results); |
||
62 | } |
||
63 | /** |
||
64 | * @NoAdminRequired |
||
65 | * @NoCSRFRequired |
||
66 | */ |
||
67 | public function get($id) { |
||
68 | $uid = \OC::$server->getUserSession()->getUser()->getUID(); |
||
0 ignored issues
–
show
|
|||
69 | $results = $this->noteService->find($id); |
||
70 | if(!$results){ |
||
71 | return new NotFoundJSONResponse(); |
||
72 | } |
||
73 | return new JSONResponse($results); |
||
74 | } |
||
75 | |||
76 | |||
77 | /** |
||
78 | * @NoAdminRequired |
||
79 | * @NoCSRFRequired |
||
80 | */ |
||
81 | public function create($title, $group, $note) { |
||
82 | $note = [ |
||
83 | 'title' => $title, |
||
84 | 'group' => $group, |
||
85 | 'note' => $note |
||
86 | ]; |
||
87 | $uid = \OC::$server->getUserSession()->getUser()->getUID(); |
||
88 | $result = $this->noteService->create('', $note, $uid); //@TODO add folder |
||
89 | return new JSONResponse($result); |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * @NoAdminRequired |
||
94 | * @NoCSRFRequired |
||
95 | */ |
||
96 | public function update($id, $title, $group, $note) { |
||
97 | |||
98 | $note = [ |
||
99 | 'id' => $id, |
||
100 | 'title' => $title, |
||
101 | 'group' => $group, |
||
102 | 'note' => $note |
||
103 | ]; |
||
104 | |||
105 | $entity = $this->noteService->find($id); |
||
106 | if(!$entity){ |
||
107 | return new NotFoundJSONResponse(); |
||
108 | } |
||
109 | |||
110 | $results = $this->noteService->update('',$note); //@TODO add folder |
||
111 | return new JSONResponse($results); |
||
112 | } |
||
113 | /** |
||
114 | * @NoAdminRequired |
||
115 | * @NoCSRFRequired |
||
116 | */ |
||
117 | 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); //@TODO add folder |
||
124 | return new JSONResponse($results); |
||
125 | } |
||
126 | |||
127 | } |
||
128 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.