chore: Improve IStorage::getPermissions typing#59925
Conversation
|
Would be nice to also do this on all setters and getters everywhere. |
5004e8c to
8f7153f
Compare
8f7153f to
8c97258
Compare
Signed-off-by: Carl Schwan <carlschwan@kde.org>
8c97258 to
af73e49
Compare
| /** @var int-mask-of<Constants::PERMISSION_*> $permissions */ | ||
| $permissions = $this->shareManager->getShareByToken($user)->getPermissions(); |
There was a problem hiding this comment.
Move it to the method return type.
There was a problem hiding this comment.
It's already the return type of IShare::getPermissions, I don't get why this is not working :(
There was a problem hiding this comment.
Maybe getShareByToken has a bad return type?
There was a problem hiding this comment.
Nope, it returns a IShare
The error is about int not being equal to the int mask. It feels like there is a bug in psalm with int-mask-of being converted to int implicitly
| $permissions = $storage->getShare()->getPermissions(); | ||
| } else { | ||
| $permissions = $this->info->getPermissions(); | ||
| } | ||
|
|
||
| /* | ||
| * We can always share non moveable mount points with DELETE and UPDATE | ||
| * We can always share non-moveable mount points with DELETE and UPDATE | ||
| * Eventually we need to do this properly | ||
| */ | ||
| $mountpoint = $this->info->getMountPoint(); | ||
| if (!($mountpoint instanceof IMovableMount)) { | ||
| /** | ||
| * @psalm-suppress UnnecessaryVarAnnotation Rector doesn't trust the return type annotation | ||
| * @var string $mountpointpath | ||
| * @var string $mountpointPath | ||
| */ | ||
| $mountpointpath = $mountpoint->getMountPoint(); | ||
| if (str_ends_with($mountpointpath, '/')) { | ||
| $mountpointpath = substr($mountpointpath, 0, -1); | ||
| $mountpointPath = $mountpoint->getMountPoint(); | ||
| if (str_ends_with($mountpointPath, '/')) { | ||
| $mountpointPath = substr($mountpointPath, 0, -1); | ||
| } | ||
|
|
||
| if (!$mountpoint->getOption('readonly', false) && $mountpointpath === $this->info->getPath()) { | ||
| if (!$mountpoint->getOption('readonly', false) && $mountpointPath === $this->info->getPath()) { | ||
| $permissions |= Constants::PERMISSION_DELETE | Constants::PERMISSION_UPDATE; | ||
| } | ||
| } | ||
|
|
||
| /* | ||
| * Files can't have create or delete permissions | ||
| */ | ||
| if ($this->info->getType() === FileInfo::TYPE_FILE) { | ||
| $permissions &= ~(Constants::PERMISSION_CREATE | Constants::PERMISSION_DELETE); | ||
| } | ||
|
|
||
| /** @var int-mask-of<Constants::PERMISSION_*> $permissions */ | ||
| return $permissions; |
There was a problem hiding this comment.
These two getPermissions calls need the correct return type to remove the var annotation.
| /** @var int-mask-of<Constants::PERMISSION_*> $ncPermissions */ | ||
| return $ncPermissions; |
There was a problem hiding this comment.
This should not be needed.
| /** @var int-mask-of<Constants::PERMISSION_*> $permissions */ | ||
| $permissions = parent::getPermissions($path) & $this->superShare->getPermissions(); |
Summary
TODO
Checklist
3. to review, feature component)stable32)AI (if applicable)