Skip to content

Commit 67ae3c5

Browse files
committed
fix(psalm): systemtags
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
1 parent 74ced3d commit 67ae3c5

8 files changed

+94
-9
lines changed

apps/dav/lib/SystemTag/SystemTagList.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ public function __construct(array $tags, ISystemTagManager $tagManager, IUser $u
4949
$this->user = $user;
5050
}
5151

52-
public function getTags() {
52+
/**
53+
* @return ISystemTag[]
54+
*/
55+
public function getTags(): array {
5356
return $this->tags;
5457
}
5558

apps/dav/lib/SystemTag/SystemTagMappingNode.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ public function getName() {
137137
* @param string $name The new name
138138
*
139139
* @throws MethodNotAllowed not allowed to rename node
140+
*
141+
* @return never
140142
*/
141143
public function setName($name) {
142144
throw new MethodNotAllowed();
@@ -145,13 +147,16 @@ public function setName($name) {
145147
/**
146148
* Returns null, not supported
147149
*
150+
* @return null
148151
*/
149152
public function getLastModified() {
150153
return null;
151154
}
152155

153156
/**
154157
* Delete tag to object association
158+
*
159+
* @return void
155160
*/
156161
public function delete() {
157162
try {

apps/dav/lib/SystemTag/SystemTagNode.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ public function getSystemTag() {
103103
* @param string $name The new name
104104
*
105105
* @throws MethodNotAllowed not allowed to rename node
106+
*
107+
* @return never
106108
*/
107109
public function setName($name) {
108110
throw new MethodNotAllowed();
@@ -114,11 +116,12 @@ public function setName($name) {
114116
* @param string $name new tag name
115117
* @param bool $userVisible user visible
116118
* @param bool $userAssignable user assignable
119+
*
117120
* @throws NotFound whenever the given tag id does not exist
118121
* @throws Forbidden whenever there is no permission to update said tag
119122
* @throws Conflict whenever a tag already exists with the given attributes
120123
*/
121-
public function update($name, $userVisible, $userAssignable) {
124+
public function update($name, $userVisible, $userAssignable): void {
122125
try {
123126
if (!$this->tagManager->canUserSeeTag($this->tag, $this->user)) {
124127
throw new NotFound('Tag with id ' . $this->tag->getId() . ' does not exist');
@@ -151,11 +154,15 @@ public function update($name, $userVisible, $userAssignable) {
151154
/**
152155
* Returns null, not supported
153156
*
157+
* @return null
154158
*/
155159
public function getLastModified() {
156160
return null;
157161
}
158162

163+
/**
164+
* @return void
165+
*/
159166
public function delete() {
160167
try {
161168
if (!$this->isAdmin) {

apps/dav/lib/SystemTag/SystemTagPlugin.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class SystemTagPlugin extends \Sabre\DAV\ServerPlugin {
8383

8484
/** @var array<int, int[]> */
8585
private array $cachedTagMappings = [];
86-
/** @var array<int, ISystemTag> */
86+
/** @var array<string, ISystemTag> */
8787
private array $cachedTags = [];
8888

8989
private ISystemTagObjectMapper $tagMapper;
@@ -225,6 +225,8 @@ private function createTag($data, $contentType = 'application/json') {
225225
*
226226
* @param PropFind $propFind
227227
* @param \Sabre\DAV\INode $node
228+
*
229+
* @return void
228230
*/
229231
public function handleGetProperties(
230232
PropFind $propFind,
@@ -281,9 +283,9 @@ private function propfindForFile(PropFind $propFind, Node $node): void {
281283
&& !is_null($propFind->getStatus(self::SYSTEM_TAGS_PROPERTYNAME))) {
282284
// note: pre-fetching only supported for depth <= 1
283285
$folderContent = $node->getNode()->getDirectoryListing();
284-
$fileIds[] = (int)$node->getId();
286+
$fileIds[] = $node->getId();
285287
foreach ($folderContent as $info) {
286-
$fileIds[] = (int)$info->getId();
288+
$fileIds[] = $info->getId();
287289
}
288290
$tags = $this->tagMapper->getTagIdsForObjects($fileIds, 'files');
289291

@@ -318,20 +320,23 @@ private function getTagsForFile(int $fileId): array {
318320
$tagIds = [];
319321
}
320322
}
323+
321324
$tags = array_filter(array_map(function($tagId) {
322325
return $this->cachedTags[$tagId] ?? null;
323326
}, $tagIds));
324327

325328
$uncachedTagIds = array_filter($tagIds, function($tagId): bool {
326329
return !isset($this->cachedTags[$tagId]);
327330
});
331+
328332
if (count($uncachedTagIds)) {
329333
$retrievedTags = $this->tagManager->getTagsByIds($uncachedTagIds);
330334
foreach ($retrievedTags as $tag) {
331335
$this->cachedTags[$tag->getId()] = $tag;
332336
}
333337
$tags += $retrievedTags;
334338
}
339+
335340
return array_filter($tags, function(ISystemTag $tag) use ($user) {
336341
return $this->tagManager->canUserSeeTag($tag, $user);
337342
});

apps/dav/lib/SystemTag/SystemTagsByIdCollection.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,28 @@ private function isAdmin() {
8484
/**
8585
* @param string $name
8686
* @param resource|string $data Initial payload
87+
*
8788
* @throws Forbidden
89+
*
90+
* @return never
8891
*/
8992
public function createFile($name, $data = null) {
9093
throw new Forbidden('Cannot create tags by id');
9194
}
9295

9396
/**
9497
* @param string $name
98+
*
99+
* @return never
95100
*/
96101
public function createDirectory($name) {
97102
throw new Forbidden('Permission denied to create collections');
98103
}
99104

100105
/**
101106
* @param string $name
107+
*
108+
* @return SystemTagNode
102109
*/
103110
public function getChild($name) {
104111
try {
@@ -115,6 +122,11 @@ public function getChild($name) {
115122
}
116123
}
117124

125+
/**
126+
* @return SystemTagNode[]
127+
*
128+
* @psalm-return array<SystemTagNode>
129+
*/
118130
public function getChildren() {
119131
$visibilityFilter = true;
120132
if ($this->isAdmin()) {
@@ -145,22 +157,33 @@ public function childExists($name) {
145157
}
146158
}
147159

160+
/**
161+
* @return never
162+
*/
148163
public function delete() {
149164
throw new Forbidden('Permission denied to delete this collection');
150165
}
151166

167+
/**
168+
* @return string
169+
*
170+
* @psalm-return 'systemtags'
171+
*/
152172
public function getName() {
153173
return 'systemtags';
154174
}
155175

176+
/**
177+
* @return never
178+
*/
156179
public function setName($name) {
157180
throw new Forbidden('Permission denied to rename this collection');
158181
}
159182

160183
/**
161184
* Returns the last modification time, as a unix timestamp
162185
*
163-
* @return int
186+
* @return null
164187
*/
165188
public function getLastModified() {
166189
return null;

apps/dav/lib/SystemTag/SystemTagsObjectMappingCollection.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ public function __construct(
9292
$this->user = $user;
9393
}
9494

95+
/**
96+
* @return void
97+
*/
9598
public function createFile($name, $data = null) {
9699
$tagId = $name;
97100
try {
@@ -110,10 +113,16 @@ public function createFile($name, $data = null) {
110113
}
111114
}
112115

116+
/**
117+
* @return never
118+
*/
113119
public function createDirectory($name) {
114120
throw new Forbidden('Permission denied to create collections');
115121
}
116122

123+
/**
124+
* @return SystemTagMappingNode
125+
*/
117126
public function getChild($tagName) {
118127
try {
119128
if ($this->tagMapper->haveTag([$this->objectId], $this->objectType, $tagName, true)) {
@@ -131,6 +140,11 @@ public function getChild($tagName) {
131140
}
132141
}
133142

143+
/**
144+
* @return SystemTagMappingNode[]
145+
*
146+
* @psalm-return list<SystemTagMappingNode>
147+
*/
134148
public function getChildren() {
135149
$tagIds = current($this->tagMapper->getTagIdsForObjects([$this->objectId], $this->objectType));
136150
if (empty($tagIds)) {
@@ -168,6 +182,9 @@ public function childExists($tagId) {
168182
}
169183
}
170184

185+
/**
186+
* @return never
187+
*/
171188
public function delete() {
172189
throw new Forbidden('Permission denied to delete this collection');
173190
}
@@ -176,14 +193,17 @@ public function getName() {
176193
return $this->objectId;
177194
}
178195

196+
/**
197+
* @return never
198+
*/
179199
public function setName($name) {
180200
throw new Forbidden('Permission denied to rename this collection');
181201
}
182202

183203
/**
184204
* Returns the last modification time, as a unix timestamp
185205
*
186-
* @return int
206+
* @return null
187207
*/
188208
public function getLastModified() {
189209
return null;

apps/dav/lib/SystemTag/SystemTagsObjectTypeCollection.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ public function __construct(
9898
/**
9999
* @param string $name
100100
* @param resource|string $data Initial payload
101-
* @return null|string
101+
*
102+
* @return never
103+
*
102104
* @throws Forbidden
103105
*/
104106
public function createFile($name, $data = null) {
@@ -107,7 +109,10 @@ public function createFile($name, $data = null) {
107109

108110
/**
109111
* @param string $name
112+
*
110113
* @throws Forbidden
114+
*
115+
* @return never
111116
*/
112117
public function createDirectory($name) {
113118
throw new Forbidden('Permission denied to create collections');
@@ -133,6 +138,9 @@ public function getChild($objectName) {
133138
);
134139
}
135140

141+
/**
142+
* @return never
143+
*/
136144
public function getChildren() {
137145
// do not list object ids
138146
throw new MethodNotAllowed();
@@ -148,6 +156,9 @@ public function childExists($name) {
148156
return call_user_func($this->childExistsFunction, $name);
149157
}
150158

159+
/**
160+
* @return never
161+
*/
151162
public function delete() {
152163
throw new Forbidden('Permission denied to delete this collection');
153164
}
@@ -158,7 +169,10 @@ public function getName() {
158169

159170
/**
160171
* @param string $name
172+
*
161173
* @throws Forbidden
174+
*
175+
* @return never
162176
*/
163177
public function setName($name) {
164178
throw new Forbidden('Permission denied to rename this collection');
@@ -167,7 +181,7 @@ public function setName($name) {
167181
/**
168182
* Returns the last modification time, as a unix timestamp
169183
*
170-
* @return int
184+
* @return null
171185
*/
172186
public function getLastModified() {
173187
return null;

apps/dav/lib/SystemTag/SystemTagsRelationsCollection.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,18 @@ function ($name) {
8484
parent::__construct('root', $children);
8585
}
8686

87+
/**
88+
* @return string
89+
*
90+
* @psalm-return 'systemtags-relations'
91+
*/
8792
public function getName() {
8893
return 'systemtags-relations';
8994
}
9095

96+
/**
97+
* @return never
98+
*/
9199
public function setName($name) {
92100
throw new Forbidden('Permission denied to rename this collection');
93101
}

0 commit comments

Comments
 (0)