Convert the adapter types and the remaining Enums classes to PHP enums (PHP 8.2)

Ouverte
#620 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
5/5
Temps estimé
Plus d'une semaine
Accessibilité débutants
35/100
Type d'issue
Refactorisation
Clarté
Clairement spécifiée
Activité
Active
Stack technique
php
Domaine
backend

Piste de recherche

Start by reading the listed adapter type classes and the factories, Database, PaginatorFactory, and Status trait named in the issue. Then trace the listed property and parameter defaults, config and .env inputs, starter project, module templates, and documentation examples that use these classes. Check every conversion against the PHP 8.2 enum value behavior described in the issue; done means all listed classes are converted or have a recorded reason to remain constants, the examples and templates work, the changelog and upgrade guide are updated, and the stated CI checks pass.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

breaking change refactoring tech debt

Summary

Convert the remaining classes in the Enums folders to PHP enums in 3.2.0, once PHP 8.2 is the minimum: the adapter types, StatusCode, ContentType, Env and ExitCode. The first batch, the classes that can convert on PHP 8.1, is #612.

Why 3.2.0

These classes appear in class constants, property defaults or parameter defaults, mostly as the keys of maps, and PHP 8.1 does not allow Case->value in a constant expression. PHP 8.2 does (the RFC "Fetch properties of enums in const expressions"). I checked it on PHP 8.2.35 and 8.1.34:

  • public const ADAPTERS = [LoggerType::SINGLE->value => SingleAdapter::class, ...] loads and works on 8.2.
  • The same code fails on 8.1 with Fatal error: Constant expression contains invalid operations, and so does the real LoggerFactory.php with its keys written that way.

With 8.2 the maps keep their shape. In each place only ->value is added to the keys.

Classes in this ticket

  • Adapter types (15): AppType, ArchiveType, AuthType, CacheType, CaptchaType, CryptorType, DatabaseType, FileSystemType, LangType, LoggerType, MailerType, PaginatorType, RateLimitType, RendererType, SessionType.
  • Others: ContentType, Env, ExitCode, StatusCode (62 integer cases).

Places that need ->value

  • the 15 ADAPTERS constants in the factories and Database
  • PaginatorFactory::REQUIRED_PARAMS
  • the Status trait's $texts map, with the status codes as keys
  • the property and parameter defaults that hold these classes

What to watch

  • An enum case is not its value: StatusCode::OK === 200 is false, and an int parameter rejects a case. Comparisons, array keys and parameters that use the value need ->value, and text from config or .env needs ::from() or ::tryFrom().
  • Apps and templates use these constants, for example AppFactory::create(AppType::WEB, ...) in the starter project and PaginatorType in the Toolkit templates. Signatures typed string $type change.

Out of scope

  • ExceptionMessages, whose classes extend a shared base class.
  • The classes in #612.

Breaking changes

  • Public constants become enum cases, and the type of some public parameters and return values changes. To be listed in the changelog and in the upgrade guide.

Acceptance criteria

  • every class above is converted or has a recorded reason to stay a constants class
  • the starter project and the module templates still work, and the docs examples use the new form
  • composer test, composer cs:check, composer phpstan and composer rector:check pass on every PHP version in the CI matrix
  • the changelog lists every converted class
Langage dominant
PHP
Étoiles
43
Forks
22
Merge moyen
54 min
PR mergées (30 j)
57

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de quantum-php/framework

Toutes les issues de quantum-php/framework

Issues similaires

Plus d'issues PHP

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.