Skip to content

Commit 8dddab8

Browse files
committed
chore: psalm fixes
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 9cbf1fc commit 8dddab8

7 files changed

Lines changed: 326 additions & 26 deletions

lib/Operation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ public function onEvent(string $eventName, Event $event, IRuleMatcher $ruleMatch
275275
*/
276276
private function getNode(IStorage $storage, string $path, $cacheEntry = null): ?Node {
277277
if ($storage->instanceOfStorage(StorageWrapper::class)) {
278-
/** @var StorageWrapper $mountPoint */
278+
/** @var StorageWrapper $storage */
279279
$mountPoint = $storage->getMount();
280280
} else {
281281
// fairly sure this branch is never taken, but not 100%

lib/StorageWrapper.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
namespace OCA\FilesAccessControl;
1010

11-
use OC\Files\Cache\Cache;
1211
use OC\Files\Storage\Storage;
1312
use OC\Files\Storage\Wrapper\Wrapper;
1413
use OCP\Constants;
@@ -155,7 +154,7 @@ public function getPermissions($path): int {
155154
* see http://php.net/manual/en/function.file_get_contents.php
156155
*
157156
* @param string $path
158-
* @return string
157+
* @return string|false
159158
* @throws ForbiddenException
160159
*/
161160
#[\Override]
@@ -168,12 +167,12 @@ public function file_get_contents($path): string|false {
168167
* see http://php.net/manual/en/function.file_put_contents.php
169168
*
170169
* @param string $path
171-
* @param string $data
172-
* @return bool
170+
* @param mixed $data
171+
* @return int|float|false
173172
* @throws ForbiddenException
174173
*/
175174
#[\Override]
176-
public function file_put_contents($path, $data): int|float|false {
175+
public function file_put_contents(string $path, mixed $data): int|float|false {
177176
$this->checkFileAccess($path, false);
178177
return $this->storage->file_put_contents($path, $data);
179178
}
@@ -228,7 +227,7 @@ public function copy($source, $target): bool {
228227
*
229228
* @param string $path
230229
* @param string $mode
231-
* @return resource
230+
* @return resource|false
232231
* @throws ForbiddenException
233232
*/
234233
#[\Override]
@@ -257,7 +256,7 @@ public function touch($path, $mtime = null): bool {
257256
*
258257
* @param string $path
259258
* @param Storage (optional) the storage to pass to the cache
260-
* @return Cache
259+
* @return ICache
261260
*/
262261
#[\Override]
263262
public function getCache($path = '', $storage = null): ICache {
@@ -274,7 +273,7 @@ public function getCache($path = '', $storage = null): ICache {
274273
* For now the returned array can hold the parameter url - in future more attributes might follow.
275274
*
276275
* @param string $path
277-
* @return array
276+
* @return array|false
278277
* @throws ForbiddenException
279278
*/
280279
#[\Override]
@@ -326,7 +325,7 @@ public function writeStream(string $path, $stream, ?int $size = null): int {
326325
$this->checkFileAccess($path, false);
327326
}
328327

329-
$result = $this->storage->writeStream($path, $stream, $size);
328+
$result = parent::writeStream($path, $stream, $size);
330329
if (!$this->isPartFile($path)) {
331330
return $result;
332331
}

psalm.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
<MoreSpecificReturnType errorLevel="error"/>
2727
</issueHandlers>
2828
<stubs>
29+
<file name="tests/stubs/oc_files_cache_cache.php" />
2930
<file name="tests/stubs/oc_hooks_emitter.php" />
31+
<file name="tests/stubs/oc_files_cache_wrapper_cachewrapper.php" />
32+
<file name="tests/stubs/oc_files_storage_wrapper_wrapper.php" />
3033
</stubs>
3134
</psalm>

tests/psalm-baseline.xml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,10 @@
66
<code><![CDATA[OC]]></code>
77
</UndefinedClass>
88
</file>
9-
<file src="lib/CacheWrapper.php">
10-
<UndefinedClass>
11-
<code><![CDATA[Wrapper]]></code>
12-
</UndefinedClass>
13-
</file>
149
<file src="lib/Operation.php">
1510
<InvalidArgument>
1611
<code><![CDATA[$this->fileEntity]]></code>
1712
</InvalidArgument>
18-
<MissingDependency>
19-
<code><![CDATA[StorageWrapper]]></code>
20-
</MissingDependency>
2113
<PossiblyUndefinedArrayOffset>
2214
<code><![CDATA[$innerPath]]></code>
2315
</PossiblyUndefinedArrayOffset>
@@ -31,12 +23,4 @@
3123
<code><![CDATA[protected]]></code>
3224
</UndefinedClass>
3325
</file>
34-
<file src="lib/StorageWrapper.php">
35-
<UndefinedClass>
36-
<code><![CDATA[Wrapper]]></code>
37-
</UndefinedClass>
38-
<UnimplementedInterfaceMethod>
39-
<code><![CDATA[StorageWrapper]]></code>
40-
</UnimplementedInterfaceMethod>
41-
</file>
4226
</files>
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
/**
4+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: AGPL-3.0-only
6+
*/
7+
8+
namespace OC\Files\Cache {
9+
use OCP\Files\Cache\ICache;
10+
use OCP\Files\Cache\ICacheEntry;
11+
use OCP\Files\IMimeTypeLoader;
12+
use OCP\Files\Search\ISearchOperator;
13+
use OCP\Files\Search\ISearchQuery;
14+
15+
class Cache implements ICache {
16+
/**
17+
* @param \OCP\Files\Cache\ICache $cache
18+
*/
19+
public function __construct($cache) {
20+
$this->cache = $cache;
21+
}
22+
public function getNumericStorageId() {
23+
}
24+
public function getIncomplete() {
25+
}
26+
public function getPathById($id) {
27+
}
28+
public function getAll() {
29+
}
30+
public function get($file) {
31+
}
32+
public function getFolderContents($folder) {
33+
}
34+
public function getFolderContentsById($fileId) {
35+
}
36+
public function put($file, array $data) {
37+
}
38+
public function insert($file, array $data) {
39+
}
40+
public function update($id, array $data) {
41+
}
42+
public function getId($file) {
43+
}
44+
public function getParentId($file) {
45+
}
46+
public function inCache($file) {
47+
}
48+
public function remove($file) {
49+
}
50+
public function move($source, $target) {
51+
}
52+
public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
53+
}
54+
public function clear() {
55+
}
56+
public function getStatus($file) {
57+
}
58+
public function search($pattern) {
59+
}
60+
public function searchByMime($mimetype) {
61+
}
62+
public function searchQuery(ISearchQuery $query) {
63+
}
64+
public function correctFolderSize($path, $data = null, $isBackgroundScan = false) {
65+
}
66+
public function copyFromCache(ICache $sourceCache, ICacheEntry $sourceEntry, string $targetPath): int {
67+
}
68+
public function normalize($path) {
69+
}
70+
public function getQueryFilterForStorage(): ISearchOperator {
71+
}
72+
public function getCacheEntryFromSearchResult(ICacheEntry $rawEntry): ?ICacheEntry {
73+
}
74+
public static function cacheEntryFromData($data, IMimeTypeLoader $mimetypeLoader) {
75+
}
76+
}
77+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/**
4+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: AGPL-3.0-only
6+
*/
7+
8+
namespace OC\Files\Cache\Wrapper {
9+
10+
use OCP\Files\Cache\ICacheEntry;
11+
12+
class CacheWrapper extends \OC\Files\Cache\Cache {
13+
/**
14+
* @param ICacheEntry $entry
15+
* @return ICacheEntry|false
16+
*/
17+
protected function formatCacheEntry($entry) {
18+
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)