Predicate fluent methods accept identifier types their predicates reject
メンテナーはふだん 1 日以内に返信
評価
調査の方向性
Start with the fluent methods in src/Sql/Predicate/Predicate.php and the corresponding constructors in Between.php, Operator.php, In.php, IsNull.php, and Like.php; compare their identifier parameter types. Read docs/book/sql/where-having.md and inspect the predicate tests to find where method signatures are covered. Done means the fluent signatures and API documentation match the constructors, with a test preventing future drift; linked pull request #224 is already open.
索引モデルが issue の本文から書いたものです。
説明
Package Version
0.6.x-dev @ e022af5c
Php Version
8.3, 8.4, 8.5
Database Engine
Any
Basic Information
The fluent methods on Predicate\Predicate (and so on Where and Having) accept wider identifier types than the predicate classes they build. Each method passes its identifier straight to a constructor that rejects the extra types:
| Method | Identifier accepted | Constructor accepts |
|---|---|---|
between(), notBetween() (Predicate.php#L33) |
float|int|string|array|ArgumentInterface|null, plus array for min/max |
Between: string|ArgumentInterface|null (Between.php#L27) |
equalTo() and the other comparisons (Predicate.php#L50) |
float|int|string|ArgumentInterface|null |
Operator left: string|ArgumentInterface|ExpressionInterface|SqlInterface|null (Operator.php#L50) |
in(), notIn() (Predicate.php#L128) |
float|int|string|ArgumentInterface |
In: string|ArgumentInterface|null (In.php#L25) |
isNull(), isNotNull() (Predicate.php#L160) |
float|int|string|ArgumentInterface |
IsNull: string|ArgumentInterface|null (IsNull.php#L22) |
like(), notLike() (Predicate.php#L210) |
float|int|string|ArgumentInterface|null |
Like: string|ArgumentInterface|null (Like.php#L23) |
The leaf constructors were narrowed in #87 (review: "It could simply be string|Argument $identifier = null"); the fluent methods kept the wider types. docs/book/sql/where-having.md documents the wider signatures. It also states that $leftType/$rightType were removed and that a value on the left should be passed as an Argument instance.
Steps to Reproduce
(new Where())->isNull(5)(new Where())->equalTo(1, 2)(new Where())->between(['a'], 1, 2)(new Where())->in(5, [1])
Expected Behavior
Each fluent method accepts exactly what its predicate accepts, so an invalid call fails at the method the caller wrote. A numeric value on the left is passed as new Argument\Value(5), as the docs describe. The API listing in where-having.md should match.
Narrowing does not break working code, because every call it rejects already throws. A test comparing each method's parameter types with its predicate's constructor would stop them drifting apart again.
Actual behavior?
TypeError: PhpDb\Sql\Predicate\IsNull::__construct(): Argument #1 ($identifier) must be of type PhpDb\Sql\ArgumentInterface|string|null, int given
TypeError: PhpDb\Sql\Predicate\Operator::__construct(): Argument #1 ($left) must be of type PhpDb\Sql\ArgumentInterface|PhpDb\Sql\ExpressionInterface|PhpDb\Sql\SqlInterface|string|null, int given
TypeError: PhpDb\Sql\Predicate\Between::__construct(): Argument #1 ($identifier) must be of type PhpDb\Sql\ArgumentInterface|string|null, array given
TypeError: PhpDb\Sql\Predicate\In::__construct(): Argument #1 ($identifier) must be of type PhpDb\Sql\ArgumentInterface|string|null, int given
Additional Info
The unmerged 0.5.x-benchmarking branch restores $leftType/$rightType as a deprecated compatibility layer (75987ac2). If that is ever ported, the left parameter would need to accept a numeric value again, alongside a type.
- 主要言語
- 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 日以内に返信
-
RFC
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
Bug Enhancement Performance
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
Feature Status: Needs Triage
難易度 2/5 1〜3時間 初心者へのやさしさ 73/100
メンテナーはふだん 1 日以内に返信
-
frontend low-priority
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
mplodowski/dynamicpdf-plugin#336 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
AdvancedCustomFields/acf#1044 ·
-
Add Zammad対応中かも @Arslan-TR が今日担当しました。 オープンrequest
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
endoflife-date/endoflife.date#11298 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信