Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

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

未關閉
#211 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
45/100
Issue 類型
功能
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
php
領域
databases

研究方向

先閱讀 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 內容生成。

描述

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.

主要語言
PHP
星號
18
分支
8
平均合併
6 天 11 小時
30 天內合併 PR
14

環境準備

  • 提供 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 沒有貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

php-db/phpdb 的其他 Issue

查看 php-db/phpdb 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。