Skip to content

Commit

Permalink
fix: Fix all property, param and return types
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <kate@provokateurin.de>
  • Loading branch information
provokateurin committed Sep 17, 2024
1 parent b8a6d00 commit ce21956
Show file tree
Hide file tree
Showing 69 changed files with 361 additions and 724 deletions.
29 changes: 12 additions & 17 deletions lib/ACL/ACLCacheWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
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 @@ -35,13 +36,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 @@ -52,38 +47,38 @@ 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);
return array_filter(array_map([$this, 'formatCacheEntry'], $results));
}

/**
* @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);
return $this->aclManager->getRelevantRulesForPath($paths, false);
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 @@ -83,7 +80,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 @@ -144,9 +140,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 @@ -157,7 +151,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 @@ -207,9 +200,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 ce21956

Please sign in to comment.