Skip to content

refactor: split SplitWorldHeritageJson::handle() into smaller methods / handle()メソッドの分割 - #584

Merged
zigzagdev merged 2 commits into
refactor/console-commands-cleanupfrom
refactor/console-commands-cleanup_split-handle
Oct 6, 2026
Merged

zigzagdev merged 2 commits into
refactor/console-commands-cleanupfrom
refactor/console-commands-cleanup_split-handle

Conversation

@zigzagdev

Copy link
Copy Markdown
Owner

Motivation / 目的

SplitWorldHeritageJson::handle() had grown to roughly 550 lines, mixing
input parsing, a 220-line per-row validation/normalization loop, and
repetitive output-payload assembly all in one method. This made the
command hard to read and reason about.

SplitWorldHeritageJson::handle()が約550行に肥大化し、入力パース・220行の
行単位の検証/正規化ループ・繰り返しの多い出力ペイロード組み立てが1つの
メソッドに混在していました。可読性・保守性を改善します。

What I have done / 実施内容

  • Stage A: Extracted the repeated meta-block construction (shared by the
    6 output payloads: sites/countries/pivot/images/judgements/exceptions)
    into a buildPayload() helper
  • Stage B: Extracted the per-row validation/normalization loop into its
    own processRows() method, returning the collected collections and
    counters as an array. handle() is now orchestration only: read input,
    delegate to processRows(), build payloads, write output
  • No behavior changes — both stages are pure structural refactors

Test Results / テスト結果

  • php artisan test (full suite): 226 passed, no regressions
  • Verified with ad-hoc fixture runs of world-heritage:split-json that
    generated JSON meta blocks are byte-identical in key order/values, and
    that skip branches (missing/non-numeric id_no) and --strict mode's
    failure propagation still behave correctly end-to-end

…e A)

The 6 output payloads (sites/countries/pivot/images/judgements/exceptions)
all shared the same meta block shape (schema/source_raw/generated_at/
rows_scanned) with only a few payload-specific extra fields. Extract that
repetition into buildPayload() to shrink the giant handle() method.

Verified against a fixture run that the generated JSON meta blocks are
unchanged in key order and values.
Move the 220-line per-row validation/normalization loop out of handle()
into its own processRows() method, returning the collected sites/
countries/pivot/images/judgements/exceptions and counters as an array.
handle() is now orchestration only: read input, delegate row processing,
build payloads, write output.

Verified against fixture runs covering the happy path, skip branches
(missing/non-numeric id_no), and --strict mode's failure propagation,
plus the full test suite (226 passed).

@zigzagdev zigzagdev left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

LGTM

@zigzagdev
zigzagdev merged commit 8eba9d2 into refactor/console-commands-cleanup Oct 6, 2026
26 checks passed
@zigzagdev
zigzagdev deleted the refactor/console-commands-cleanup_split-handle branch October 6, 2026 00:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant