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

fix(IStorage): Use false instead of bool intersection type to match implementations #48219

Merged
merged 6 commits into from
Sep 27, 2024

Conversation

provokateurin
Copy link
Member

Summary

This adds strong return types to all implementations to match the interface.
The changes escalated a bit, but everything should be fixed at once.
It also fixes some bugs in poorly implemented storages.

Technically this is a breaking change due to changing the signature, but I only did that for private classes and the fix is completely backwards compatible.
The temporary pain of adding the return types to all implementations is justified by fixing all these type mismatches for once.
This change should also allow us to actually add the strong return types to IStorage since all implementations should also be extending Common which already has them.
Please don't hate me for this change 🙈

I was not able to test files_external due to the terrible test setup which I can not get working locally, so let's see what CI has to say.

Checklist

@provokateurin provokateurin added this to the Nextcloud 31 milestone Sep 19, 2024
@provokateurin provokateurin changed the title fix(files_trashbin): Fix all IStorage return types fix(IStorage): Use false instead of bool intersection type to match implementations Sep 19, 2024
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

Psalm found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

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.

To be continued…

apps/files_external/lib/Lib/Storage/AmazonS3.php Outdated Show resolved Hide resolved
apps/files_external/lib/Lib/Storage/AmazonS3.php Outdated Show resolved Hide resolved
apps/files_external/lib/Lib/Storage/FTP.php Show resolved Hide resolved
apps/files_external/lib/Lib/Storage/FTP.php Outdated Show resolved Hide resolved
apps/files_external/lib/Lib/Storage/FTP.php Outdated Show resolved Hide resolved
apps/files_external/lib/Lib/Storage/SFTP.php Outdated Show resolved Hide resolved
apps/files_external/lib/Lib/Storage/SFTP.php Outdated Show resolved Hide resolved
apps/files_external/lib/Lib/Storage/SMB.php Outdated Show resolved Hide resolved
apps/files_external/lib/Lib/Storage/Swift.php Outdated Show resolved Hide resolved
@provokateurin
Copy link
Member Author

I hope I fixed all the weird typings, but please take another look.

Signed-off-by: provokateurin <kate@provokateurin.de>
Signed-off-by: provokateurin <kate@provokateurin.de>
Signed-off-by: provokateurin <kate@provokateurin.de>
Signed-off-by: provokateurin <kate@provokateurin.de>
Signed-off-by: provokateurin <kate@provokateurin.de>
…mplementations

Signed-off-by: provokateurin <kate@provokateurin.de>
@provokateurin provokateurin merged commit 4f88123 into master Sep 27, 2024
175 checks passed
@provokateurin provokateurin deleted the fix/istorage/return-types branch September 27, 2024 05:40
@nickvergessen
Copy link
Member

This breaks all apps that have a storage wrapper.
Despite being in OC, it's de-facto standard and should be kept stable...

At least it should be documented

@nickvergessen nickvergessen added the pending documentation This pull request needs an associated documentation update label Sep 29, 2024
@@ -823,7 +750,7 @@ public function writeStream(string $path, $stream, ?int $size = null): int {
return $count;
}

public function getDirectoryContent($directory): \Traversable {
public function getDirectoryContent($directory): \Traversable|false {
Copy link
Contributor

Choose a reason for hiding this comment

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

I missed this change, can you explain why the |false?
There is no return false in there.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok I thought I remembered that one of the implementations returns false so every implementation has to handle it, but I was wrong. The only error handling I could find was done using exceptions, so I will revert this.

vitormattos added a commit to vitormattos/groupquota that referenced this pull request Oct 7, 2024
After the PR nextcloud/server#48219 the
signatore of this method was changed and now is necessary to have return
typing.

Problem fixed:

```
Declaration of OCA\\GroupQuota\\Wrapper\\GroupQuotaWrapper::getCache($path = '', $storage = null) must be compatible with OC\\Files\\Storage\\Wrapper\\Wrapper::getCache($path = '', $storage = null): OCP\\Files\\Cache\\ICache at /var/www/html/apps-writable/groupquota/lib/Wrapper/GroupQuotaWrapper.php#35
```

Server version affected: >= 31

Signed-off-by: Vitor Mattos <vitor@php.rio>
@provokateurin provokateurin removed the pending documentation This pull request needs an associated documentation update label Oct 14, 2024
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.

4 participants