[RFC]: Read string specifications through a typed accessor in AbstractSql
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
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
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.
- 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
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de php-db/phpdb
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
RFC
Dificultad 3/5 1-2 días Aptitud para principiantes 66/100
Los mantenedores suelen responder en 1 día
-
RFC
Dificultad 5/5 Más de una semana Aptitud para principiantes 38/100
Los mantenedores suelen responder en 1 día
-
RFC
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
Sql's foreign-table guard raises TypeError when its table is a TableIdentifier or aliased arrayPosiblemente ocupada @simon-mundy la tomó hace 2 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 50/100
Los mantenedores suelen responder en 1 día
Todos los issues de php-db/phpdb
Issues similares
-
Dificultad 2/5 Menos de una hora Aptitud para principiantes 78/100
opencart/opencart#15763 · 2 comentarios · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
L: github:actions L: php:composer
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
dependabot/dependabot-core#16493 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
api-platform/core#8649 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 1/5 Menos de una hora Aptitud para principiantes 84/100
open-telemetry/opentelemetry-php#2071 ·
Los mantenedores suelen responder en 1 día
-
Always show measure tooltipsAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día