[RFC]: Read string specifications through a typed accessor in AbstractSql
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
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
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
protectedmethod onAbstractSql. 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
TypeErrorto 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
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de php-db/phpdb
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
Les mainteneurs répondent en général sous 1 jour
-
RFC
Difficulté 3/5 1-2 jours Accessibilité débutants 66/100
Les mainteneurs répondent en général sous 1 jour
-
RFC
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 38/100
Les mainteneurs répondent en général sous 1 jour
-
RFC
Difficulté 3/5 1-2 jours Accessibilité débutants 68/100
Les mainteneurs répondent en général sous 1 jour
-
Sql's foreign-table guard raises TypeError when its table is a TableIdentifier or aliased arrayPeut-être pris @simon-mundy l’a pris il y a 3 jours. Ouvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 50/100
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de php-db/phpdb
Issues similaires
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 90/100
crazy-goat/rabbit-stream#753 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
opensourcepos/opensourcepos#4743 ·
Les mainteneurs répondent en général sous 2 jours
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 82/100
grokability/snipe-it#19786 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
Les mainteneurs répondent en général sous 3 jours
-
Difficulté 2/5 1-3 heures Accessibilité débutants 69/100
PrestaShop/PrestaShop#43140 ·
Les mainteneurs répondent en général sous 1 jour