[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 於 2 天前認領。 未關閉bug
難度 2/5 1-3 小時 新手友好度 50/100
維護者通常 1 天內回覆
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 88/100
維護者通常 1 天內回覆
-
🧠 Admin
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 90/100
pluginsGLPI/tag#389 ·
維護者通常 1 天內回覆
-
難度 2/5 1 小時以內 新手友好度 78/100
opencart/opencart#15763 · 2 則留言 · 1 個 reaction ·
維護者通常 1 天內回覆
-
support
難度 2/5 1-3 小時 新手友好度 74/100
維護者通常 1 天內回覆