Skip to content

refactor!: rename callback parameters for named-argument use#91

Merged
valbeat merged 2 commits into
mainfrom
refactor/named-argument-params
Jul 7, 2026
Merged

refactor!: rename callback parameters for named-argument use#91
valbeat merged 2 commits into
mainfrom
refactor/named-argument-params

Conversation

@valbeat

@valbeat valbeat commented Jul 7, 2026

Copy link
Copy Markdown
Owner

概要

コードレビューで指摘したパラメータ命名の不整合(3 通りの揺れ)を解消します。

  • 実装: $ok_fn / $err_fn / $default_fn(snake_case)
  • README Basic Usage: ok: / err:(実行するとフェイタルエラー)
  • README API Reference: $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)(同上)
  • README API Reference の match() シグネチャを実装に一致させる
  • README Basic Usage の match(ok: ..., err: ...) の例はこの変更でそのまま動くようになります

BC への影響

名前付き引数でこれらを渡している呼び出し元は引数名の更新が必要です(BREAKING CHANGE として明記)。位置引数の呼び出しには影響ありません。

TDD

  1. 名前付き引数の使用をピン留めするテスト 4 件を先に追加し、RED(Unknown named parameter $ok)を確認してコミット
  2. 改名を実装して GREEN(73 tests / PHPStan max / cs-fixer すべてパス)

関連

https://claude.ai/code/session_017XTM7pxbWPVNLV639i5WgK

valbeat added 2 commits July 7, 2026 13:00
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
@valbeat valbeat self-assigned this Jul 7, 2026
@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@valbeat, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 58 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: e761a4c7-249b-4cc8-8f9c-e87e7da0656f

📥 Commits

Reviewing files that changed from the base of the PR and between 98a2fcb and aef6a6e.

📒 Files selected for processing (6)
  • README.md
  • src/Err.php
  • src/Ok.php
  • src/Result.php
  • tests/ErrTest.php
  • tests/OkTest.php
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/named-argument-params

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (98a2fcb) to head (aef6a6e).
✅ All tests successful. No failed tests found.

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           
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@valbeat valbeat marked this pull request as ready for review July 7, 2026 04:35
Copilot AI review requested due to automatic review settings July 7, 2026 04:35
valbeat added a commit that referenced this pull request Jul 7, 2026
…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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_fn to $ok/$err in Result, Ok, and Err.
  • Renamed mapOrElse() default callback parameter from $default_fn to $defaultFn in Result, Ok, and Err.
  • Updated README API Reference and added PHPUnit coverage to pin named-argument usage for match() and mapOrElse() on both Ok and Err.

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.

@valbeat valbeat merged commit 03a3a75 into main Jul 7, 2026
10 checks passed
@valbeat valbeat deleted the refactor/named-argument-params branch July 7, 2026 06:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants