[RFC]: Read string specifications through a typed accessor in AbstractSql
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
まず 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 の本文から書いたものです。
説明
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時間
- マージ済み PR(30日)
- 14
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートなし
- コントリビューションガイドなし
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
php-db/phpdb のほかの issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
RFC
難易度 3/5 1〜2日 初心者へのやさしさ 66/100
メンテナーはふだん 1 日以内に返信
-
RFC
難易度 5/5 1週間以上 初心者へのやさしさ 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 が 3 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 50/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
crazy-goat/rabbit-stream#753 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
opensourcepos/opensourcepos#4743 ·
メンテナーはふだん 2 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
grokability/snipe-it#19786 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 3 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 69/100
PrestaShop/PrestaShop#43140 ·
メンテナーはふだん 1 日以内に返信