Skip to content

Commit 6a8352b

Browse files
authored
chore: translate Japanese comments and docs to English (#102)
Translate all Japanese docblocks, inline comments, and CodeRabbit review instructions to English across src/, tests/, and .coderabbit.yaml. Also switch CodeRabbit review language from ja to en-US. The multibyte test fixture (str_repeat('あ', 200)) is kept as-is since it verifies UTF-8 truncation behavior. Claude-Session: https://claude.ai/code/session_014UL25HVV4YV6N7uZc9bZA1
1 parent 41da4e7 commit 6a8352b

10 files changed

Lines changed: 135 additions & 134 deletions

File tree

.coderabbit.yaml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
2-
language: ja
2+
language: en-US
33
early_access: false
44
tone_instructions: |
5-
日本語で簡潔かつ建設的にレビューしてください。
6-
指摘の根拠(PHPのバージョン依存、型安全性、Result型の不変条件など)を明示してください。
5+
Review concisely and constructively.
6+
Make the rationale for each comment explicit (PHP version dependencies, type safety, Result type invariants, etc.).
77
88
reviews:
99
profile: assertive
@@ -29,24 +29,24 @@ reviews:
2929
path_instructions:
3030
- path: "src/**/*.php"
3131
instructions: |
32-
- PHP 8.4 以上の構文・機能を前提にレビューする。
33-
- Rust の Result<T, E> に倣った API 設計を尊重し、Ok / Err / Result の不変条件を崩していないか確認する。
34-
- 例外による暗黙のエラー伝播ではなく、Result 型での明示的なエラーハンドリングを推奨する。
35-
- readonly / final / 型宣言(戻り値・引数・プロパティ)の徹底をチェックする。
36-
- 公開 API の破壊的変更がある場合は明示的に指摘する。
32+
- Review assuming PHP 8.4+ syntax and features.
33+
- Respect the API design modeled after Rust's Result<T, E>, and check that the Ok / Err / Result invariants are not broken.
34+
- Prefer explicit error handling via the Result type over implicit error propagation through exceptions.
35+
- Check for thorough use of readonly / final / type declarations (return, parameter, and property types).
36+
- Explicitly point out any breaking changes to the public API.
3737
- path: "tests/**/*.php"
3838
instructions: |
39-
- PHPUnit のテストとして、t-wadaTDDRed→Green→Refactor を意識しているかをチェックする。
40-
- 1 テスト 1 アサーション主義に偏りすぎず、振る舞い単位で検証されているか確認する。
41-
- エッジケース(Ok/Err 双方、ネスト、map/and_then などのコンビネータ)が網羅されているかを見る。
39+
- As PHPUnit tests, check whether they follow t-wada-style TDD's Red→Green→Refactor.
40+
- Without over-adhering to one-assertion-per-test dogma, check that they verify behavior units.
41+
- Check that edge cases are covered (both Ok/Err, nesting, combinators such as map/and_then).
4242
- path: "**/*.md"
4343
instructions: |
44-
- サンプルコードは PHP 8.4+ で実行可能か確認する。
45-
- README の API 説明と src の実装が一致しているかを確認する。
44+
- Check that sample code is runnable on PHP 8.4+.
45+
- Check that the README's API descriptions match the implementation in src.
4646
- path: ".github/workflows/**"
4747
instructions: |
48-
- 使用するアクションはバージョンを固定(SHA か明示的なタグ)しているかを確認する。
49-
- secrets の取り扱いに不適切なものがないかをチェックする。
48+
- Check that the actions used are version-pinned (by SHA or an explicit tag).
49+
- Check for any improper handling of secrets.
5050
5151
tools:
5252
phpstan:

src/Err.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Override;
88

99
/**
10-
* Err はエラー値を表します.
10+
* Err represents an error value.
1111
*
1212
* @template-covariant E
1313
*

src/Ok.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Override;
88

99
/**
10-
* Ok は成功値を表します.
10+
* Ok represents a success value.
1111
*
1212
* @template-covariant T
1313
*

src/Result.php

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55
namespace Valbeat\Result;
66

77
/**
8-
* Result型は、成功(Ok)または失敗(Err)を表現します。
8+
* The Result type represents either success (Ok) or failure (Err).
99
*
10-
* 注意: instanceof による絞り込みでは型引数が失われます(PHPStan の既知の制限。
11-
* Result<int, E> が型引数なしの Ok になり unwrap() は mixed になる)。
12-
* 値を取り出す分岐では isOk() / isErr() で絞り込んでください。
10+
* Note: narrowing via instanceof loses the type arguments (a known PHPStan
11+
* limitation; Result<int, E> becomes an Ok without type arguments and unwrap()
12+
* returns mixed). In branches that extract the value, narrow with isOk() / isErr().
1313
*
14-
* @template-covariant T 成功時の値の型
15-
* @template-covariant E 失敗時のエラーの型
14+
* @template-covariant T the type of the success value
15+
* @template-covariant E the type of the error value
1616
*
1717
* @phpstan-sealed Ok|Err
1818
*/
1919
interface Result
2020
{
2121
/**
22-
* 結果が成功(Ok)の場合に true を返します.
22+
* Returns true if the result is a success (Ok).
2323
*
2424
* @phpstan-assert-if-true Ok<T> $this
2525
* @phpstan-assert-if-false Err<E> $this
@@ -29,7 +29,7 @@ interface Result
2929
public function isOk(): bool;
3030

3131
/**
32-
* 結果が成功(Ok)でありコールバックが true を返す場合に true を返します.
32+
* Returns true if the result is a success (Ok) and the callback returns true.
3333
*
3434
* @param callable(T): bool $fn
3535
*
@@ -38,7 +38,7 @@ public function isOk(): bool;
3838
public function isOkAnd(callable $fn): bool;
3939

4040
/**
41-
* 結果が失敗(Err)の場合に true を返します.
41+
* Returns true if the result is a failure (Err).
4242
*
4343
* @phpstan-assert-if-true Err<E> $this
4444
* @phpstan-assert-if-false Ok<T> $this
@@ -48,7 +48,7 @@ public function isOkAnd(callable $fn): bool;
4848
public function isErr(): bool;
4949

5050
/**
51-
* 結果が失敗(Err)でありコールバックが true を返す場合に true を返します.
51+
* Returns true if the result is a failure (Err) and the callback returns true.
5252
*
5353
* @param callable(E): bool $fn
5454
*
@@ -57,47 +57,47 @@ public function isErr(): bool;
5757
public function isErrAnd(callable $fn): bool;
5858

5959
/**
60-
* 成功値を返します。失敗の場合は例外を投げます.
60+
* Returns the success value. Throws an exception on failure.
6161
*
6262
* @return ($this is Ok<mixed> ? T : never)
6363
*
64-
* @throws UnwrapException $this Err の場合
64+
* @throws UnwrapException if $this is Err
6565
*/
6666
public function unwrap(): mixed;
6767

6868
/**
69-
* エラー値を返します。成功の場合は例外を投げます.
69+
* Returns the error value. Throws an exception on success.
7070
*
7171
* @return ($this is Err<mixed> ? E : never)
7272
*
73-
* @throws UnwrapException $this Ok の場合
73+
* @throws UnwrapException if $this is Ok
7474
*/
7575
public function unwrapErr(): mixed;
7676

7777
/**
78-
* 成功値を返します。失敗の場合は指定したメッセージで例外を投げます.
78+
* Returns the success value. On failure, throws an exception with the given message.
7979
*
80-
* @param string $message 失敗時の例外メッセージ(エラー値の要約が付加されます)
80+
* @param string $message the exception message on failure (a summary of the error value is appended)
8181
*
8282
* @return ($this is Ok<mixed> ? T : never)
8383
*
84-
* @throws UnwrapException $this Err の場合
84+
* @throws UnwrapException if $this is Err
8585
*/
8686
public function expect(string $message): mixed;
8787

8888
/**
89-
* エラー値を返します。成功の場合は指定したメッセージで例外を投げます.
89+
* Returns the error value. On success, throws an exception with the given message.
9090
*
91-
* @param string $message 成功時の例外メッセージ(成功値の要約が付加されます)
91+
* @param string $message the exception message on success (a summary of the success value is appended)
9292
*
9393
* @return ($this is Err<mixed> ? E : never)
9494
*
95-
* @throws UnwrapException $this Ok の場合
95+
* @throws UnwrapException if $this is Ok
9696
*/
9797
public function expectErr(string $message): mixed;
9898

9999
/**
100-
* 成功値またはデフォルト値を返します.
100+
* Returns the success value or a default value.
101101
*
102102
* @template U
103103
* @param U $default
@@ -106,7 +106,7 @@ public function expectErr(string $message): mixed;
106106
public function unwrapOr(mixed $default): mixed;
107107

108108
/**
109-
* 成功値またはクロージャーの結果を返します.
109+
* Returns the success value or the result of the closure.
110110
*
111111
* @template U
112112
* @param callable(E): U $fn
@@ -116,7 +116,7 @@ public function unwrapOr(mixed $default): mixed;
116116
public function unwrapOrElse(callable $fn): mixed;
117117

118118
/**
119-
* 成功値に関数を適用します.
119+
* Applies a function to the success value.
120120
*
121121
* @template U
122122
*
@@ -127,7 +127,7 @@ public function unwrapOrElse(callable $fn): mixed;
127127
public function map(callable $fn): self;
128128

129129
/**
130-
* エラー値に関数を適用します.
130+
* Applies a function to the error value.
131131
*
132132
* @template F
133133
*
@@ -138,7 +138,7 @@ public function map(callable $fn): self;
138138
public function mapErr(callable $fn): self;
139139

140140
/**
141-
* 成功値に副作用を適用します.
141+
* Applies a side effect to the success value.
142142
*
143143
* @param callable(T): void $fn
144144
*
@@ -147,7 +147,7 @@ public function mapErr(callable $fn): self;
147147
public function inspect(callable $fn): self;
148148

149149
/**
150-
* エラー値に副作用を適用します.
150+
* Applies a side effect to the error value.
151151
*
152152
* @param callable(E): void $fn
153153
*
@@ -156,7 +156,7 @@ public function inspect(callable $fn): self;
156156
public function inspectErr(callable $fn): self;
157157

158158
/**
159-
* 成功値に関数を適用するか、デフォルト値を返します.
159+
* Applies a function to the success value, or returns a default value.
160160
*
161161
* @template U
162162
*
@@ -168,7 +168,7 @@ public function inspectErr(callable $fn): self;
168168
public function mapOr(mixed $default, callable $fn): mixed;
169169

170170
/**
171-
* 成功値に関数を適用するか、クロージャーの結果を返します.
171+
* Applies a function to the success value, or returns the result of the closure.
172172
*
173173
* @template U
174174
*
@@ -180,7 +180,7 @@ public function mapOr(mixed $default, callable $fn): mixed;
180180
public function mapOrElse(callable $defaultFn, callable $fn): mixed;
181181

182182
/**
183-
* 成功の場合は第2の結果を返し、失敗の場合は最初のエラーを返します.
183+
* Returns the second result on success, or the first error on failure.
184184
*
185185
* @template U
186186
* @template F
@@ -192,9 +192,9 @@ public function mapOrElse(callable $defaultFn, callable $fn): mixed;
192192
public function and(self $res): self;
193193

194194
/**
195-
* 成功の場合は関数を適用し、失敗の場合は現在のエラーを返します.
195+
* Applies a function on success, or returns the current error on failure.
196196
*
197-
* 関数は元と異なるエラー型を返せます。エラー型は E|F に合成されます.
197+
* The function may return a different error type; the error type is combined into E|F.
198198
*
199199
* @template U
200200
* @template F
@@ -206,7 +206,7 @@ public function and(self $res): self;
206206
public function andThen(callable $fn): self;
207207

208208
/**
209-
* 失敗の場合は第2の結果を返し、成功の場合は最初の値を返します.
209+
* Returns the second result on failure, or the first value on success.
210210
*
211211
* @template U
212212
* @template F
@@ -218,9 +218,9 @@ public function andThen(callable $fn): self;
218218
public function or(self $res): self;
219219

220220
/**
221-
* 失敗の場合は関数を適用し、成功の場合は現在の値を返します.
221+
* Applies a function on failure, or returns the current value on success.
222222
*
223-
* 関数は元と異なる成功型を返せます。成功型は T|U に合成されます.
223+
* The function may return a different success type; the success type is combined into T|U.
224224
*
225225
* @template U
226226
* @template F
@@ -232,15 +232,15 @@ public function or(self $res): self;
232232
public function orElse(callable $fn): self;
233233

234234
/**
235-
* 成功の場合はokを、失敗の場合はerrを適用します.
235+
* Applies ok on success, or err on failure.
236236
*
237237
* @template U
238238
* @template V
239239
*
240-
* @param callable(T): U $ok 成功値に適用する関数
241-
* @param callable(E): V $err エラー値に適用する関数
240+
* @param callable(T): U $ok the function applied to the success value
241+
* @param callable(E): V $err the function applied to the error value
242242
*
243-
* @return U|V 適用された関数の結果
243+
* @return U|V the result of the applied function
244244
*/
245245
public function match(callable $ok, callable $err): mixed;
246246
}

src/Results.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
namespace Valbeat\Result;
66

77
/**
8-
* Result を生成・合成する静的ヘルパーです.
8+
* Static helpers for creating and composing Results.
99
*/
1010
final class Results
1111
{
1212
/**
13-
* 静的ヘルパーのためインスタンス化を禁止します.
13+
* Prevents instantiation since this is a static helper.
1414
*
1515
* @codeCoverageIgnore
1616
*/
@@ -19,10 +19,10 @@ private function __construct()
1919
}
2020

2121
/**
22-
* 例外を投げうる処理を実行し、結果を Result に包みます.
22+
* Executes a callable that may throw and wraps the result in a Result.
2323
*
24-
* 成功時は戻り値を Ok に、\Throwable が送出された場合は Err に包んで返します.
25-
* 例外ベースの既存コードを Result の世界に持ち込む入口として使います.
24+
* On success the return value is wrapped in Ok; if a \Throwable is thrown it is wrapped in Err.
25+
* Use it as an entry point for bringing existing exception-based code into the Result world.
2626
*
2727
* @template T
2828
*
@@ -40,9 +40,9 @@ public static function try(callable $fn): Result
4040
}
4141

4242
/**
43-
* 複数の Result を 1 つに合成します.
43+
* Combines multiple Results into one.
4444
*
45-
* すべて成功なら値のリストを Ok で返し、失敗が含まれる場合は最初の Err を返します.
45+
* If all are successes, returns the list of values as an Ok; if any failure is present, returns the first Err.
4646
*
4747
* @template T
4848
* @template E
@@ -65,11 +65,11 @@ public static function combine(iterable $results): Result
6565
}
6666

6767
/**
68-
* ネストした Result を 1 段平坦化します.
68+
* Flattens a nested Result by one level.
6969
*
70-
* インスタンスメソッドにしないのは、PHPStan の条件型ではテンプレート T を
71-
* Result<U, F> に分解できない(infer がない)ため。静的ヘルパーなら
72-
* パラメータ側のテンプレートで内側の型を正確に推論できます.
70+
* This is not an instance method because PHPStan's conditional types cannot
71+
* decompose the template T into Result<U, F> (there is no infer). As a static
72+
* helper, the inner type can be inferred precisely from the parameter-side template.
7373
*
7474
* @template T
7575
* @template E1

0 commit comments

Comments
 (0)