Raise PHPStan to level 9

Aperta
#693 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
20/100
Tipo di issue
Refactoring
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
php

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.
Lingua principale
PHP
Stelle
43
Fork
22
Merge medio
54m
PR unite (30g)
57

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di quantum-php/framework

Tutte le issue di quantum-php/framework

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.