use OCP\ICacheFactory;
use OCP\IMemcache;
use OCP\Server;
+use OCP\ICache;
class AmazonS3 extends \OC\Files\Storage\Common {
use S3ConnectionTrait;
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);
}
/**
- * @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([
}
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];
*/
protected $root;
- /**
- * @var IFileInfo[]
- */
- protected $statCache;
+ /** @var CappedMemoryCache<IFileInfo> */
+ protected CappedMemoryCache $statCache;
/** @var ILogger */
protected $logger;
}
try {
- $this->statCache = [];
+ $this->statCache = new CappedMemoryCache();
$content = $this->share->dir($this->buildPath($path));
foreach ($content as $file) {
if ($file->isDirectory()) {
$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 {
*
* @param \OCP\Share\IShare $share
* @param SharedMount[] $mountpoints
+ * @param CappedMemoryCache<bool> $folderExistCache
* @return string
*/
private function verifyMountPoint(
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 */
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) {
* 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,
/** @var ILogger */
protected $logger;
- /** @var CappedMemoryCache */
- protected $operationsByScope = [];
+ /** @var CappedMemoryCache<int[]> */
+ protected CappedMemoryCache $operationsByScope;
/** @var IUserSession */
protected $session;
$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);
</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->getCode()</code>
<code>$e->getCode()</code>
<ParadoxicalCondition occurrences="1"/>
</file>
<file src="apps/user_ldap/lib/Group_LDAP.php">
- <InvalidArgument occurrences="1">
- <code>$this->cachedGroupsByMember[$uid]</code>
- </InvalidArgument>
- <InvalidPropertyAssignmentValue occurrences="5">
- <code>$this->cachedGroupsByMember</code>
- <code>$this->cachedNestedGroups</code>
- <code>new CappedMemoryCache()</code>
- <code>new CappedMemoryCache()</code>
- <code>new CappedMemoryCache()</code>
- </InvalidPropertyAssignmentValue>
<InvalidReturnStatement occurrences="1">
<code>$groupName</code>
</InvalidReturnStatement>
<InvalidOperand occurrences="1">
<code>$result</code>
</InvalidOperand>
- <InvalidPropertyAssignmentValue occurrences="1">
- <code>[]</code>
- </InvalidPropertyAssignmentValue>
<InvalidReturnStatement occurrences="1">
<code>$result</code>
</InvalidReturnStatement>
<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>
<LessSpecificImplementedReturnType occurrences="1">
<code>array</code>
</LessSpecificImplementedReturnType>
- <UndefinedInterfaceMethod occurrences="9">
- <code>$this->cacheInfoCache</code>
- <code>$this->cacheInfoCache</code>
- <code>$this->cacheInfoCache</code>
- <code>$this->mountsForUsers</code>
- <code>$this->mountsForUsers</code>
- <code>$this->mountsForUsers</code>
- <code>$this->mountsForUsers</code>
- <code>$this->mountsForUsers</code>
- <code>$this->mountsForUsers</code>
- </UndefinedInterfaceMethod>
</file>
<file src="lib/private/Files/Filesystem.php">
<InvalidNullableReturnType occurrences="1">
}
/**
- * @param string $key
+ * @param string $offset
* @param T $value
* @return void
*/
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.
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;
}
}
/**
* cache results of already checked folders
*
- * @var array
+ * @var CappedMemoryCache<array>
*/
- protected $cache;
+ protected CappedMemoryCache $cache;
public function __construct(Util $util,
IRootFolder $rootFolder,
/**
- * 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) {
* 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) {
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.
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;
* 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.
foreach ($addedMounts as $mount) {
$this->addToCache($mount);
+ /** @psalm-suppress InvalidArgument */
$this->mountsForUsers[$user->getUID()][] = $mount;
}
foreach ($removedMounts as $mount) {
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;
}
private function clearCache() {
- $this->invokePrivate($this->cache, 'mountsForUsers', [[]]);
+ $this->invokePrivate($this->cache, 'mountsForUsers', [new CappedMemoryCache()]);
}
public function testNewMounts() {