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 - namespace OCA\Nextnote |
||
4 | * |
||
5 | * @copyright Copyright (c) 2016, Sander Brand ([email protected]) |
||
6 | * @copyright Copyright (c) 2016, Marcos Zuriaga Miguel ([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\NextNote\Service; |
||
25 | |||
26 | use OCA\NextNote\Db\Notebook; |
||
27 | use OCA\NextNote\Db\Note; |
||
28 | use OCA\NextNote\Fixtures\ShareFix; |
||
29 | use OCA\NextNote\ShareBackend\NextNoteShareBackend; |
||
30 | use OCA\NextNote\Utility\Utils; |
||
31 | use OCA\NextNote\Db\NoteMapper; |
||
32 | |||
33 | |||
34 | class NoteService { |
||
35 | |||
36 | private $noteMapper; |
||
37 | private $utils; |
||
38 | private $sharing; |
||
39 | private $groupService; |
||
40 | |||
41 | public function __construct(NoteMapper $noteMapper, Utils $utils, NextNoteShareBackend $shareBackend, NotebookService $groupService) { |
||
42 | $this->noteMapper = $noteMapper; |
||
43 | $this->utils = $utils; |
||
44 | $this->sharing = $shareBackend; |
||
45 | $this->groupService = $groupService; |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * Get vaults from a user. |
||
50 | * |
||
51 | * @param $userId |
||
52 | * @param int|bool $deleted |
||
53 | * @param string|bool $grouping |
||
54 | * @return Note[] |
||
55 | */ |
||
56 | public function findNotesFromUser($userId, $deleted = false, $grouping = false) { |
||
57 | // Get shares |
||
58 | |||
59 | $dbNotes = $this->noteMapper->findNotesFromUser($userId, $deleted, $grouping); |
||
60 | $sharedNotes = $this->sharing->getSharedNotes(); |
||
61 | $notes = array_merge($dbNotes, $sharedNotes); |
||
62 | return $notes; |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Get a single vault |
||
67 | * |
||
68 | * @param $note_id |
||
69 | * @param $user_id |
||
70 | * @param bool|int $deleted |
||
71 | * @return Note |
||
72 | * @internal param $vault_id |
||
73 | */ |
||
74 | public function find($note_id, $user_id = null, $deleted = false) { |
||
75 | $note = $this->noteMapper->find($note_id, $user_id, $deleted); |
||
76 | return $note; |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * Creates a note |
||
81 | * |
||
82 | * @param Note $note |
||
83 | * @return Note |
||
84 | * @throws \Exception |
||
85 | */ |
||
86 | public function create(Note $note) { |
||
87 | if (!$note instanceof Note) { |
||
88 | throw new \Exception("Expected Note object!"); |
||
89 | } |
||
90 | |||
91 | return $this->noteMapper->create($note); |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * Update vault |
||
96 | * |
||
97 | * @param $note Note |
||
98 | * @return Note|bool |
||
99 | * @throws \Exception |
||
100 | * @internal param $userId |
||
101 | * @internal param $vault |
||
102 | */ |
||
103 | public function update(Note $note) { |
||
104 | if (!$note instanceof Note) { |
||
105 | throw new \Exception("Expected Note object!"); |
||
106 | } |
||
107 | |||
108 | return $this->noteMapper->updateNote($note); |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * Delete a vault from user |
||
113 | * |
||
114 | * @param $note_id |
||
115 | * @param string $user_id |
||
116 | * @return bool |
||
117 | * @internal param string $vault_guid |
||
118 | */ |
||
119 | public function delete($note_id, $user_id = null) { |
||
120 | if (!$this->checkPermissions(\OCP\Constants::PERMISSION_DELETE, $note_id)) { |
||
121 | return false; |
||
122 | } |
||
123 | |||
124 | $note = $this->noteMapper->find($note_id, $user_id); |
||
125 | if ($note instanceof Note) { |
||
126 | $this->noteMapper->deleteNote($note); |
||
127 | return true; |
||
128 | } else { |
||
129 | return false; |
||
130 | } |
||
131 | } |
||
132 | |||
133 | |||
134 | /** |
||
135 | * @param $FOLDER |
||
136 | * @param boolean $showdel |
||
137 | * @return array |
||
138 | * @throws \Exception |
||
139 | */ |
||
140 | public function getListing($FOLDER, $showdel) { |
||
141 | throw new \Exception('Calling a deprecated method! (Folder' . $FOLDER . '. Showdel: ' . $showdel . ')'); |
||
142 | } |
||
143 | |||
144 | private function checkPermissions($permission, $nid) { |
||
145 | return true; |
||
146 | // gather information |
||
147 | $uid = \OC::$server->getUserSession()->getUser()->getUID(); |
||
0 ignored issues
–
show
|
|||
148 | $note = $this->find($nid); |
||
149 | // owner is allowed to change everything |
||
150 | if ($uid === $note->getUid()) { |
||
151 | return true; |
||
152 | } |
||
153 | |||
154 | // check share permissions |
||
155 | $shared_note = ShareFix::getItemSharedWith('nextnote', $nid, 'populated_shares')[0]; |
||
156 | return $shared_note['permissions'] & $permission; |
||
157 | } |
||
158 | } |
||
159 |
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return
,die
orexit
statements that have been added for debug purposes.In the above example, the last
return false
will never be executed, because a return statement has already been met in every possible execution path.