Skip to content

refactor: extract shared path-resolution helpers for console commands / コンソールコマンドのパス解決ヘルパーを共通化 - #583

Merged
zigzagdev merged 7 commits into
refactor/console-commands-cleanupfrom
refactor/console-commands-cleanup_path-helpers
Oct 4, 2026
Merged

zigzagdev merged 7 commits into
refactor/console-commands-cleanupfrom
refactor/console-commands-cleanup_path-helpers

Conversation

@zigzagdev

Copy link
Copy Markdown
Owner

Motivation / 目的

normalizeLocalDiskPath/resolvePathToDir/resolvePathToFile/resolvePath were
copy-pasted across multiple UNESCO data pipeline console commands
(SplitWorldHeritageJson, DumpUnescoWorldHeritageJson,
DumpWorldHeritageSiteJapaneseName, ImportWorldHeritageJapaneseNameFromJson,
ImportSiteStatePartiesFromSplitFile, and the LoadsJsonRows trait). This made
the pipeline harder to maintain and was identified while reviewing the
Console/Commands directory for cleanup.

複数のUNESCOデータパイプライン用コンソールコマンドに同一のパス解決ロジックが
コピペされており、保守性を下げていました。Console/Commandsディレクトリの
整理の一環として対応します。

What I have done / 実施内容

  • Added ResolvesLocalDiskPaths trait consolidating
    normalizeLocalDiskPath / resolvePathToDir / resolvePathToFile
  • Updated LoadsJsonRows to delegate resolvePath() to the new trait
    instead of duplicating the same logic
  • Removed the duplicated methods from SplitWorldHeritageJson,
    DumpUnescoWorldHeritageJson, DumpWorldHeritageSiteJapaneseName,
    ImportWorldHeritageJapaneseNameFromJson, and the redundant override in
    ImportSiteStatePartiesFromSplitFile
  • Left MakeManualSiteNamesJson::resolvePath() untouched — it behaves
    differently (uses base_path(), doesn't strip the private/ prefix),
    so unifying it would change behavior, not just dedupe

Test Results / テスト結果

  • php artisan test (full suite): 216 passed, no regressions
  • Confirmed SplitWorldHeritageJsonIsTransboundaryTest and
    ImportWorldHeritageSiteFromSplitFileIsTransboundaryTest still pass,
    since they exercise the refactored path-resolution code paths

…h resolution

normalizeLocalDiskPath/resolvePathToDir/resolvePathToFile were copy-pasted
across multiple console commands. Extract them into a shared trait and
have LoadsJsonRows delegate to it instead of duplicating the same logic.
Remove the duplicated normalizeLocalDiskPath/resolvePathToDir/
resolvePathToFile methods in favor of the shared trait.
Remove the duplicated normalizeLocalDiskPath method in favor of the
shared trait.
…Name

Remove the duplicated normalizeLocalDiskPath/resolvePath methods in
favor of the shared trait, renaming the call site to resolvePathToFile.
…meFromJson

Remove the duplicated resolvePath method in favor of the shared trait,
renaming the call sites to resolvePathToFile.
…tiesFromSplitFile

This class already uses LoadsJsonRows, which now provides resolvePath
via ResolvesLocalDiskPaths. The local override was an exact duplicate
of the trait's implementation.
@codecov

codecov Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.08197% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.85%. Comparing base (8329774) to head (eeac4d2).

Files with missing lines Patch % Lines
...mmands/ImportWorldHeritageJapaneseNameFromJson.php 0.00% 2 Missing ⚠️
...ole/Commands/DumpWorldHeritageSiteJapaneseName.php 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                           Coverage Diff                           @@
##             refactor/console-commands-cleanup     #583      +/-   ##
=======================================================================
+ Coverage                                67.02%   67.85%   +0.82%     
+ Complexity                                1707     1689      -18     
=======================================================================
  Files                                      149      151       +2     
  Lines                                     8929     8896      -33     
=======================================================================
+ Hits                                      5985     6036      +51     
+ Misses                                    2944     2860      -84     
Files with missing lines Coverage Δ
...p/Console/Commands/DumpUnescoWorldHeritageJson.php 0.00% <ø> (ø)
...e/Commands/ImportSiteStatePartiesFromSplitFile.php 0.00% <ø> (ø)
...rc/app/Console/Commands/SplitWorldHeritageJson.php 15.13% <ø> (+0.55%) ⬆️
src/app/Console/Concerns/LoadsJsonRows.php 75.00% <100.00%> (+6.81%) ⬆️
...rc/app/Console/Concerns/ResolvesLocalDiskPaths.php 100.00% <100.00%> (ø)
...WorldHeritage/Tests/ResolvesLocalDiskPathsTest.php 100.00% <100.00%> (ø)
...ole/Commands/DumpWorldHeritageSiteJapaneseName.php 0.00% <0.00%> (ø)
...mmands/ImportWorldHeritageJapaneseNameFromJson.php 0.00% <0.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Address codecov/patch failure on PR #583 (46.66% diff coverage) by
directly testing normalizeLocalDiskPath/resolvePathToDir/resolvePathToFile
for empty input, absolute paths, Windows drive paths, and relative paths
resolved via the local disk.
@zigzagdev zigzagdev self-assigned this Oct 4, 2026

@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.

Ok

@zigzagdev
zigzagdev merged commit 8f0d304 into refactor/console-commands-cleanup Oct 4, 2026
27 checks passed
@zigzagdev
zigzagdev deleted the refactor/console-commands-cleanup_path-helpers branch October 4, 2026 23:38
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