Skip to content

Commit 53888a4

Browse files
committed
refactor: Apply second batch of comments
Signed-off-by: Carl Schwan <[email protected]>
1 parent 95fbaeb commit 53888a4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+163
-415
lines changed

apps/files_external/lib/Lib/Notify/SMBNotifyHandler.php

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -110,21 +110,16 @@ private function mapChange(\Icewind\SMB\Change $change) {
110110
return $result;
111111
}
112112

113-
private function mapNotifyType($smbType) {
114-
switch ($smbType) {
115-
case \Icewind\SMB\INotifyHandler::NOTIFY_ADDED:
116-
return IChange::ADDED;
117-
case \Icewind\SMB\INotifyHandler::NOTIFY_REMOVED:
118-
return IChange::REMOVED;
119-
case \Icewind\SMB\INotifyHandler::NOTIFY_MODIFIED:
120-
case \Icewind\SMB\INotifyHandler::NOTIFY_ADDED_STREAM:
121-
case \Icewind\SMB\INotifyHandler::NOTIFY_MODIFIED_STREAM:
122-
case \Icewind\SMB\INotifyHandler::NOTIFY_REMOVED_STREAM:
123-
return IChange::MODIFIED;
124-
case \Icewind\SMB\INotifyHandler::NOTIFY_RENAMED_NEW:
125-
return IChange::RENAMED;
126-
default:
127-
return null;
128-
}
113+
/**
114+
* @return IChange::ADDED|IChange::REMOVED|IChange::MODIFIED|IChange::RENAMED|null
115+
*/
116+
private function mapNotifyType($smbType): ?int {
117+
return match ($smbType) {
118+
\Icewind\SMB\INotifyHandler::NOTIFY_ADDED => IChange::ADDED,
119+
\Icewind\SMB\INotifyHandler::NOTIFY_REMOVED => IChange::REMOVED,
120+
\Icewind\SMB\INotifyHandler::NOTIFY_MODIFIED, \Icewind\SMB\INotifyHandler::NOTIFY_ADDED_STREAM, \Icewind\SMB\INotifyHandler::NOTIFY_MODIFIED_STREAM, \Icewind\SMB\INotifyHandler::NOTIFY_REMOVED_STREAM => IChange::MODIFIED,
121+
\Icewind\SMB\INotifyHandler::NOTIFY_RENAMED_NEW => IChange::RENAMED,
122+
default => null,
123+
};
129124
}
130125
}

