[RFC]: Read string specifications through a typed accessor in AbstractSql
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
先阅读 src/Sql/AbstractSql.php,了解 $specifications 是如何声明和使用的,然后在 Delete、Insert、Update、Combine 和 CreateTable 中定位每一处 str_replace(..., $this->specifications[static::SPECIFICATION_*]) 调用点。从 issue 中提出的 getStringSpecification() 辅助方法以及 Sql\Exception\RuntimeException 中对应的命名构造函数和消息常量开始。完成的标准是每次读取字符串 specification 都通过 accessor 进行,且 mago analyze --ignore-baseline src/Sql 不再报告列出的 findings,同时现有测试套件(包括 *Ignore 测试资源)仍然通过。
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- PHP
- 星标
- 18
- 派生
- 8
- 平均合并
- 6 天 11 小时
- 30 天内合并 PR
- 14
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
php-db/phpdb 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
RFC
难度 3/5 1-2 天 新手友好度 66/100
维护者通常 1 天内回复
-
RFC
难度 5/5 一周以上 新手友好度 38/100
维护者通常 1 天内回复
-
RFC
难度 3/5 1-2 天 新手友好度 68/100
维护者通常 1 天内回复
-
Sql's foreign-table guard raises TypeError when its table is a TableIdentifier or aliased array可能已有人在做 @simon-mundy 于 4 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 50/100
维护者通常 1 天内回复
相似的 Issue
-
spec:debating
难度 2/5 1-3 小时 新手友好度 72/100
blackie0424/tao_among#93 ·
维护者通常 1 天内回复
-
📚 Documentation: Placeholder link `link-to-realtime-docs` in Flutter SDK changelog可能已有人在做 @ShyneChikwapulo 今天认领。 未关闭api / realtime product / auth product / messaging product / vcs
难度 1/5 1 小时以内 新手友好度 82/100
appwrite/appwrite#14272 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
-
难度 1/5 1 小时以内 新手友好度 75/100
Boavizta/boaviztapi#580 · 1 条评论 ·
-
Add Prestashop未关闭request
难度 2/5 1-3 小时 新手友好度 72/100
endoflife-date/endoflife.date#11303 ·
维护者通常 1 天内回复