-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Remove usage of static vars or properties #59002
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
Open
come-nc
wants to merge
23
commits into
master
Choose a base branch
from
fix/remove-static-vars
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+408
−265
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
58bc96a
fix: Remove static var in Memcache/Redis
come-nc e4e1c46
fix: Remove static vars in TaskProcessing, TextProcessing, TextToImage
come-nc 7f3d2f8
chore: Remove types from const properties
come-nc 9cd72b7
feat: Add a psalm plugin to forbid static properties and variables
come-nc 8248c73
fix: Remove static vars in trashbin, versions and storages
come-nc db9128f
chore: Move Util static property to top of the file
come-nc 82b06c7
chore: Remove static vars in TemplateLayout
come-nc 84c33b2
fix: Add a factory for Memcached object instead of a static var
come-nc ed35b1a
fix: Fix TemplateLayout tests
come-nc 3c99734
fix: Remove static vars in preview Generator
come-nc 69a670d
fix: Remove static var is Access class
come-nc 361e925
fix: Use a CappedMemoryCache instead of an array to cache stuff in us…
come-nc b95495f
fix: Turn static var into standard one in Tags class
come-nc cca08ec
fix: Remove static property use in SeekableHttpStream
come-nc ce50b1b
fix: Fix suppressing ImpureStaticProperty and suppress it in a few pl…
come-nc 6827da0
chore: Remove dead code detected by psalm
come-nc 27c8d42
chore(user_ldap): Move static var to static property and silence warning
come-nc 7391c49
chore: Silence psalm false-positives
come-nc 702f9ea
fix(user_ldap): Move accesses to AccessFactory instead of static var
come-nc dd80bc2
chore(files_versions): Be extra-cautious to please psalm
come-nc 19a85a9
chore: Suppress last known impure static properties
come-nc ab6109b
chore: Get cache lazily in OC\Memcache\Redis
come-nc a1036fe
fix: Make sure getNumConcurrentPreviews never returns 0
come-nc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| use PhpParser\Node\Stmt\Property; | ||
| use PhpParser\Node\Stmt\Static_; | ||
| use Psalm\CodeLocation; | ||
| use Psalm\IssueBuffer; | ||
| use Psalm\Plugin\EventHandler\AfterStatementAnalysisInterface; | ||
| use Psalm\Plugin\EventHandler\Event\AfterStatementAnalysisEvent; | ||
|
|
||
| /** | ||
| * Complains about static property in classes and static vars in methods | ||
| */ | ||
| class StaticVarsChecker implements AfterStatementAnalysisInterface { | ||
| public static function afterStatementAnalysis(AfterStatementAnalysisEvent $event): ?bool { | ||
| $stmt = $event->getStmt(); | ||
| if ($stmt instanceof Property) { | ||
| if ($stmt->isStatic()) { | ||
| IssueBuffer::maybeAdd( | ||
| // ImpureStaticProperty is close enough, all static properties are impure to my eyes | ||
| new \Psalm\Issue\ImpureStaticProperty( | ||
| 'Static property should not be used as they do not follow requests lifecycle', | ||
| new CodeLocation($event->getStatementsSource(), $stmt), | ||
| ), | ||
| $event->getStatementsSource()->getSuppressedIssues(), | ||
| ); | ||
| } | ||
| } elseif ($stmt instanceof Static_) { | ||
| IssueBuffer::maybeAdd( | ||
| // Same logic | ||
| new \Psalm\Issue\ImpureStaticVariable( | ||
| 'Static var should not be used as they do not follow requests lifecycle and are hard to reset', | ||
| new CodeLocation($event->getStatementsSource(), $stmt), | ||
| ), | ||
| $event->getStatementsSource()->getSuppressedIssues(), | ||
| ); | ||
| } | ||
| return null; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| class StaticVarsTest { | ||
| public static $forbiddenStaticProperty; | ||
| protected static $forbiddenProtectedStaticProperty; | ||
| private static $forbiddenPrivateStaticProperty; | ||
| private static $forbiddenPrivateStaticPropertyWithValue = []; | ||
|
|
||
| public function normalFunction(): void { | ||
| static $forbiddenStaticVar = false; | ||
| } | ||
|
|
||
| public static function staticFunction(): void { | ||
| static $forbiddenStaticVar = false; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.