Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン
#211 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
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 内の対応する名前付きコンストラクタおよびメッセージ定数を出発点とする。完了の条件は、文字列仕様の読み取りがすべて 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時間
マージ済み PR(30日)
14

環境構築

  • Dockerfile または Docker Compose ファイルあり
  • プルリクエストのテンプレートなし
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

php-db/phpdb のほかの issue

php-db/phpdb の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。