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

Predicate fluent methods accept identifier types their predicates reject

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

維護者通常 1 天內回覆

@simon-mundy 已經在處理了。

開始於 2026年10月5日。

  • #224 來自 @simon-mundy —— 未關閉

評估

難度
3/5
預估耗時
1-2 天
新手友好度
30/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
停滯
技術堆疊
php, sql
領域
databases

研究方向

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

描述

bug
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
  1. (new Where())->isNull(5)
  2. (new Where())->equalTo(1, 2)
  3. (new Where())->between(['a'], 1, 2)
  4. (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 小時
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 摘要。