Skip to content

Commit

Permalink
Merge pull request #3245 from nextcloud/fix/psalm/param-property-retu…
Browse files Browse the repository at this point in the history
…rn-types

fix: Fix all property, param and return types
  • Loading branch information
come-nc authored Sep 19, 2024
2 parents 3caf402 + a21dac1 commit 83acbe3
Show file tree
Hide file tree
Showing 69 changed files with 400 additions and 722 deletions.
33 changes: 16 additions & 17 deletions lib/ACL/ACLCacheWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@
use OCP\Files\Search\ISearchQuery;

class ACLCacheWrapper extends CacheWrapper {
private ACLManager $aclManager;
private bool $inShare;
public function __construct(
ICache $cache,
private ACLManager $aclManager,
private bool $inShare,
) {
parent::__construct($cache);
}

private function getACLPermissionsForPath(string $path, array $rules = []) {
private function getACLPermissionsForPath(string $path, array $rules = []): int {
if ($rules) {
$permissions = $this->aclManager->getPermissionsForPathFromRules($path, $rules);
} else {
Expand All @@ -37,13 +42,7 @@ private function getACLPermissionsForPath(string $path, array $rules = []) {
return $canRead ? $permissions : 0;
}

public function __construct(ICache $cache, ACLManager $aclManager, bool $inShare) {
parent::__construct($cache);
$this->aclManager = $aclManager;
$this->inShare = $inShare;
}

protected function formatCacheEntry($entry, array $rules = []) {
protected function formatCacheEntry($entry, array $rules = []): ICacheEntry|false {
if (isset($entry['permissions'])) {
$entry['scan_permissions'] = $entry['permissions'];
$entry['permissions'] &= $this->getACLPermissionsForPath($entry['path'], $rules);
Expand All @@ -55,30 +54,30 @@ protected function formatCacheEntry($entry, array $rules = []) {
return $entry;
}

public function getFolderContentsById($fileId) {
public function getFolderContentsById($fileId): array {
$results = $this->getCache()->getFolderContentsById($fileId);
$rules = $this->preloadEntries($results);

return array_filter(array_map(function ($entry) use ($rules) {
return array_filter(array_map(function (ICacheEntry $entry) use ($rules): ICacheEntry|false {
return $this->formatCacheEntry($entry, $rules);
}, $results));
}

public function search($pattern) {
public function search($pattern): array {
$results = $this->getCache()->search($pattern);
$this->preloadEntries($results);

return array_filter(array_map($this->formatCacheEntry(...), $results));
}

public function searchByMime($mimetype) {
public function searchByMime($mimetype): array {
$results = $this->getCache()->searchByMime($mimetype);
$this->preloadEntries($results);

return array_filter(array_map($this->formatCacheEntry(...), $results));
}

public function searchQuery(ISearchQuery $query) {
public function searchQuery(ISearchQuery $query): array {
$results = $this->getCache()->searchQuery($query);
$this->preloadEntries($results);

Expand All @@ -87,10 +86,10 @@ public function searchQuery(ISearchQuery $query) {

/**
* @param ICacheEntry[] $entries
* @return Rule[][]
* @return array<string, Rule[]>
*/
private function preloadEntries(array $entries): array {
$paths = array_map(function (ICacheEntry $entry) {
$paths = array_map(function (ICacheEntry $entry): string {
return $entry->getPath();
}, $entries);

Expand Down
20 changes: 5 additions & 15 deletions lib/ACL/ACLManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,17 @@

class ACLManager {
private CappedMemoryCache $ruleCache;
/** @var callable */
private $rootFolderProvider;

public function __construct(
private RuleManager $ruleManager,
private RuleManager $ruleManager,
private TrashManager $trashManager,
private LoggerInterface $logger,
private IUser $user,
callable $rootFolderProvider,
private ?int $rootStorageId = null,
private bool $inheritMergePerUser = false,
private IUser $user,
private \Closure $rootFolderProvider,
private ?int $rootStorageId = null,
private bool $inheritMergePerUser = false,
) {
$this->ruleCache = new CappedMemoryCache();
$this->rootFolderProvider = $rootFolderProvider;
}

private function getRootStorageId(): int {
Expand Down Expand Up @@ -84,7 +81,6 @@ private function getRules(array $paths, bool $cache = true): array {
*
* This contains the $path itself and any parent folder
*
* @param string $path
* @return string[]
*/
private function getRelevantPaths(string $path): array {
Expand Down Expand Up @@ -147,9 +143,7 @@ public function getACLPermissionsForPath(string $path): int {
}

/**
* @param string $path
* @param array<string, Rule[]> $rules list of rules per path
* @return int
*/
public function getPermissionsForPathFromRules(string $path, array $rules): int {
$path = ltrim($path, '/');
Expand All @@ -161,7 +155,6 @@ public function getPermissionsForPathFromRules(string $path, array $rules): int

/**
* @param array<string, Rule[]> $rules list of rules per path, sorted parent first
* @return int
*/
private function calculatePermissionsForPath(array $rules): int {
// given the following rules
Expand Down Expand Up @@ -212,9 +205,6 @@ private function calculatePermissionsForPath(array $rules): int {

/**
* Get the combined "lowest" permissions for an entire directory tree
*
* @param string $path
* @return int
*/
public function getPermissionsForTree(string $path): int {
$path = ltrim($path, '/');
Expand Down
5 changes: 1 addition & 4 deletions lib/ACL/ACLManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@
use Psr\Log\LoggerInterface;

class ACLManagerFactory {
private $rootFolderProvider;

public function __construct(
private RuleManager $ruleManager,
private TrashManager $trashManager,
private IConfig $config,
private LoggerInterface $logger,
callable $rootFolderProvider,
private \Closure $rootFolderProvider,
) {
$this->rootFolderProvider = $rootFolderProvider;
}

public function getACLManager(IUser $user, ?int $rootStorageId = null): ACLManager {
Expand Down
Loading

0 comments on commit 83acbe3

Please sign in to comment.