refactor!: rename callback parameters for named-argument use#91
Conversation
Parameter names are part of the public API since PHP 8.0 named arguments. Pin the intended names (ok/err, defaultFn/fn) with tests. Currently RED: the implementation uses $ok_fn/$err_fn/$default_fn. Claude-Session: https://claude.ai/code/session_017XTM7pxbWPVNLV639i5WgK
Rename match($ok_fn, $err_fn) to match($ok, $err) and mapOrElse($default_fn, ...) to mapOrElse($defaultFn, ...). Parameter names are public API via PHP named arguments, and the previous names were inconsistent with the README, which documented ok:/err: in Basic Usage and $okFn/$errFn/$defaultFn in the API reference. The README Basic Usage example now works as written. BREAKING CHANGE: callers passing these arguments by name must update the argument names. Claude-Session: https://claude.ai/code/session_017XTM7pxbWPVNLV639i5WgK
|
Warning Review limit reached
Next review available in: 58 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (6)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #91 +/- ##
===========================================
Coverage 100.00% 100.00%
Complexity 40 40
===========================================
Files 2 2
Lines 80 80
===========================================
Hits 80 80
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
There was a problem hiding this comment.
Code Review
This pull request renames the parameter names of mapOrElse (from $default_fn to $defaultFn) and match (from $ok_fn and $err_fn to $ok and $err) in the Result, Ok, and Err classes to support PHP named arguments. It also updates the README documentation and adds corresponding unit tests to verify named argument support. I have no feedback to provide as the changes are clean and well-tested.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
…name PR Review feedback: rewriting the example to positional args and then back once #91 renames the parameters to ok/err is patch-then-revert churn on the same lines. Keep the named-argument form here and merge this PR after #91, which makes it valid. Claude-Session: https://claude.ai/code/session_017XTM7pxbWPVNLV639i5WgK
There was a problem hiding this comment.
Pull request overview
This PR standardizes public callback parameter names to support PHP named arguments consistently across the library (PHP 8.0+ makes parameter names part of the public API when named arguments are used).
Changes:
- Renamed
match()callback parameters from$ok_fn/$err_fnto$ok/$errinResult,Ok, andErr. - Renamed
mapOrElse()default callback parameter from$default_fnto$defaultFninResult,Ok, andErr. - Updated README API Reference and added PHPUnit coverage to pin named-argument usage for
match()andmapOrElse()on bothOkandErr.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/OkTest.php | Adds tests asserting Ok::match(ok: ..., err: ...) and Ok::mapOrElse(defaultFn: ..., fn: ...) work with named arguments. |
| tests/ErrTest.php | Adds tests asserting Err::match(ok: ..., err: ...) and Err::mapOrElse(defaultFn: ..., fn: ...) work with named arguments. |
| src/Result.php | Updates the public interface parameter names to match the intended named-argument API (ok/err, defaultFn). |
| src/Ok.php | Updates implementation parameter names and internal usage to align with the interface and named-argument API. |
| src/Err.php | Updates implementation parameter names and internal usage to align with the interface and named-argument API. |
| README.md | Updates the API Reference match() signature to reflect the new parameter names. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
概要
コードレビューで指摘したパラメータ命名の不整合(3 通りの揺れ)を解消します。
$ok_fn/$err_fn/$default_fn(snake_case)ok:/err:(実行するとフェイタルエラー)$okFn/$errFn/$defaultFn(camelCase)PHP 8.0 以降、パラメータ名は名前付き引数経由で公開 API の一部です。Rust の match アームに合わせて
match(callable $ok, callable $err)、その他は PHP 標準の camelCase($defaultFn)に統一しました。変更内容
match($ok_fn, $err_fn)→match($ok, $err)(Result / Ok / Err)mapOrElse($default_fn, $fn)→mapOrElse($defaultFn, $fn)(同上)match()シグネチャを実装に一致させるmatch(ok: ..., err: ...)の例はこの変更でそのまま動くようになりますBC への影響
名前付き引数でこれらを渡している呼び出し元は引数名の更新が必要です(BREAKING CHANGE として明記)。位置引数の呼び出しには影響ありません。
TDD
Unknown named parameter $ok)を確認してコミット関連
https://claude.ai/code/session_017XTM7pxbWPVNLV639i5WgK