Skip to content

GH-74: Split the 164-line mapSingleObject() along its phases - #120

Merged
magicsunday merged 2 commits into
mainfrom
GH-74
Jul 19, 2026
Merged

GH-74: Split the 164-line mapSingleObject() along its phases#120
magicsunday merged 2 commits into
mainfrom
GH-74

Conversation

@magicsunday

Copy link
Copy Markdown
Owner

Fixes #74.

mapSingleObject() ran a full pipeline in one body, its phases already marked by comment blocks. It is now a 22-line orchestration that reads as the pipeline it is:

collect converted values  ->  report missing properties (strict)  ->  hydrate

Each phase is its own method, and the state they hand along — the converted values, the names actually mapped — travels by return rather than by shared locals, so each method's inputs and outputs are its signature.

Three phases, not four

The issue suggested applyUnknownCollector() as a fourth method. The simplicity review argued against it and I agreed: a 12-line single caller that re-read collectorProperty (which the collect loop already holds) and forced a third tuple element whose only job was to be handed straight back for merging. The divert and the merge are two halves of one concern — a key with no declared property is diverted during the loop, the gathered keys merged after it — so both live in collectConvertedValues() now. e.g. in the issue, and a single-caller method re-reading its own input is what KISS ranks below keeping the concern whole.

Verification

Behaviour-neutral: main and this branch produce identical results, confirmed statement-by-statement by review and by the full suite. The collector merge still runs at the same logical point — appending its property to the mapped list before the strict missing-check, so it is never falsely reported missing.

Rests on #72 and #73 having already removed the configuration round trip and the per-element reflection this method used to carry, so what remained split cleanly along the existing seams.

composer ci:test green, verified by exit code: 379 tests, 1225 assertions; PHPStan max, Rector, CGL and CPD clean.

The method ran a full pipeline in one body, its phases already marked by
comment blocks. It is now an orchestration that reads as the pipeline it
is - collect converted values, apply the unknown collector, report missing
properties, hydrate - with each phase in its own method.

The state the phases hand along - the converted values, the names actually
mapped, the diverted unknown keys - travels by return rather than by
shared locals, so each method's inputs and outputs are its signature. That
is also why collectConvertedValues() returns the unknown keys separately
for applyUnknownCollector() rather than merging inline: the merge is a
distinct phase, not a tail of the collection loop.

180 lines of body became a 31-line orchestration plus four named methods.
Behaviour-neutral: the whole suite was green before this commit's own
formatting pass. #72 and #73 had already removed the configuration round
trip and the per-element reflection this method used to carry, so what
remained split cleanly along the existing seams.
The simplicity review pushed back on applyUnknownCollector() as its own
method, and the argument held: it re-read metadata->collectorProperty that
collectConvertedValues() already has as a local, and it forced that method
to return a third tuple element whose only purpose was to be handed
straight back for merging. The divert and the merge are two halves of one
concern - a key with no declared property is diverted during the loop and
the gathered keys merged after it - so they belong in one method.

collectConvertedValues() now does both and returns a two-tuple. The
orchestration drops to three phases, and the double read is gone. The
issue suggested applyUnknownCollector() as a phase name, but 'e.g.' - and
a single-caller method re-reading its own input is what KISS ranks below
keeping the concern whole.

Also trimmed per the review: the orchestration's lead comment no longer
narrates the refactor's history, and a docblock sentence that restated an
inline comment three lines down is gone.
@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@magicsunday
magicsunday merged commit 976e49a into main Jul 19, 2026
19 checks passed
@magicsunday
magicsunday deleted the GH-74 branch July 19, 2026 20:21
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.

Split the 164-line mapSingleObject() along its existing phases

1 participant