Raise PHPStan to level 9

Offen
#693 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Anfängerfreundlichkeit
20/100
Issue-Typ
Refactoring
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
php

Rechercherichtung

Run composer phpstan to reproduce the level 8 baseline, then temporarily set level: 9 in phpstan.neon.dist to see the 581 errors grouped per file. Start with the Di facade (Quantum\Di\Di): give its @method tags generic class-string<T>-in / T-out signatures, which clears the 49 errors from DiContainer::get() and create(). After that the work splits by package (Mailer, Database, Console, Storage, Lang, Http, Auth) into array shapes, typed accessors such as Config::getString()/getArray() next to getBool()/getInt(), and checks where mixed values enter. Done means the analysis is clean at level 9 with no baseline, tests green, and only then the level bumped in phpstan.neon.dist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

refactoring tech debt

Summary

Raise the static analysis of src/ from PHPStan level 8 to level 9, which treats mixed strictly: a value of type mixed can no longer be used as a string, array or object without being checked or typed first.

Current state

composer phpstan passes at level 8. At level 9 it reports 581 errors in 151 files (PHPStan 2.3.7). They come from four sources:

  1. The Di facade returns mixed. DiContainer::get() and create() are generic (class-string<T> in, T out), but the @method tags of the static facade Quantum\Di\Di declare mixed, so every call on a service fetched through Di::get() is a call on mixed. Generic @method tags fix 49 errors.
  2. Arrays without a shape. Config arrays ($this->config['session']['remember_lifetime']), mail addresses ($address['email']), table column definitions and console argument lists are typed as plain array, so every read returns mixed. They need array shapes (array{email: string, name: string}) or a value object.
  3. Values that are mixed by nature: config()->get(), $_SERVER, Symfony's InputInterface::getOption() and getArgument(), json_decode() and remote API responses. They need a check where they enter the code, or typed accessors such as Config::getString() and Config::getArray() next to the existing getBool() and getInt().
  4. Single cases: casts and returns of mixed values.

Most errors are in Mailer (81), Database (79), Console (56), Storage (48), Lang (41), Http (37) and Auth (34).

Approach

  1. Generic @method tags on the Di facade.
  2. Typed config accessors, if the review agrees.
  3. One checkpoint per package (or a few small packages together): array shapes, checks at the entry of mixed values, no behaviour change.
  4. Raise level in phpstan.neon.dist to 9 in the last checkpoint, when the analysis is clean; CI stays on level 8 until then. No baseline file and no @phpstan-ignore for real type gaps.

Every checkpoint keeps the tests green and adds tests where a check changes behaviour (for example a config value of the wrong type).

Out of scope

  • Level 10 (implicit mixed from missing types).
  • The tests in tests/, which PHPStan does not analyse.
Vorherrschende Sprache
PHP
Sterne
43
Forks
22
Ø Merge
54 Min.
Gemergte PRs (30 T.)
57

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus quantum-php/framework

Alle Issues in quantum-php/framework

Ähnliche Issues

Weitere Issues zu PHP

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.