Skip to content

Commit

Permalink
chore: Check storage is an instance of the correct class instead of p…
Browse files Browse the repository at this point in the history
…salm-suppress

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
  • Loading branch information
come-nc committed Sep 16, 2024
1 parent ed0ac28 commit e7ac9bb
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/private/Files/Storage/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,12 @@ public function getScanner($path = '', $storage = null) {
if (!$storage) {
$storage = $this;
}
/** @psalm-suppress NoInterfaceProperties The isset check is safe */
if (!$storage->instanceOfStorage(self::class)) {
throw new \InvalidArgumentException('Storage is not of the correct class');
}
if (!isset($storage->scanner)) {
$storage->scanner = new Scanner($storage);
}
/** @psalm-suppress NoInterfaceProperties Legacy stuff */
return $storage->scanner;
}

Expand All @@ -356,12 +357,13 @@ public function getPropagator($storage = null) {
if (!$storage) {
$storage = $this;
}
/** @psalm-suppress NoInterfaceProperties The isset check is safe */
if (!$storage->instanceOfStorage(self::class)) {
throw new \InvalidArgumentException('Storage is not of the correct class');
}
if (!isset($storage->propagator)) {
$config = \OC::$server->getSystemConfig();
$storage->propagator = new Propagator($storage, \OC::$server->getDatabaseConnection(), ['appdata_' . $config->getValue('instanceid')]);
}
/** @psalm-suppress NullableReturnStatement False-positive, as the if above avoids this being null */
return $storage->propagator;
}

Expand All @@ -375,11 +377,12 @@ public function getUpdater($storage = null) {
if (!$storage) {
$storage = $this;
}
/** @psalm-suppress NoInterfaceProperties The isset check is safe */
if (!$storage->instanceOfStorage(self::class)) {
throw new \InvalidArgumentException('Storage is not of the correct class');
}
if (!isset($storage->updater)) {
$storage->updater = new Updater($storage);
}
/** @psalm-suppress NullableReturnStatement False-positive, as the if above avoids this being null */
return $storage->updater;
}

Expand Down

0 comments on commit e7ac9bb

Please sign in to comment.