WS004 · Mutable singleton
Default severity: MEDIUM · Framework: Any
What it checks
Section titled “What it checks”A singleton is created once and then reused. Under a persistent worker “once” means once per worker process, so every request shares the same instance and everything written into it.
What to review
Section titled “What to review”- Register the class in your container instead, so its lifetime is controlled by the framework.
- Keep the shared instance immutable: readonly properties set in the constructor only.
- If it must hold per-request values, resolve a fresh instance per request (Laravel:
scoped()).
Inspect this rule
Section titled “Inspect this rule”vendor/bin/worker-safety rules WS004Accepting a reviewed risk
Section titled “Accepting a reviewed risk”Use a targeted suppression or a baseline only after reviewing the value’s origin and lifetime. Changing an assignment elsewhere may not invalidate an existing property-level suppression.