[RFC]: Read string specifications through a typed accessor in AbstractSql
Maintainer antworten meist innerhalb von 2 Tagen
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 45/100
Rechercherichtung
Lies zuerst src/Sql/AbstractSql.php, um zu sehen, wie $specifications deklariert und verwendet wird, und lokalisiere dann jeden str_replace(..., $this->specifications[static::SPECIFICATION_*]) Aufrufort in Delete, Insert, Update, Combine und CreateTable. Beginne mit dem vorgeschlagenen Helper getStringSpecification() im Issue sowie dem passenden benannten Konstruktor und der Nachrichtenkonstante in Sql\Exception\RuntimeException. Fertig bedeutet, dass jeder Zugriff auf eine String-Spezifikation über den accessor erfolgt und mago analyze --ignore-baseline src/Sql die aufgeführten findings nicht mehr meldet, wobei die bestehende Testsuite (einschließlich der *Ignore-Testassets) weiterhin besteht.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- PHP
- Sterne
- 18
- Forks
- 8
- Ø Merge
- 2 T. 14 Std.
- Gemergte PRs (30 T.)
- 26
Entwicklungsumgebung
- Enthält ein Dockerfile oder eine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Kein Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus php-db/phpdb
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
Maintainer antworten meist innerhalb von 2 Tagen
-
RFC
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 66/100
Maintainer antworten meist innerhalb von 2 Tagen
-
RFC
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 38/100
Maintainer antworten meist innerhalb von 2 Tagen
-
RFC
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 68/100
Maintainer antworten meist innerhalb von 2 Tagen
-
VALID_FETCH_MODES lists three entries that are not usable fetch modesEvtl. vergeben @simon-mundy hat das vor 13 Tagen übernommen. Offenbug confirmed
php-db/phpdb#199 · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 2 Tagen
Ähnliche Issues
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 78/100
backdrop-contrib/commerce#60 ·
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 76/100
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 84/100
TYPO3-Documentation/TYPO3CMS-Reference-CoreApi#7330 ·
Maintainer antworten meist innerhalb von 1 Tag
-
dependencies
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 67/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100