Use @template generics on resource-typed interface members instead of the generic resource type
維護者通常 2 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
Locate DriverInterface, StatementInterface, and the concrete platform implementations; start by reading their existing resource docblocks and the related mago analyzer fixes. Apply the proposed generic contract consistently, then verify that concrete mysqli types no longer require downstream suppressions and that the static analyzers accept the implementations.
由索引模型根據 Issue 內容生成。
描述
Context
Found while working phpdb-mysql#60 (mago analyze fixes).
Problem
DriverInterface::createResult($resource), DriverInterface::createStatement($sqlOrResource), and StatementInterface::getResource() are documented with a generic resource docblock type, intended to stay valid across every supported RDBMS platform. Concrete per-platform implementations (e.g. phpdb-mysql) pass/return real objects (mysqli, mysqli_result, mysqli_stmt), not resource handles, since mysqli has been object-oriented since its introduction in PHP 5.0 and was never part of PHP's resource-to-object migration. Static analyzers (mago, phpstan, psalm) flag every concrete usage as a type mismatch against the generic resource docblock, requiring local suppressions in every downstream platform package.
Proposed direction
Use PHP docblock generics (@template) on the interfaces instead of a fixed resource type, so the interface stays a single, platform-agnostic contract, and each concrete implementation narrows the generic to its own real type via @implements:
/** @template TResource */
interface DriverInterface
{
/** @param TResource $resource */
public function createResult($resource): ResultInterface;
}
/** @implements DriverInterface<mysqli|mysqli_result|mysqli_stmt> */
final class Driver implements DriverInterface { /* ... */ }
This avoids introducing per-RDBMS interfaces (a platform still free to use literal resource handles, e.g. a hypothetical oci8 implementation, can declare DriverInterface<resource>), while letting static analyzers correctly understand each concrete implementation's real type without suppressions. Same pattern applies to StatementInterface::getResource() and DriverInterface::createStatement()'s $sqlOrResource parameter.
- 主要語言
- PHP
- 星號
- 18
- 分支
- 8
- 平均合併
- 2 天 14 小時
- 30 天內合併 PR
- 26
環境準備
- 提供 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 沒有貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
php-db/phpdb 的其他 Issue
-
bug
難度 2/5 1-3 小時 新手友好度 82/100
維護者通常 2 天內回覆
-
RFC
難度 3/5 1-2 天 新手友好度 66/100
維護者通常 2 天內回覆
-
RFC
難度 5/5 一週以上 新手友好度 38/100
維護者通常 2 天內回覆
-
RFC
難度 3/5 1-2 天 新手友好度 68/100
維護者通常 2 天內回覆
-
RFC
難度 4/5 3-5 天 新手友好度 45/100
維護者通常 2 天內回覆
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 66/100
Automattic/blocks-engine#2866 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 62/100
community-scripts/ProxmoxVE#17944 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 62/100
EasyCorp/EasyAdminBundle#7861 · 2 則留言 ·
維護者通常 1 天內回覆
-
enhancement good first issue help wanted
難度 2/5 1-3 小時 新手友好度 82/100
-
backend gamification P0
難度 2/5 1-3 小時 新手友好度 66/100
semanadeinformatica/website#461 ·