Skip to content

Commit f165220

Browse files
refactor(support): share the result-to-array reading of the intake, permit, capacity and advice services
Six more classes carried the jsonSerialize-only reading under other names (normalize, normalizeToArray, arrayOf, asArray, objectAsArray). Each now delegates to Support\SerialisedArray::of(), added here with the same content as in the sibling changes so any of them can merge first. Assisted-by: ClaudeCode:claude-opus-5-5
1 parent 2d82b95 commit f165220

7 files changed

Lines changed: 71 additions & 72 deletions

File tree

‎lib/Service/Advice/AdviceRepository.php‎

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
use OCA\Dossiq\AppInfo\Application;
4343
use OCA\Dossiq\Service\SettingsService;
4444
use OCA\Dossiq\Service\Support\SearchesObjects;
45+
use OCA\Dossiq\Service\Support\SerialisedArray;
4546
use Psr\Log\LoggerInterface;
4647
use RuntimeException;
4748
use Throwable;
@@ -232,17 +233,6 @@ public function save(array $update, string $adviceId): array {
232233
* @spec openspec/specs/advice-management/spec.md
233234
*/
234235
public function normalize(mixed $result): array {
235-
if (is_array($result) === true) {
236-
return $result;
237-
}
238-
239-
if (is_object($result) === true && method_exists($result, 'jsonSerialize') === true) {
240-
$data = $result->jsonSerialize();
241-
if (is_array($data) === true) {
242-
return $data;
243-
}
244-
}
245-
246-
return [];
236+
return SerialisedArray::of(value: $result);
247237
}//end normalize()
248238
}//end class

‎lib/Service/DsoCaseService.php‎

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use OCA\Dossiq\AppInfo\Application;
3131
use OCA\Dossiq\Service\Lifecycle\CaseJournal;
3232
use OCA\Dossiq\Service\Support\SearchesObjects;
33+
use OCA\Dossiq\Service\Support\SerialisedArray;
3334
use OCA\OpenRegister\Contract\ObjectServiceInterface;
3435
use OCP\IAppConfig;
3536
use OCP\IUser;
@@ -437,18 +438,7 @@ private function getObjectService(): object {
437438
* @return array<string, mixed> The normalised array (empty when not coercible).
438439
*/
439440
private function normalizeToArray(mixed $value): array {
440-
if (is_array($value) === true) {
441-
return $value;
442-
}
443-
444-
if (is_object($value) === true && method_exists($value, 'jsonSerialize') === true) {
445-
$serialized = $value->jsonSerialize();
446-
if (is_array($serialized) === true) {
447-
return $serialized;
448-
}
449-
}
450-
451-
return [];
441+
return SerialisedArray::of(value: $value);
452442
}//end normalizeToArray()
453443

454444
/**

‎lib/Service/FormsIntakeService.php‎

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
namespace OCA\Dossiq\Service;
4646

4747
use OCA\Dossiq\Service\Intake\IntakeFormBinding;
48+
use OCA\Dossiq\Service\Support\SerialisedArray;
4849
use OCA\OpenRegister\Service\Form\FormSubmission;
4950
use OCA\OpenRegister\Service\Form\FormSubmitter;
5051
use Psr\Log\LoggerInterface;
@@ -351,18 +352,7 @@ private function rowsOf(mixed $result): array {
351352
* @return array<string, mixed> The row as an array.
352353
*/
353354
private function arrayOf(mixed $row): array {
354-
if (is_array($row) === true) {
355-
return $row;
356-
}
357-
358-
if (is_object($row) === true && method_exists($row, 'jsonSerialize') === true) {
359-
$serialised = $row->jsonSerialize();
360-
if (is_array($serialised) === true) {
361-
return $serialised;
362-
}
363-
}
364-
365-
return [];
355+
return SerialisedArray::of(value: $row);
366356
}//end arrayOf()
367357

368358
/**

‎lib/Service/Intake/CaseIntakeFiling.php‎

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
use OCA\Dossiq\Exception\RefusedException;
5050
use OCA\Dossiq\Service\CaseTypeStore;
5151
use OCA\Dossiq\Service\SettingsService;
52+
use OCA\Dossiq\Service\Support\SerialisedArray;
5253
use Psr\Log\LoggerInterface;
5354
use Throwable;
5455

@@ -270,17 +271,6 @@ private function reasonOf(Throwable $error): string {
270271
* @return array<string, mixed> The array.
271272
*/
272273
private function asArray(mixed $value): array {
273-
if (is_array($value) === true) {
274-
return $value;
275-
}
276-
277-
if (is_object($value) === true && method_exists($value, 'jsonSerialize') === true) {
278-
$serialised = $value->jsonSerialize();
279-
if (is_array($serialised) === true) {
280-
return $serialised;
281-
}
282-
}
283-
284-
return [];
274+
return SerialisedArray::of(value: $value);
285275
}//end asArray()
286276
}//end class

