Skip to content

Remove usage of static vars or properties#59002

Draft
come-nc wants to merge 17 commits intomasterfrom
fix/remove-static-vars
Draft

Remove usage of static vars or properties#59002
come-nc wants to merge 17 commits intomasterfrom
fix/remove-static-vars

Conversation

@come-nc
Copy link
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 added 11 commits March 17, 2026 15:04
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>
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>
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>
@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
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
@come-nc
Copy link
Contributor Author

come-nc commented Mar 17, 2026

Error: lib/private/TextProcessing/Manager.php:140:13: InvalidArrayOffset: Cannot access value on variable OC\TextProcessing\Manager::COMPATIBLE_TASK_TYPES using a class-string<OCP\TextProcessing\ITaskType> offset, expecting 'OCP\\TextProcessing\\FreePromptTaskType'|'OCP\\TextProcessing\\HeadlineTaskType'|'OCP\\TextProcessing\\SummaryTaskType'|'OCP\\TextProcessing\\TopicsTaskType' (see https://psalm.dev/115)
Error: lib/private/TextProcessing/Manager.php:228:10: InvalidArrayOffset: Cannot access value on variable OC\TextProcessing\Manager::COMPATIBLE_TASK_TYPES using a class-string<OCP\TextProcessing\ITaskType> offset, expecting 'OCP\\TextProcessing\\FreePromptTaskType'|'OCP\\TextProcessing\\HeadlineTaskType'|'OCP\\TextProcessing\\SummaryTaskType'|'OCP\\TextProcessing\\TopicsTaskType' (see https://psalm.dev/115)
Error: lib/private/TextProcessing/Manager.php:229:67: InvalidArrayOffset: Cannot access value on variable OC\TextProcessing\Manager::COMPATIBLE_TASK_TYPES using a class-string<OCP\TextProcessing\ITaskType> offset, expecting 'OCP\\TextProcessing\\FreePromptTaskType'|'OCP\\TextProcessing\\HeadlineTaskType'|'OCP\\TextProcessing\\SummaryTaskType'|'OCP\\TextProcessing\\TopicsTaskType' (see https://psalm.dev/115)

No idea how to explain to psalm that this is fine 🤷

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
come-nc added 4 commits March 17, 2026 16:33
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
There are still some left, harder to remove.

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>
static $eventSent = false;
if (!$eventSent) {
private function callForRegistrations(): void {
if (!$this->eventSent) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This fails in tests because the listener gets the singleton from container and tries to re-register the backend.
It can only happen if code creates BackendService objects.

Not sure how to best fix it.
Ideally we should move to a typed event with a pointer to the backend service. But that cannot be done right away.

Maybe we should get the singleton from container and check eventSent on it?

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

Labels

2. developing Work in progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant