Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Schwan <carl@carlschwan.eu>2022-05-03 12:15:24 +0300
committerCarl Schwan <carl@carlschwan.eu>2022-05-12 16:06:18 +0300
commitec6b83cc1891214c7fa3a236626807b4335f9a2f (patch)
treeb5f12993172528ddec15b7b8ae6a09a0080fedd7
parent5a0b28d603e142051967175f023b698ff7e262db (diff)
Add stricter psalm type for CappedMemoryCachecleanup/cappedmemorycache
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
-rw-r--r--apps/files_external/lib/Lib/Storage/AmazonS3.php28
-rw-r--r--apps/files_external/lib/Lib/Storage/SMB.php8
-rw-r--r--apps/files_sharing/lib/MountProvider.php1
-rw-r--r--apps/files_sharing/lib/SharedMount.php1
-rw-r--r--apps/user_ldap/lib/Group_LDAP.php12
-rw-r--r--apps/user_ldap/lib/Helper.php13
-rw-r--r--apps/user_ldap/lib/User/Manager.php51
-rw-r--r--apps/workflowengine/lib/Manager.php9
-rw-r--r--build/psalm-baseline.xml33
-rw-r--r--lib/private/Cache/CappedMemoryCache.php2
-rw-r--r--lib/private/Diagnostics/QueryLogger.php16
-rw-r--r--lib/private/Encryption/File.php8
-rw-r--r--lib/private/Encryption/Util.php2
-rw-r--r--lib/private/Files/AppData/AppData.php21
-rw-r--r--lib/private/Files/Config/UserMountCache.php27
-rw-r--r--tests/lib/Files/Config/UserMountCacheTest.php3
16 files changed, 74 insertions, 161 deletions
diff --git a/apps/files_external/lib/Lib/Storage/AmazonS3.php b/apps/files_external/lib/Lib/Storage/AmazonS3.php
index d3e9605e5a1..e7a8c5f9329 100644
--- a/apps/files_external/lib/Lib/Storage/AmazonS3.php
+++ b/apps/files_external/lib/Lib/Storage/AmazonS3.php
@@ -54,6 +54,7 @@ use OCP\Files\IMimeTypeDetector;
use OCP\ICacheFactory;
use OCP\IMemcache;
use OCP\Server;
+use OCP\ICache;
class AmazonS3 extends \OC\Files\Storage\Common {
use S3ConnectionTrait;
@@ -63,23 +64,18 @@ class AmazonS3 extends \OC\Files\Storage\Common {
return false;
}
- /** @var CappedMemoryCache|Result[] */
- private $objectCache;
+ /** @var CappedMemoryCache<array|false> */
+ private CappedMemoryCache $objectCache;
- /** @var CappedMemoryCache|bool[] */
- private $directoryCache;
+ /** @var CappedMemoryCache<bool> */
+ private CappedMemoryCache $directoryCache;
- /** @var CappedMemoryCache|array */
- private $filesCache;
+ /** @var CappedMemoryCache<array> */
+ private CappedMemoryCache $filesCache;
- /** @var IMimeTypeDetector */
- private $mimeDetector;
-
- /** @var bool|null */
- private $versioningEnabled = null;
-
- /** @var IMemcache */
- private $memCache;
+ private IMimeTypeDetector $mimeDetector;
+ private ?bool $versioningEnabled = null;
+ private ICache $memCache;
public function __construct($parameters) {
parent::__construct($parameters);
@@ -146,10 +142,9 @@ class AmazonS3 extends \OC\Files\Storage\Common {
}
/**
- * @param $key
* @return array|false
*/
- private function headObject($key) {
+ private function headObject(string $key) {
if (!isset($this->objectCache[$key])) {
try {
$this->objectCache[$key] = $this->getConnection()->headObject([
@@ -165,6 +160,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
}
if (is_array($this->objectCache[$key]) && !isset($this->objectCache[$key]["Key"])) {
+ /** @psalm-suppress InvalidArgument Psalm doesn't understand nested arrays well */
$this->objectCache[$key]["Key"] = $key;
}
return $this->objectCache[$key];
diff --git a/apps/files_external/lib/Lib/Storage/SMB.php b/apps/files_external/lib/Lib/Storage/SMB.php
index c2555f87b93..bdb9b4f9c8f 100644
--- a/apps/files_external/lib/Lib/Storage/SMB.php
+++ b/apps/files_external/lib/Lib/Storage/SMB.php
@@ -84,10 +84,8 @@ class SMB extends Common implements INotifyStorage {
*/
protected $root;
- /**
- * @var IFileInfo[]
- */
- protected $statCache;
+ /** @var CappedMemoryCache<IFileInfo> */
+ protected CappedMemoryCache $statCache;
/** @var ILogger */
protected $logger;
@@ -527,7 +525,7 @@ class SMB extends Common implements INotifyStorage {
}
try {
- $this->statCache = [];
+ $this->statCache = new CappedMemoryCache();
$content = $this->share->dir($this->buildPath($path));
foreach ($content as $file) {
if ($file->isDirectory()) {
diff --git a/apps/files_sharing/lib/MountProvider.php b/apps/files_sharing/lib/MountProvider.php
index bfb40387622..d27f9e5e0da 100644
--- a/apps/files_sharing/lib/MountProvider.php
+++ b/apps/files_sharing/lib/MountProvider.php
@@ -109,6 +109,7 @@ class MountProvider implements IMountProvider {
$view = new View('/' . $user->getUID() . '/files');
$ownerViews = [];
$sharingDisabledForUser = $this->shareManager->sharingDisabledForUser($user->getUID());
+ /** @var CappedMemoryCache<bool> $folderExistCache */
$foldersExistCache = new CappedMemoryCache();
foreach ($superShares as $share) {
try {
diff --git a/apps/files_sharing/lib/SharedMount.php b/apps/files_sharing/lib/SharedMount.php
index 398da5eaf23..95ff66c4b71 100644
--- a/apps/files_sharing/lib/SharedMount.php
+++ b/apps/files_sharing/lib/SharedMount.php
@@ -96,6 +96,7 @@ class SharedMount extends MountPoint implements MoveableMount {
*
* @param \OCP\Share\IShare $share
* @param SharedMount[] $mountpoints
+ * @param CappedMemoryCache<bool> $folderExistCache
* @return string
*/
private function verifyMountPoint(
diff --git a/apps/user_ldap/lib/Group_LDAP.php b/apps/user_ldap/lib/Group_LDAP.php
index f9d9b061743..8fcb10cb850 100644
--- a/apps/user_ldap/lib/Group_LDAP.php
+++ b/apps/user_ldap/lib/Group_LDAP.php
@@ -55,12 +55,12 @@ use Psr\Log\LoggerInterface;
class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, IGetDisplayNameBackend, IDeleteGroupBackend {
protected $enabled = false;
- /** @var string[][] $cachedGroupMembers array of users with gid as key */
- protected $cachedGroupMembers;
- /** @var string[] $cachedGroupsByMember array of groups with uid as key */
- protected $cachedGroupsByMember;
- /** @var string[] $cachedNestedGroups array of groups with gid (DN) as key */
- protected $cachedNestedGroups;
+ /** @var CappedMemoryCache<string[]> $cachedGroupMembers array of users with gid as key */
+ protected CappedMemoryCache $cachedGroupMembers;
+ /** @var CappedMemoryCache<string[]> $cachedGroupsByMember array of groups with uid as key */
+ protected CappedMemoryCache $cachedGroupsByMember;
+ /** @var CappedMemoryCache<string[]> $cachedNestedGroups array of groups with gid (DN) as key */
+ protected CappedMemoryCache $cachedNestedGroups;
/** @var GroupPluginManager */
protected $groupPluginManager;
/** @var LoggerInterface */
diff --git a/apps/user_ldap/lib/Helper.php b/apps/user_ldap/lib/Helper.php
index 437fab6b6a8..3ca5de67874 100644
--- a/apps/user_ldap/lib/Helper.php
+++ b/apps/user_ldap/lib/Helper.php
@@ -35,15 +35,10 @@ use OCP\IConfig;
use OCP\IDBConnection;
class Helper {
-
- /** @var IConfig */
- private $config;
-
- /** @var IDBConnection */
- private $connection;
-
- /** @var CappedMemoryCache */
- protected $sanitizeDnCache;
+ private IConfig $config;
+ private IDBConnection $connection;
+ /** @var CappedMemoryCache<string> */
+ protected CappedMemoryCache $sanitizeDnCache;
public function __construct(IConfig $config,
IDBConnection $connection) {
diff --git a/apps/user_ldap/lib/User/Manager.php b/apps/user_ldap/lib/User/Manager.php
index e752b113e3f..e52b093f5af 100644
--- a/apps/user_ldap/lib/User/Manager.php
+++ b/apps/user_ldap/lib/User/Manager.php
@@ -47,43 +47,20 @@ use Psr\Log\LoggerInterface;
* cache
*/
class Manager {
- /** @var Access */
- protected $access;
-
- /** @var IConfig */
- protected $ocConfig;
-
- /** @var IDBConnection */
- protected $db;
-
- /** @var IUserManager */
- protected $userManager;
-
- /** @var INotificationManager */
- protected $notificationManager;
-
- /** @var FilesystemHelper */
- protected $ocFilesystem;
-
- /** @var LoggerInterface */
- protected $logger;
-
- /** @var Image */
- protected $image;
-
- /** @param \OCP\IAvatarManager */
- protected $avatarManager;
-
- /**
- * @var CappedMemoryCache $usersByDN
- */
- protected $usersByDN;
- /**
- * @var CappedMemoryCache $usersByUid
- */
- protected $usersByUid;
- /** @var IManager */
- private $shareManager;
+ protected ?Access $access = null;
+ protected IConfig $ocConfig;
+ protected IDBConnection $db;
+ protected IUserManager $userManager;
+ protected INotificationManager $notificationManager;
+ protected FilesystemHelper $ocFilesystem;
+ protected LoggerInterface $logger;
+ protected Image $image;
+ protected IAvatarManager $avatarManager;
+ /** @var CappedMemoryCache<User> $usersByDN */
+ protected CappedMemoryCache $usersByDN;
+ /** @var CappedMemoryCache<User> $usersByUid */
+ protected CappedMemoryCache $usersByUid;
+ private IManager $shareManager;
public function __construct(
IConfig $ocConfig,
diff --git a/apps/workflowengine/lib/Manager.php b/apps/workflowengine/lib/Manager.php
index 34dbf507b91..f6c3e3086c2 100644
--- a/apps/workflowengine/lib/Manager.php
+++ b/apps/workflowengine/lib/Manager.php
@@ -109,8 +109,8 @@ class Manager implements IManager {
/** @var ILogger */
protected $logger;
- /** @var CappedMemoryCache */
- protected $operationsByScope = [];
+ /** @var CappedMemoryCache<int[]> */
+ protected CappedMemoryCache $operationsByScope;
/** @var IUserSession */
protected $session;
@@ -350,10 +350,11 @@ class Manager implements IManager {
$qb->setParameters(['scope' => $scopeContext->getScope(), 'scopeId' => $scopeContext->getScopeId()]);
$result = $qb->execute();
- $this->operationsByScope[$scopeContext->getHash()] = [];
+ $operations = [];
while (($opId = $result->fetchOne()) !== false) {
- $this->operationsByScope[$scopeContext->getHash()][] = (int)$opId;
+ $operations[] = (int)$opId;
}
+ $this->operationsByScope[$scopeContext->getHash()] = $operations;
$result->closeCursor();
return in_array($id, $this->operationsByScope[$scopeContext->getHash()], true);
diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml
index 7152a3fbffe..60b1a435339 100644
--- a/build/psalm-baseline.xml
+++ b/build/psalm-baseline.xml
@@ -1371,9 +1371,7 @@
</InvalidReturnType>
</file>
<file src="apps/files_external/lib/Lib/Storage/SMB.php">
- <InvalidPropertyAssignmentValue occurrences="1">
- <code>new CappedMemoryCache()</code>
- </InvalidPropertyAssignmentValue>
+ <InvalidPropertyAssignmentValue occurrences="1"/>
<InvalidScalarArgument occurrences="7">
<code>$e-&gt;getCode()</code>
<code>$e-&gt;getCode()</code>
@@ -1911,16 +1909,6 @@
<ParadoxicalCondition occurrences="1"/>
</file>
<file src="apps/user_ldap/lib/Group_LDAP.php">
- <InvalidArgument occurrences="1">
- <code>$this-&gt;cachedGroupsByMember[$uid]</code>
- </InvalidArgument>
- <InvalidPropertyAssignmentValue occurrences="5">
- <code>$this-&gt;cachedGroupsByMember</code>
- <code>$this-&gt;cachedNestedGroups</code>
- <code>new CappedMemoryCache()</code>
- <code>new CappedMemoryCache()</code>
- <code>new CappedMemoryCache()</code>
- </InvalidPropertyAssignmentValue>
<InvalidReturnStatement occurrences="1">
<code>$groupName</code>
</InvalidReturnStatement>
@@ -2116,9 +2104,6 @@
<InvalidOperand occurrences="1">
<code>$result</code>
</InvalidOperand>
- <InvalidPropertyAssignmentValue occurrences="1">
- <code>[]</code>
- </InvalidPropertyAssignmentValue>
<InvalidReturnStatement occurrences="1">
<code>$result</code>
</InvalidReturnStatement>
@@ -2989,11 +2974,6 @@
<code>getShareForToken</code>
</UndefinedMethod>
</file>
- <file src="lib/private/Encryption/File.php">
- <InvalidPropertyAssignmentValue occurrences="1">
- <code>new CappedMemoryCache()</code>
- </InvalidPropertyAssignmentValue>
- </file>
<file src="lib/private/Encryption/Keys/Storage.php">
<InvalidNullableReturnType occurrences="1">
<code>deleteUserKey</code>
@@ -3123,17 +3103,6 @@
<LessSpecificImplementedReturnType occurrences="1">
<code>array</code>
</LessSpecificImplementedReturnType>
- <UndefinedInterfaceMethod occurrences="9">
- <code>$this-&gt;cacheInfoCache</code>
- <code>$this-&gt;cacheInfoCache</code>
- <code>$this-&gt;cacheInfoCache</code>
- <code>$this-&gt;mountsForUsers</code>
- <code>$this-&gt;mountsForUsers</code>
- <code>$this-&gt;mountsForUsers</code>
- <code>$this-&gt;mountsForUsers</code>
- <code>$this-&gt;mountsForUsers</code>
- <code>$this-&gt;mountsForUsers</code>
- </UndefinedInterfaceMethod>
</file>
<file src="lib/private/Files/Filesystem.php">
<InvalidNullableReturnType occurrences="1">
diff --git a/lib/private/Cache/CappedMemoryCache.php b/lib/private/Cache/CappedMemoryCache.php
index 0a3300435eb..6063b5e7110 100644
--- a/lib/private/Cache/CappedMemoryCache.php
+++ b/lib/private/Cache/CappedMemoryCache.php
@@ -88,7 +88,7 @@ class CappedMemoryCache implements ICache, \ArrayAccess {
}
/**
- * @param string $key
+ * @param string $offset
* @param T $value
* @return void
*/
diff --git a/lib/private/Diagnostics/QueryLogger.php b/lib/private/Diagnostics/QueryLogger.php
index 499947178a3..40d68d94ae3 100644
--- a/lib/private/Diagnostics/QueryLogger.php
+++ b/lib/private/Diagnostics/QueryLogger.php
@@ -28,15 +28,10 @@ use OC\Cache\CappedMemoryCache;
use OCP\Diagnostics\IQueryLogger;
class QueryLogger implements IQueryLogger {
- /**
- * @var \OC\Diagnostics\Query
- */
- protected $activeQuery;
-
- /**
- * @var CappedMemoryCache
- */
- protected $queries;
+ protected int $index = 0;
+ protected ?Query $activeQuery = null;
+ /** @var CappedMemoryCache<Query> */
+ protected CappedMemoryCache $queries;
/**
* QueryLogger constructor.
@@ -74,7 +69,8 @@ class QueryLogger implements IQueryLogger {
public function stopQuery() {
if ($this->activated && $this->activeQuery) {
$this->activeQuery->end(microtime(true));
- $this->queries[] = $this->activeQuery;
+ $this->queries[(string)$this->index] = $this->activeQuery;
+ $this->index++;
$this->activeQuery = null;
}
}
diff --git a/lib/private/Encryption/File.php b/lib/private/Encryption/File.php
index 2c486dfade6..2d7e23a8883 100644
--- a/lib/private/Encryption/File.php
+++ b/lib/private/Encryption/File.php
@@ -47,9 +47,9 @@ class File implements \OCP\Encryption\IFile {
/**
* cache results of already checked folders
*
- * @var array
+ * @var CappedMemoryCache<array>
*/
- protected $cache;
+ protected CappedMemoryCache $cache;
public function __construct(Util $util,
IRootFolder $rootFolder,
@@ -62,10 +62,10 @@ class File implements \OCP\Encryption\IFile {
/**
- * get list of users with access to the file
+ * Get list of users with access to the file
*
* @param string $path to the file
- * @return array ['users' => $uniqueUserIds, 'public' => $public]
+ * @return array{users: string[], public: bool}
*/
public function getAccessList($path) {
diff --git a/lib/private/Encryption/Util.php b/lib/private/Encryption/Util.php
index dc878ba8fc1..693e24c4721 100644
--- a/lib/private/Encryption/Util.php
+++ b/lib/private/Encryption/Util.php
@@ -220,7 +220,7 @@ class Util {
* get the owner and the path for the file relative to the owners files folder
*
* @param string $path
- * @return array
+ * @return array{0: string, 1: string}
* @throws \BadMethodCallException
*/
public function getUidAndFilename($path) {
diff --git a/lib/private/Files/AppData/AppData.php b/lib/private/Files/AppData/AppData.php
index 53f69be7127..471de799c2f 100644
--- a/lib/private/Files/AppData/AppData.php
+++ b/lib/private/Files/AppData/AppData.php
@@ -38,21 +38,12 @@ use OCP\Files\NotPermittedException;
use OCP\Files\SimpleFS\ISimpleFolder;
class AppData implements IAppData {
-
- /** @var IRootFolder */
- private $rootFolder;
-
- /** @var SystemConfig */
- private $config;
-
- /** @var string */
- private $appId;
-
- /** @var Folder */
- private $folder;
-
- /** @var (ISimpleFolder|NotFoundException)[]|CappedMemoryCache */
- private $folders;
+ private IRootFolder $rootFolder;
+ private SystemConfig $config;
+ private string $appId;
+ private ?Folder $folder = null;
+ /** @var CappedMemoryCache<ISimpleFolder|NotFoundException> */
+ private CappedMemoryCache $folders;
/**
* AppData constructor.
diff --git a/lib/private/Files/Config/UserMountCache.php b/lib/private/Files/Config/UserMountCache.php
index a5fe04c2cac..c326eeb0b6c 100644
--- a/lib/private/Files/Config/UserMountCache.php
+++ b/lib/private/Files/Config/UserMountCache.php
@@ -36,7 +36,6 @@ use OCP\Files\Config\ICachedMountInfo;
use OCP\Files\Config\IUserMountCache;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\NotFoundException;
-use OCP\ICache;
use OCP\IDBConnection;
use OCP\IUser;
use OCP\IUserManager;
@@ -46,30 +45,17 @@ use Psr\Log\LoggerInterface;
* Cache mounts points per user in the cache so we can easilly look them up
*/
class UserMountCache implements IUserMountCache {
- /**
- * @var IDBConnection
- */
- private $connection;
-
- /**
- * @var IUserManager
- */
- private $userManager;
+ private IDBConnection $connection;
+ private IUserManager $userManager;
/**
* Cached mount info.
- * Map of $userId to ICachedMountInfo.
- *
- * @var ICache
+ * @var CappedMemoryCache<ICachedMountInfo[]>
**/
- private $mountsForUsers;
-
+ private CappedMemoryCache $mountsForUsers;
private LoggerInterface $logger;
-
- /**
- * @var ICache
- */
- private $cacheInfoCache;
+ /** @var CappedMemoryCache<array> */
+ private CappedMemoryCache $cacheInfoCache;
/**
* UserMountCache constructor.
@@ -132,6 +118,7 @@ class UserMountCache implements IUserMountCache {
foreach ($addedMounts as $mount) {
$this->addToCache($mount);
+ /** @psalm-suppress InvalidArgument */
$this->mountsForUsers[$user->getUID()][] = $mount;
}
foreach ($removedMounts as $mount) {
diff --git a/tests/lib/Files/Config/UserMountCacheTest.php b/tests/lib/Files/Config/UserMountCacheTest.php
index f4c6a427abd..221159bc983 100644
--- a/tests/lib/Files/Config/UserMountCacheTest.php
+++ b/tests/lib/Files/Config/UserMountCacheTest.php
@@ -11,6 +11,7 @@ namespace Test\Files\Config;
use OC\DB\QueryBuilder\Literal;
use OC\Files\Mount\MountPoint;
use OC\Files\Storage\Storage;
+use OC\Cache\CappedMemoryCache;
use OC\User\Manager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\ICachedMountInfo;
@@ -114,7 +115,7 @@ class UserMountCacheTest extends TestCase {
}
private function clearCache() {
- $this->invokePrivate($this->cache, 'mountsForUsers', [[]]);
+ $this->invokePrivate($this->cache, 'mountsForUsers', [new CappedMemoryCache()]);
}
public function testNewMounts() {