‎lib/Service/Intake/ChannelIntake.php‎

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
use OCA\Dossiq\Service\Email\IntakeLog;
6262
use OCA\Dossiq\Service\SettingsService;
6363
use OCA\Dossiq\Service\Support\SearchesObjects;
64+
use OCA\Dossiq\Service\Support\SerialisedArray;
6465
use Psr\Log\LoggerInterface;
6566
use Throwable;
6667

@@ -479,17 +480,6 @@ private function refuse(string $channel, string $externalId, array $message, str
479480
* @return array<string, mixed> The row, or an empty array.
480481
*/
481482
private function objectAsArray(mixed $value): array {
482-
if (is_array($value) === true) {
483-
return $value;
484-
}
485-
486-
if (is_object($value) === true && method_exists($value, 'jsonSerialize') === true) {
487-
$serialized = $value->jsonSerialize();
488-
if (is_array($serialized) === true) {
489-
return $serialized;
490-
}
491-
}
492-
493-
return [];
483+
return SerialisedArray::of(value: $value);
494484
}//end objectAsArray()
495485
}//end class
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
/**
4+
* An OpenRegister result as an array, through its own serialisation only
5+
*
6+
* OpenRegister answers a plain array or an entity depending on the call path.
7+
* Many readers keep an array, take an entity's jsonSerialize() array, and
8+
* treat anything else as empty. Unlike NormalisesObjectRows::objectToArray(),
9+
* an object without jsonSerialize() is not cast: it is empty.
10+
*
11+
* @category Service
12+
* @package OCA\Dossiq\Service\Support
13+
*
14+
* @author Conduction Development Team <info@conduction.nl>
15+
* @copyright 2026 Conduction B.V.
16+
* @license EUPL-1.2 https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
17+
*
18+
* SPDX-License-Identifier: EUPL-1.2
19+
* SPDX-FileCopyrightText: 2026 Conduction B.V. <info@conduction.nl>
20+
*
21+
* @link https://conduction.nl
22+
*
23+
* @spec openspec/specs/case-management/spec.md
24+
*/
25+
26+
declare(strict_types=1);
27+
28+
namespace OCA\Dossiq\Service\Support;
29+
30+
/**
31+
* Turns a result into the array it serialises to, or an empty array.
32+
*
33+
* @spec openspec/specs/case-management/spec.md
34+
*/
35+
final class SerialisedArray {
36+
/**
37+
* The result as an array: itself, or its jsonSerialize() array, or empty.
38+
*
39+
* @param mixed $value An array, an entity or anything else OpenRegister answered.
40+
*
41+
* @return array<mixed> The array; empty when the value serialises to no array.
42+
*
43+
* @spec openspec/specs/case-management/spec.md
44+
*/
45+
public static function of(mixed $value): array {
46+
if (is_array($value) === true) {
47+
return $value;
48+
}
49+
50+
if (is_object($value) === true && method_exists($value, 'jsonSerialize') === true) {
51+
$serialised = $value->jsonSerialize();
52+
if (is_array($serialised) === true) {
53+
return $serialised;
54+
}
55+
}
56+
57+
return [];
58+
}//end of()
59+
}//end class

‎lib/Service/Transitions/CapacityGuard.php‎

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
namespace OCA\Dossiq\Service\Transitions;
4343

4444
use OCA\Dossiq\Service\SettingsService;
45+
use OCA\Dossiq\Service\Support\SerialisedArray;
4546
use OCP\IL10N;
4647
use Throwable;
4748

@@ -370,17 +371,6 @@ private static function firstId(array $row): string {
370371
* @return array<string, mixed> The row.
371372
*/
372373
private function arrayOf(mixed $row): array {
373-
if (is_array($row) === true) {
374-
return $row;
375-
}
376-
377-
if (is_object($row) === true && method_exists($row, 'jsonSerialize') === true) {
378-
$serialised = $row->jsonSerialize();
379-
if (is_array($serialised) === true) {
380-
return $serialised;
381-
}
382-
}
383-
384-
return [];
374+
return SerialisedArray::of(value: $row);
385375
}//end arrayOf()
386376
}//end class

0 commit comments

Comments
 (0)