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 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->getListing('', false); |
||
60 | return new JSONResponse($results); |
||
61 | } |
||
62 | /** |
||
63 | * @NoAdminRequired |
||
64 | * @NoCSRFRequired |
||
65 | */ |
||
66 | public function get($id) { |
||
67 | $uid = \OC::$server->getUserSession()->getUser()->getUID(); |
||
0 ignored issues
–
show
|
|||
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); //@TODO add folder |
||
88 | return new JSONResponse($result); |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * @NoAdminRequired |
||
93 | * @NoCSRFRequired |
||
94 | */ |
||
95 | public function update($id, $title, $group, $note) { |
||
96 | |||
97 | $note = [ |
||
98 | 'id' => $id, |
||
99 | 'title' => $title, |
||
100 | 'group' => $group, |
||
101 | 'note' => $note |
||
102 | ]; |
||
103 | |||
104 | $entity = $this->noteService->find($id); |
||
105 | if(!$entity){ |
||
106 | return new NotFoundJSONResponse(); |
||
107 | } |
||
108 | |||
109 | $results = $this->noteService->update('',$note); //@TODO add folder |
||
110 | return new JSONResponse($results); |
||
111 | } |
||
112 | /** |
||
113 | * @NoAdminRequired |
||
114 | * @NoCSRFRequired |
||
115 | */ |
||
116 | public function delete($id) { |
||
117 | $entity = $this->noteService->find($id); |
||
118 | if(!$entity){ |
||
119 | return new NotFoundJSONResponse(); |
||
120 | } |
||
121 | |||
122 | $results = $this->noteService->delete('', $id); //@TODO add folder |
||
123 | return new JSONResponse($results); |
||
124 | } |
||
125 | |||
126 | } |
||
127 |
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.