Skip to content

refactor(types): tighten $REQUEST_JSON + ApiResponse return shapes (#405)#413

Merged
hideyukiMORI merged 1 commit into
mainfrom
refactor/405-type-tightening
May 22, 2026
Merged

refactor(types): tighten $REQUEST_JSON + ApiResponse return shapes (#405)#413
hideyukiMORI merged 1 commit into
mainfrom
refactor/405-type-tightening

Conversation

@hideyukiMORI
Copy link
Copy Markdown
Owner

評価レポート #401 § 2 Code Quality の 2 件を解消。

$REQUEST_JSON

`ControllerBase::$REQUEST_JSON` の PHPDoc を `array<string,mixed>` に parameterize (native type は `array` のまま)。`JsonResponder::inputJsonToArray` の戻り PHPDoc と整合。

ApiResponse return shape

  • `success()`: `@return array<string,mixed>` 維持 + array_merge 振る舞いと caller keys win の説明を追記
  • `failure()`: `@return array{status: 'failure', errorCode: string, errorMessage: string}` の shape 形式 に変更 → 静的解析が failure 戻り値を success と shape で区別可能に

Test plan

  • composer test 99/99
  • composer test:http 24/24 (1 expected skip)
  • composer analyze (Phan) exit 0 (baseline 不変)
  • composer format:check exit 0

Closes #405.

…405)

評価レポート (#401 § 2 Code Quality) 指摘の 2 件:

1. \$REQUEST_JSON が non-parameterized array → array<string,mixed>
2. ApiResponse::success() と failure() の戻り型が PHPDoc 上は
   両方 array<string,*> で statically 区別不能

### Changes

#### class/xion/ControllerBase.php

- protected \$REQUEST_JSON の PHPDoc を array<string,mixed> に
  parameterize (native type は array のまま、JsonResponder::inputJsonToArray
  の戻り PHPDoc と整合)
- 説明コメントも追加 (REST 状態変化 method のみ populate される旨)

#### class/xion/ApiResponse.php

- success() の PHPDoc に array_merge 振る舞いと "caller keys win" の
  説明を追記。@return は array<string,mixed> 維持 (caller-merged keys
  の存在で正確な shape は表現不能)。
- failure() の @return を array-shape 形式に変更:
  array{status: 'failure', errorCode: string, errorMessage: string}
  → 静的解析が failure 戻り値を success と shape で区別可能に。

### Verification

- composer test 99/99
- composer test:http 24/24 (1 expected skip)
- composer analyze (Phan) exit 0 (baseline 不変)
- composer format:check exit 0

Closes #405.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@hideyukiMORI hideyukiMORI merged commit 60d2b3a into main May 22, 2026
2 checks passed
@hideyukiMORI hideyukiMORI deleted the refactor/405-type-tightening branch May 22, 2026 16:01
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.

refactor(types): $REQUEST_JSON を array<string,mixed> 化 + ApiResponse 戻り型の success / failure 区別 (eval report PR #401)

1 participant