Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(Files\Storage): Strong-type properties #49064

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

provokateurin
Copy link
Member

Summary

Added strong types where possible (mostly with rector and a modified config file).
Rector also added some return types and other cleanups.

Checklist

@provokateurin provokateurin added this to the Nextcloud 31 milestone Nov 4, 2024
@provokateurin provokateurin added 2. developing Work in progress and removed 3. to review Waiting for reviews labels Nov 4, 2024
@provokateurin provokateurin marked this pull request as draft November 4, 2024 09:29
Signed-off-by: provokateurin <kate@provokateurin.de>
Signed-off-by: provokateurin <kate@provokateurin.de>
Signed-off-by: provokateurin <kate@provokateurin.de>
@provokateurin provokateurin force-pushed the refactor/storage/strong-type-properties branch from 679152a to a0e2749 Compare November 4, 2024 09:31
Copy link
Contributor

@come-nc come-nc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests failing, also this will break applications I think, a lot of them use Storage classes as parent classes.

@@ -171,7 +171,7 @@ private function parseUnixItem(string $item, string $directory): array {
];
}

private function normalizePermissions(string $permissions) {
private function normalizePermissions(string $permissions): mixed {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private function normalizePermissions(string $permissions): mixed {
private function normalizePermissions(string $permissions): string {

But we might need to update the code for psalm to trust us on this, unless psalm has a stub for array_reduce with templates and stuff.

* @return ICacheEntry
*/
private function getSourceRootInfo() {
private function getSourceRootInfo(): ICacheEntry|false|null {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No way to do better?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw this as well and I think it can be improved.
I was planning to do that later, but I can also do it in this PR.

Comment on lines 85 to 86
if (is_null($this->sourceRootInfo)) {
if (is_null($this->superShare->getNodeCacheEntry())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (is_null($this->sourceRootInfo)) {
if (is_null($this->superShare->getNodeCacheEntry())) {
if (is_null($this->sourceRootInfo)) {
$this->sourceRootInfo = $this->superShare->getNodeCacheEntry()
if (is_null($this->sourceRootInfo)) {

This would avoid the else and calling the method twice

Comment on lines +36 to +39
/**
* @var array<string, bool>
* for which path we execute the repair step to avoid recursions
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/**
* @var array<string, bool>
* for which path we execute the repair step to avoid recursions
*/
/**
* @var array<string, bool> for which path we execute the repair step to avoid recursions
*/

@@ -47,7 +44,7 @@ public function getUnjailedPath(string $path): string {
/**
* This is separate from Wrapper::getWrapperStorage so we can get the jailed storage consistently even if the jail is inside another wrapper
*/
public function getUnjailedStorage(): IStorage {
public function getUnjailedStorage(): ?IStorage {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 🤔

use OCP\Files\Cache\ICacheEntry;
use OCP\Files\FileInfo;
use OCP\Files\Storage\IStorage;

class Quota extends Wrapper {
/** @var callable|null */
protected $quotaCallback;
/** @var int|float|null int on 64bits, float on 32bits for bigint */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this info removed?

/** @var callable|null */
protected $quotaCallback;
/** @var int|float|null int on 64bits, float on 32bits for bigint */
protected ?\Closure $quotaCallback;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it always a closure?

class Wrapper implements Storage, ILockingStorage, IWriteStreamStorage {
protected ?Storage $storage;
public ?ICache $cache = null;
public IScanner $scanner;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scanner is not set in constructor, why is this one not nullable?

@provokateurin
Copy link
Member Author

also this will break applications I think, a lot of them use Storage classes as parent classes.

I don't think so. Any property is either private and the subclass has it's own independent definition or it's protected and the subclass uses the definition of the parent and can not override it either.

@come-nc
Copy link
Contributor

come-nc commented Nov 5, 2024

also this will break applications I think, a lot of them use Storage classes as parent classes.

I don't think so. Any property is either private and the subclass has it's own independent definition or it's protected and the subclass uses the definition of the parent and can not override it either.

I was thinking of return types, but it seems you did not add those to Common/Wrapper, so maybe it will be fine.

@provokateurin
Copy link
Member Author

The return types I already added in the other PR a few weeks ago.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants