Skip to content

Apply removeSensitiveData()'s formatted return in services() - #201

Merged
Terrence721 merged 1 commit into
mainfrom
fix/services-list-endpoint-serialization
Aug 21, 2026
Merged

Apply removeSensitiveData()'s formatted return in services()#201
Terrence721 merged 1 commit into
mainfrom
fix/services-list-endpoint-serialization

Conversation

@Terrence721

Copy link
Copy Markdown
Owner

Summary

Found via a fresh /code-review pass on app/Http/Controllers/Api/ServicesController.php (issue #70).

services() reassigned the foreach loop variable instead of writing the result back into the $services collection:

foreach ($services as $service) {
    $service = $this->removeSensitiveData($service);
}
return response()->json($services->flatten());

Sensitive fields still ended up hidden only because makeHidden() mutates the underlying model in place, but serializeApiResponse()'s key-sort/field-reordering (created_at/updated_at moved to the end, id/uuid/description/name prepended in that order) was discarded - the list endpoint's response shape was inconsistent with every other endpoint in this controller.

Fix

->map() instead of a foreach that discards its result, so removeSensitiveData()'s actual return value is what gets serialized.

Verification

TDD-proved: formats the list endpoint response the same way removeSensitiveData() formats every other endpoint asserts updated_at is the last response key (serializeApiResponse()'s guarantee - raw model attribute order does neither the alphabetical sort nor the timestamp-to-end move). Confirmed failing against the pre-fix code (databases last instead) and passing after. Full tests/v4/Feature/Api/ suite passes (236 tests). Pint/PHPStan clean on the changed file.

services() reassigned the foreach loop variable instead of writing
the result back into the \$services collection, so
removeSensitiveData()'s formatted return (serializeApiResponse()'s
key-sort/field-reordering) was discarded - sensitive fields stayed
hidden only because makeHidden() mutates the model in place, but the
response shape was inconsistent with every other endpoint in this
controller.
@Terrence721
Terrence721 merged commit a05c237 into main Aug 21, 2026
9 checks passed
@Terrence721 Terrence721 mentioned this pull request Aug 21, 2026
77 tasks
@Terrence721
Terrence721 deleted the fix/services-list-endpoint-serialization branch August 21, 2026 12:10
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.

2 participants