Skip to content

refactor(support): read results through SearchesObjects in the contact, transition and subsidy readers - #5883

Merged
rubenvdlinde merged 2 commits into
developmentfrom
quality/h16-result-reader-contacts
Nov 12, 2026
Merged

rubenvdlinde merged 2 commits into
developmentfrom
quality/h16-result-reader-contacts

Conversation

@rubenvdlinde

Copy link
Copy Markdown
Contributor

What changed

Seven classes carried their own copy of a reading Support\SearchesObjects already has (objectToArrayOrNull()): keep an array, take an entity's jsonSerialize() array, and treat anything else (an object without jsonSerialize(), a serialisation that is not an array, a scalar, null) as empty. Two spellings existed (array first, or object first), with the same answers.

Service\Support\SerialisedResult offers the trait's reading to classes that do not compose SearchesObjects: rowOf() (the row or null) and arrayOf() (the row or an empty array). It adds no reading of its own; it composes the trait and calls it. Each private toArray() keeps its name and delegates to SerialisedResult::arrayOf(), so every caller stays untouched, including the methods changed by open PRs #5340, #5349 and #5353.

Classes: SubsidieRegisterController, Kcc\CallbackService, Kcc\ContactMomentService, Kcc\RoutingRuleService, StateMachineService, Transitions\CaseResultWriter, Transitions\CaseTypeReader.

This replaces #5860, whose new static helper repeated the trait's reading and so was itself reported as a new duplicated fragment while other copies remained.

Characterisation tests

tests/Unit/Service/Support/ResultArrayContactCopiesTest.php, committed first and green on the old code: every copy (by reflection) against nine kinds of result (array, empty array, serialisable to an array, serialisable to a string, plain object, ArrayObject, string, integer, null). 63 cases.

What ran

  • phpunit -c phpunit-unit.xml on the new test, every unit test class that names one of the seven classes, and tests/Unit/Architecture: 641 tests, all green but two inherited failures.
  • phpcs and phpstan analyse on the touched files: no findings.
  • The duplicated-fragment and unit ratchet (gate 122) against development: 0 findings.

Inherited: ServiceCatchReturnsNullTest::testEveryAllowlistEntryNamesALiveSite is red on development too (a stale allowlist entry for lib/Service/Settings/OpenRegisterBridge.php), and StatusEntryRequirementsGuardTest::testTheEvaluatorReadsTheCaseAsTheFilterDoes needs an installed openregister checkout beside the app; both untouched here.

Duplication figures (duplicated 6-line windows, before -> after)

  • CallbackService <-> ContactMomentService: 23 -> 13 (what remains sits in cancel and update, both changed by refactor(dossiq): save objects through ObjectSaveOptions #5353, and in resolve, get, related and findOwned)
  • CallbackService <-> RoutingRuleService: 9 -> 0
  • CaseTypeReader <-> CaseResultWriter: 8 -> 0
  • SubsidieRegisterController <-> CaseTypeReader: 8 -> 0

AI-assisted: prepared with Claude Code (claude-opus-5-5); reviewed by a maintainer before merge.


Generated by Claude Code

…subsidy readers before sharing them

Assisted-by: ClaudeCode:claude-opus-5-5
…t, transition and subsidy readers

Seven classes carried their own copy of the reading SearchesObjects already
has: keep an array, take an entity's jsonSerialize() array, anything else
is empty. Support\SerialisedResult offers the trait's reading to classes
that do not compose it; each private toArray() now delegates to it.

Assisted-by: ClaudeCode:claude-opus-5-5
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