apps/files_sharing/lib/SharedMount.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828
* Shared mount points can be moved by the user
2929
*/
3030
class SharedMount extends MountPoint implements MoveableMount, ISharedMountPoint {
31-
/**
32-
* @var SharedStorage $storage
33-
*/
31+
/** @var ?SharedStorage $storage */
3432
protected $storage = null;
3533

3634
/** @var IShare */

build/psalm-baseline.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3681,11 +3681,6 @@
36813681
<code><![CDATA[self::getGlobalCache()->getStorageInfo($storageId)]]></code>
36823682
</NullableReturnStatement>
36833683
</file>
3684-
<file src="lib/private/Files/Cache/Updater.php">
3685-
<RedundantCondition>
3686-
<code><![CDATA[$this->cache instanceof Cache]]></code>
3687-
</RedundantCondition>
3688-
</file>
36893684
<file src="lib/private/Files/Cache/Wrapper/CacheWrapper.php">
36903685
<LessSpecificImplementedReturnType>
36913686
<code><![CDATA[array]]></code>

lib/private/Authentication/LoginCredentials/Credentials.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Credentials implements ICredentials {
1313
public function __construct(
1414
private readonly string $uid,
1515
private readonly string $loginName,
16-
private readonly string $password,
16+
private readonly ?string $password,
1717
) {
1818
}
1919

@@ -28,7 +28,7 @@ public function getLoginName(): string {
2828
}
2929

3030
#[Override]
31-
public function getPassword(): string {
31+
public function getPassword(): ?string {
3232
return $this->password;
3333
}
3434
}

lib/private/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct(
3030
protected string $configDir,
3131
protected string $configFileName = 'config.php',
3232
) {
33-
$this->configFilePath = $this->configDir . $configFileName;
33+
$this->configFilePath = $this->configDir . $this->configFileName;
3434
$this->readData();
3535
$this->isReadOnly = $this->getValue('config_is_read_only', false);
3636
}

lib/private/Encryption/Util.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,20 @@ class Util {
2828
public const HEADER_ENCRYPTION_MODULE_KEY = 'oc_encryption_module';
2929

3030
/**
31-
* block size will always be 8192 for a PHP stream
31+
* Block size will always be 8192 for a PHP stream
3232
* @see https://bugs.php.net/bug.php?id=21641
33-
* @var integer
3433
*/
35-
protected $headerSize = 8192;
34+
protected int $headerSize = 8192;
3635

3736
/**
38-
* block size will always be 8192 for a PHP stream
37+
* Block size will always be 8192 for a PHP stream
3938
* @see https://bugs.php.net/bug.php?id=21641
40-
* @var integer
4139
*/
42-
protected $blockSize = 8192;
40+
protected int $blockSize = 8192;
4341

44-
/** @var array */
45-
protected $ocHeaderKeys;
46-
47-
/** @var array paths excluded from encryption */
42+
protected array $ocHeaderKeys;
4843
protected array $excludedPaths = [];
4944

50-
/**
51-
*
52-
* @param View $rootView
53-
* @param IConfig $config
54-
*/
5545
public function __construct(
5646
protected View $rootView,
5747
protected IUserManager $userManager,

lib/private/Files/Cache/FailedCache.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,8 @@
1919
* Storage placeholder to represent a missing precondition, storage unavailable
2020
*/
2121
class FailedCache implements ICache {
22-
/**
23-
* FailedCache constructor.
24-
*
25-
* @param bool $visible
26-
*/
2722
public function __construct(
28-
private $visible = true,
23+
private readonly bool $visible = true,
2924
) {
3025
}
3126

lib/private/Files/Cache/Scanner.php

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use OC\Files\Storage\Wrapper\Encryption;
1414
use OC\Files\Storage\Wrapper\Jail;
1515
use OC\Hooks\BasicEmitter;
16+
use OCP\Files\Cache\ICache;
1617
use OCP\Files\Cache\ICacheEntry;
1718
use OCP\Files\Cache\IScanner;
1819
use OCP\Files\ForbiddenException;
@@ -42,15 +43,11 @@
4243
*/
4344
class Scanner extends BasicEmitter implements IScanner {
4445
protected string $storageId;
45-
/** @var Cache */
46-
protected $cache;
47-
/** @var boolean $cacheActive If true, perform cache operations, if false, do not affect cache */
46+
protected ICache $cache;
47+
/** @var bool $cacheActive Whether to perform cache operations */
4848
protected bool $cacheActive;
49-
/** @var bool $useTransactions whether to use transactions */
5049
protected bool $useTransactions = true;
51-
/** * @var ILockingProvider */
5250
protected ILockingProvider $lockingProvider;
53-
5451
protected IDBConnection $connection;
5552

5653
public function __construct(
@@ -416,7 +413,9 @@ protected function scanChildren(string $path, $recursive, int $reuse, int $folde
416413
// for encrypted storages, we trigger a regular folder size calculation instead of using the calculated size
417414
// to make sure we also updated the unencrypted-size where applicable
418415
if ($this->storage->instanceOfStorage(Encryption::class)) {
419-
$this->cache->calculateFolderSize($path);
416+
/** @var Cache $cache */
417+
$cache = $this->cache;
418+
$cache->calculateFolderSize($path);
420419
} else {
421420
if ($this->cacheActive) {
422421
$updatedData = [];
@@ -588,14 +587,8 @@ protected function runBackgroundScanJob(callable $callback, $path) {
588587
if ($this->cacheActive && $this->cache instanceof Cache) {
589588
$this->cache->correctFolderSize($path, null, true);
590589
}
591-
} catch (StorageInvalidException $e) {
592-
// skip unavailable storages
593-
} catch (StorageNotAvailableException $e) {
594-
// skip unavailable storages
595-
} catch (ForbiddenException $e) {
596-
// skip forbidden storages
597-
} catch (LockedException $e) {
598-
// skip unavailable storages
590+
} catch (StorageInvalidException|StorageNotAvailableException|ForbiddenException|LockedException) {
591+
// skip unavailable and forbidden storages
599592
}
600593
}
601594

lib/private/Files/Cache/Updater.php

Lines changed: 23 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,21 @@
1313
use OC\Files\Storage\Storage;
1414
use OCP\Files\Cache\ICache;
1515
use OCP\Files\Cache\ICacheEntry;
16+
use OCP\Files\Cache\IPropagator;
17+
use OCP\Files\Cache\IScanner;
1618
use OCP\Files\Cache\IUpdater;
1719
use OCP\Files\Storage\IStorage;
1820
use OCP\Server;
21+
use Override;
1922
use Psr\Log\LoggerInterface;
2023

21-
/**
22-
* Update the cache and propagate changes
23-
*
24-
*/
2524
class Updater implements IUpdater {
26-
/**
27-
* @var bool
28-
*/
29-
protected $enabled = true;
30-
31-
/**
32-
* @var Propagator
33-
*/
34-
protected $propagator;
35-
36-
/**
37-
* @var Scanner
38-
*/
39-
protected $scanner;
40-
41-
/**
42-
* @var Cache
43-
*/
44-
protected $cache;
45-
25+
protected bool $enabled = true;
26+
protected IPropagator $propagator;
27+
protected IScanner $scanner;
28+
protected ICache $cache;
4629
private LoggerInterface $logger;
4730

48-
/**
49-
* @param Storage $storage
50-
*/
5131
public function __construct(
5232
protected Storage $storage,
5333
) {
@@ -60,46 +40,32 @@ public function __construct(
6040
/**
6141
* Disable updating the cache through this updater
6242
*/
63-
public function disable() {
43+
public function disable(): void {
6444
$this->enabled = false;
6545
}
6646

6747
/**
6848
* Re-enable the updating of the cache through this updater
6949
*/
70-
public function enable() {
50+
public function enable(): void {
7151
$this->enabled = true;
7252
}
7353

74-
/**
75-
* Get the propagator for etags and mtime for the view the updater works on
76-
*
77-
* @return Propagator
78-
*/
79-
public function getPropagator() {
54+
#[Override]
55+
public function getPropagator(): IPropagator {
8056
return $this->propagator;
8157
}
8258

83-
/**
84-
* Propagate etag and mtime changes for the parent folders of $path up to the root of the filesystem
85-
*
86-
* @param string $path the path of the file to propagate the changes for
87-
* @param int|null $time the timestamp to set as mtime for the parent folders, if left out the current time is used
88-
*/
89-
public function propagate($path, $time = null) {
59+
#[Override]
60+
public function propagate(string $path, ?int $time = null): void {
9061
if (Scanner::isPartialFile($path)) {
9162
return;
9263
}
9364
$this->propagator->propagateChange($path, $time);
9465
}
9566

96-
/**
97-
* Update the cache for $path and update the size, etag and mtime of the parent folders
98-
*
99-
* @param string $path
100-
* @param int $time
101-
*/
102-
public function update($path, $time = null, ?int $sizeDifference = null) {
67+
#[Override]
68+
public function update(string $path, ?int $time = null, ?int $sizeDifference = null): void {
10369
if (!$this->enabled || Scanner::isPartialFile($path)) {
10470
return;
10571
}
@@ -126,12 +92,8 @@ public function update($path, $time = null, ?int $sizeDifference = null) {
12692
$this->propagator->propagateChange($path, $time, $sizeDifference ?? 0);
12793
}
12894

129-
/**
130-
* Remove $path from the cache and update the size, etag and mtime of the parent folders
131-
*
132-
* @param string $path
133-
*/
134-
public function remove($path) {
95+
#[Override]
96+
public function remove(string $path): void {
13597
if (!$this->enabled || Scanner::isPartialFile($path)) {
13698
return;
13799
}
@@ -156,14 +118,8 @@ public function remove($path) {
156118
}
157119
}
158120

159-
/**
160-
* Rename a file or folder in the cache.
161-
*
162-
* @param IStorage $sourceStorage
163-
* @param string $source
164-
* @param string $target
165-
*/
166-
public function renameFromStorage(IStorage $sourceStorage, $source, $target) {
121+
#[Override]
122+
public function renameFromStorage(IStorage $sourceStorage, string $source, string $target): void {
167123
$this->copyOrRenameFromStorage($sourceStorage, $source, $target, function (ICache $sourceCache) use ($sourceStorage, $source, $target): void {
168124
// Remove existing cache entry to no reuse the fileId.
169125
if ($this->cache->inCache($target)) {
@@ -178,9 +134,7 @@ public function renameFromStorage(IStorage $sourceStorage, $source, $target) {
178134
});
179135
}
180136

181-
/**
182-
* Copy a file or folder in the cache.
183-
*/
137+
#[Override]
184138
public function copyFromStorage(IStorage $sourceStorage, string $source, string $target): void {
185139
$this->copyOrRenameFromStorage($sourceStorage, $source, $target, function (ICache $sourceCache, ICacheEntry $sourceInfo) use ($target): void {
186140
$parent = dirname($target);
@@ -250,7 +204,7 @@ private function copyOrRenameFromStorage(IStorage $sourceStorage, string $source
250204
$this->propagator->propagateChange($target, $time);
251205
}
252206

253-
private function updateStorageMTimeOnly($internalPath) {
207+
private function updateStorageMTimeOnly(string $internalPath): void {
254208
$fileId = $this->cache->getId($internalPath);
255209
if ($fileId !== -1) {
256210
$mtime = $this->storage->filemtime($internalPath);
@@ -266,11 +220,9 @@ private function updateStorageMTimeOnly($internalPath) {
266220
}
267221

268222
/**
269-
* update the storage_mtime of the direct parent in the cache to the mtime from the storage
270-
*
271-
* @param string $internalPath
223+
* Update the storage_mtime of the direct parent in the cache to the mtime from the storage
272224
*/
273-
private function correctParentStorageMtime($internalPath) {
225+
private function correctParentStorageMtime(string $internalPath): void {
274226
$parentId = $this->cache->getParentId($internalPath);
275227
$parent = dirname($internalPath);
276228
if ($parentId != -1) {

lib/private/Files/Cache/Watcher.php

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,22 @@
88
namespace OC\Files\Cache;
99

1010
use OC\Files\Storage\Storage;
11+
use OCP\Files\Cache\ICache;
1112
use OCP\Files\Cache\ICacheEntry;
13+
use OCP\Files\Cache\IScanner;
1214
use OCP\Files\Cache\IWatcher;
1315

1416
/**
1517
* check the storage backends for updates and change the cache accordingly
1618
*/
1719
class Watcher implements IWatcher {
18-
protected $watchPolicy = self::CHECK_ONCE;
19-
20-
protected $checkedPaths = [];
21-
22-
/**
23-
* @var Cache $cache
24-
*/
25-
protected $cache;
26-
27-
/**
28-
* @var Scanner $scanner ;
29-
*/
30-
protected $scanner;
31-
20+
protected int $watchPolicy = self::CHECK_ONCE;
21+
protected array $checkedPaths = [];
22+
protected ICache $cache;
23+
protected IScanner $scanner;
3224
/** @var callable[] */
33-
protected $onUpdate = [];
25+
protected array $onUpdate = [];
3426

35-
/**
36-
* @param Storage $storage
37-
*/
3827
public function __construct(
3928
protected Storage $storage,
4029
) {

0 commit comments

Comments
 (0)