Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

[RFC]: Read string specifications through a typed accessor in AbstractSql

Ouverte
#211 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é
4/5
Temps estimé
3-5 jours
Accessibilité débutants
45/100
Type d'issue
Fonctionnalité
Clarté
Plutôt claire
Activité
Active
Stack technique
php
Domaine
databases

Piste de recherche

Lis d'abord src/Sql/AbstractSql.php pour voir comment $specifications est déclaré et consommé, puis repère chaque site d'appel str_replace(..., $this->specifications[static::SPECIFICATION_*]) dans Delete, Insert, Update, Combine et CreateTable. Partez du helper getStringSpecification() proposé dans l'issue ainsi que du constructeur nommé correspondant et de la constante de message dans Sql\Exception\RuntimeException. Pour être terminé, toute lecture d'une spécification de chaîne passe par l'accessor et mago analyze --ignore-baseline src/Sql ne signale plus les findings listés, la suite de tests existante (y compris les *Ignore test assets) continuant de passer.

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

Description

RFC
Proposed Version

Next minor

Basic Information

Delete, Insert, Update, Combine and CreateTable render clauses with str_replace() on a specification read straight from $this->specifications[static::SPECIFICATION_*]. $specifications holds both string templates and nested parameter specifications, so the analyzer cannot tell that a given entry is a string. It also cannot tell that the key exists, since subclasses can replace the whole array. This accounts for 26 analyzer findings in src/Sql: possibly-undefined-string-array-index, possibly-null-argument, possibly-invalid-argument and one invalid-return-statement.

Background

At runtime, a missing or non-string specification produces an "Undefined array key" warning followed by a TypeError from str_replace(), or renders an array where a string is expected. Neither error names the specification. Subclasses (the *Ignore test assets, and driver decorators) replace individual entries, so this can happen outside the library.

Considerations
  • A new protected method on AbstractSql. A subclass that already declares a method with the same name would conflict; none of the driver packages do.
  • The failure changes from a warning plus TypeError to a named exception. That only affects specifications that are already broken.
Proposal(s)
/**
 * @throws Exception\RuntimeException
 */
protected function getStringSpecification(string $name): string
{
    $specification = $this->specifications[$name] ?? null;
    if (! is_string($specification)) {
        throw Exception\RuntimeException::forInvalidSpecification($name);
    }

    return $specification;
}

Each str_replace(..., $this->specifications[static::SPECIFICATION_X]) becomes str_replace(..., $this->getStringSpecification(static::SPECIFICATION_X)). A matching named constructor and message constant are added to Sql\Exception\RuntimeException.

Appendix/Additional Info

Finding counts are from mago analyze --ignore-baseline src/Sql once the docblock typing in #204 is applied.

Langage dominant
PHP
Étoiles
18
Forks
8
Merge moyen
6 j 11 h
PR mergées (30 j)
14

Préparer son environnement

  • Fournit un Dockerfile ou un fichier Docker Compose
  • Aucun modèle de pull request
  • Aucun guide de contribution

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 php-db/phpdb

Toutes les issues de php-db/phpdb

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.