Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto
#211 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
45/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
php
Área
databases

Línea de trabajo

Lee primero src/Sql/AbstractSql.php para ver cómo se declara y se consume $specifications, y luego localiza cada punto de llamada de str_replace(..., $this->specifications[static::SPECIFICATION_*]) en Delete, Insert, Update, Combine y CreateTable. Empieza por el helper getStringSpecification() propuesto en el issue y por el constructor con nombre correspondiente más la constante de mensaje en Sql\Exception\RuntimeException. Se considera terminado cuando toda lectura de una especificación de cadena pasa por el accessor y mago analyze --ignore-baseline src/Sql ya no reporta los findings listados, con la suite de pruebas existente (incluidos los *Ignore test assets) sigue pasando.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
PHP
Estrellas
18
Forks
8
Merge medio
6 d 11 h
PR fusionados (30 d)
14

Preparar el entorno

  • Incluye un Dockerfile o un archivo de Docker Compose
  • Sin plantilla de pull request
  • Sin guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de php-db/phpdb

Todos los issues de php-db/phpdb

Issues similares

Más issues de PHP

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.