Skip to content

Remove usage of static vars or properties#59002

Open
come-nc wants to merge 23 commits into
masterfrom
fix/remove-static-vars
Open

Remove usage of static vars or properties#59002
come-nc wants to merge 23 commits into
masterfrom
fix/remove-static-vars

Conversation

@come-nc
Copy link
Copy Markdown
Contributor

@come-nc come-nc commented Mar 17, 2026

Summary

Static properties, and even worse static vars in methods are hard to reset from outside, and become a major problem when wanting to make use of the worker mode of FrankenPHP or any similar project.

So this PR removes such declarations and adds a psalm custom plugin to forbid their use.

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

@come-nc come-nc added this to the Nextcloud 34 milestone Mar 17, 2026
@come-nc come-nc self-assigned this Mar 17, 2026
@come-nc come-nc added the 2. developing Work in progress label Mar 17, 2026
@come-nc

This comment was marked as resolved.

Comment thread lib/private/Memcache/Redis.php Outdated
Comment thread apps/files_external/lib/Service/BackendService.php Outdated
@come-nc come-nc mentioned this pull request Mar 23, 2026
7 tasks
@come-nc come-nc force-pushed the fix/remove-static-vars branch from 4620c0f to 91ba91a Compare March 24, 2026 13:23
@joshtrichards joshtrichards added the technical debt 🧱 🤔🚀 label Apr 13, 2026
@come-nc come-nc force-pushed the fix/remove-static-vars branch 2 times, most recently from 068218c to 2a29e8e Compare April 28, 2026 14:43
@come-nc come-nc force-pushed the fix/remove-static-vars branch from 2a29e8e to 93cbab6 Compare May 11, 2026 16:45
@come-nc
Copy link
Copy Markdown
Contributor Author

come-nc commented May 12, 2026

@come-nc come-nc force-pushed the fix/remove-static-vars branch 2 times, most recently from 5ac54b5 to af33409 Compare May 21, 2026 09:27
come-nc added 15 commits June 1, 2026 14:08
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Support was added in PHP 8.3 and we need to support 8.2

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
It’s not easy to remove this one but at least make it visible

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
The behaviour of getAppNameFromPath is really different from what was
 mocked, so I’m not sure whether the class behaves as initially
 intended. I adapted the test to match the class behavior for now.

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
There is only one instance so caching in a property is enough.
There were two levels of caching, removed one.

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
It’s actually more correct to cache this per-instance.
What’s less clear is whether this can always fit in memory.

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
…er_ldap

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
…aces

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
come-nc added 5 commits June 1, 2026 14:09
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
We will keep these legacy ones for now. We can search for the
 ImpureStaticProperty suppression and add special treatement for them in
 the frankenphp PR if needed.

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
@come-nc come-nc force-pushed the fix/remove-static-vars branch from af33409 to 19a85a9 Compare June 1, 2026 12:10
@come-nc come-nc added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Jun 1, 2026
@come-nc come-nc modified the milestones: Nextcloud 34, Nextcloud 35 Jun 1, 2026
@come-nc come-nc marked this pull request as ready for review June 1, 2026 12:40
@come-nc come-nc requested a review from a team as a code owner June 1, 2026 12:40
@come-nc come-nc requested review from ArtificialOwl, icewind1991, leftybournes and salmart-dev and removed request for a team June 1, 2026 12:40
Comment thread build/psalm/StaticVarsChecker.php
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
@come-nc come-nc marked this pull request as draft June 1, 2026 14:58
@come-nc come-nc added 2. developing Work in progress and removed 3. to review Waiting for reviews labels Jun 1, 2026
@come-nc

This comment was marked as resolved.

Tests were stuck forever waiting for a semaphore because concurrency was
 returning 0. It was previously working by chance because cache of the
 value in a static var was leaking through tests.

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
@come-nc come-nc force-pushed the fix/remove-static-vars branch from bba8e07 to a1036fe Compare June 1, 2026 16:05
@CarlSchwan CarlSchwan marked this pull request as ready for review June 1, 2026 16:09
@come-nc come-nc added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Jun 1, 2026
@provokateurin
Copy link
Copy Markdown
Member

Can you add an explanation for all @psalm-supress ImpureStaticProperty, so can understand it in the review and anyone else in the future?

@come-nc
Copy link
Copy Markdown
Contributor Author

come-nc commented Jun 1, 2026

Can you add an explanation for all @psalm-supress ImpureStaticProperty, so can understand it in the review and anyone else in the future?

I’ve put an explanation where I could.
The one without explanation are ones which are really impure and should be fixed, but cannot really right now.
Some of them will get a cleanup method like in 4d08ffe later.

I’d like to avoid putting a generic psalm-supress ImpureStaticProperty TODO remove later. The idea is to avoid adding more static properties and have an easy way to search for current ones (search for ImpureStaticProperty or run psalm in info mode)

But if there are some of them specifically where you want an explanation comment on them and I’ll try to add one.
For stuff like Filesystem and versions/trashbin static classes, it’s just bad design technical debt. It’s not easy to remove as it’s used all-over.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews technical debt 🧱 🤔🚀

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants