Skip to content

Commit 7484ece

Browse files
authored
Merge pull request #6612 from ConductionNL/quality/build-method-decomposition-6
feat(dossiq): build method-decomposition
2 parents 30a8fed + 5b27a56 commit 7484ece

38 files changed

Lines changed: 1752 additions & 526 deletions

‎lib/Controller/WOOAssessmentController.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
* parameter is a distinct, independently-used collaborator (same rationale
6161
* as CouplingBetweenObjects above); `woo-llm-anonymisation` adds one more
6262
* (`WOOAnonymisationAssistService`) to an already-wide, long-established list.
63-
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity) The total is the sum of small private steps; each method stays under the method thresholds.
6463
*
6564
* @spec openspec/changes/archive/2026-06-13-woo-case-type/tasks.md#task-5
6665
* @spec openspec/changes/archive/2026-06-13-woo-case-type/tasks.md#task-7

‎lib/Review/ReviewBatches.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
* batch and its reviews when the case type keeps them private.
5151
*
5252
* @spec openspec/changes/woo-review-triage/specs/document-review/spec.md#requirement-batches-are-assigned-to-named-reviewers-before-any-verdict-req-wrt-003
53-
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity) The total is the sum of small private steps; each method stays under the method thresholds.
5453
*/
5554
class ReviewBatches implements ReviewBatchesInterface {
5655

‎lib/Service/CaseCopyService.php‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@
4848
* Copies one case into a new case of the same type.
4949
*
5050
* @spec openspec/specs/case-management/spec.md
51-
*
52-
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity) The total is the sum of small private steps; each method stays under the method thresholds.
5351
*/
5452
class CaseCopyService implements CaseCopyServiceInterface {
5553

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?php
2+
3+
/**
4+
* Dossiq complaint deadline alerts.
5+
*
6+
* Which active complaints are past their handling deadline or close to it,
7+
* and the overdue list an assistant may see, rebuilt from an allowlist so the
8+
* complainant never leaves.
9+
*
10+
* @category Service
11+
* @package OCA\Dossiq\Service\Complaint
12+
*
13+
* @author Conduction Development Team <info@conduction.nl>
14+
* @copyright 2026 Conduction B.V.
15+
* @license EUPL-1.2 https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
16+
*
17+
* @version GIT: <git-id>
18+
*
19+
* @link https://conduction.nl
20+
*
21+
* SPDX-License-Identifier: EUPL-1.2
22+
* SPDX-FileCopyrightText: 2026 Conduction B.V. <info@conduction.nl>
23+
*
24+
* @spec openspec/changes/method-decomposition/tasks.md
25+
*/
26+
27+
declare(strict_types=1);
28+
29+
namespace OCA\Dossiq\Service\Complaint;
30+
31+
use OCA\Dossiq\Service\CaseDateNormaliser;
32+
use OCA\Dossiq\Service\Term\DayCount;
33+
34+
/**
35+
* Sorts complaint rows by their deadlines; reads no store.
36+
*
37+
* @spec openspec/changes/archive/2026-06-13-complaint-management/tasks.md#task-TASK-CM-02
38+
* @spec openspec/changes/method-decomposition/tasks.md
39+
*/
40+
class ComplaintDeadlineAlerts {
41+
42+
/**
43+
* Fields of a complaint an assistant may see in a list (REQ-MCP-203).
44+
*
45+
* `complainant` is the citizen and is never one of them.
46+
*
47+
* @var array<string>
48+
*/
49+
private const OVERDUE_PROJECTION = [
50+
'id',
51+
'complaintNumber',
52+
'subject',
53+
'category',
54+
'status',
55+
'handler',
56+
'acknowledgementOfReceiptDeadline',
57+
'afhandelDeadline',
58+
];
59+
60+
/**
61+
* Constructor.
62+
*
63+
* @param CaseDateNormaliser $dates The one date path, and today.
64+
* @param DayCount $days Counts the days between two moments.
65+
*/
66+
public function __construct(
67+
private readonly CaseDateNormaliser $dates,
68+
private readonly DayCount $days = new DayCount(),
69+
) {
70+
}//end __construct()
71+
72+
/**
73+
* The complaints past their handling deadline, and those within the window.
74+
*
75+
* The window is counted in calendar days. A complaint without a readable
76+
* deadline is in neither group.
77+
*
78+
* @param array<int, array<string, mixed>> $complaints The active complaints.
79+
* @param int $warningDays Warn when the deadline is within this many days.
80+
*
81+
* @return array<string, array<int, array<string, mixed>>> overdue and warning.
82+
*
83+
* @spec openspec/changes/archive/2026-06-13-complaint-management/tasks.md#task-TASK-CM-02
84+
* @spec openspec/changes/method-decomposition/tasks.md
85+
*/
86+
public function grouped(array $complaints, int $warningDays): array {
87+
$today = $this->dates->today();
88+
$overdue = [];
89+
$warning = [];
90+
91+
foreach ($complaints as $complaint) {
92+
$deadlineDate = $this->dates->tryParse($complaint['afhandelDeadline'] ?? null);
93+
if ($deadlineDate === null) {
94+
continue;
95+
}
96+
97+
$diff = $this->days->between(from: $today, to: $deadlineDate);
98+
$isPast = $today > $deadlineDate;
99+
100+
if ($isPast === true) {
101+
$overdue[] = $complaint;
102+
} elseif ($diff <= $warningDays) {
103+
$warning[] = $complaint;
104+
}
105+
}
106+
107+
return ['overdue' => $overdue, 'warning' => $warning];
108+
}//end grouped()
109+
110+
/**
111+
* The overdue complaints as an assistant may see them, without the complainant.
112+
*
113+
* A row is rebuilt from an allowlist rather than stripped of a denylist, so
114+
* a field added to the schema later stays out until someone names it.
115+
*
116+
* @param array<int, array<string, mixed>> $overdue The overdue complaints.
117+
*
118+
* @return array{complaints: list<array<string, mixed>>, count: int}
119+
*
120+
* @spec openspec/changes/hermiq-ai-tooling/specs/mcp-integration/spec.md#requirement-req-mcp-203-overdue-complaints-via-redacted-projection
121+
* @spec openspec/changes/method-decomposition/tasks.md
122+
*/
123+
public function overdueRows(array $overdue): array {
124+
$today = $this->dates->today();
125+
$rows = [];
126+
foreach ($overdue as $complaint) {
127+
$row = [];
128+
foreach (self::OVERDUE_PROJECTION as $field) {
129+
if (array_key_exists($field, $complaint) === true) {
130+
$row[$field] = $complaint[$field];
131+
}
132+
}
133+
134+
$ackDeadline = $this->dates->tryParse($complaint['acknowledgementOfReceiptDeadline'] ?? null);
135+
$row['handlingOverdue'] = true;
136+
$row['acknowledgementOverdue'] = $ackDeadline !== null
137+
&& $today > $ackDeadline
138+
&& ($complaint['status'] ?? null) === 'received';
139+
$rows[] = $row;
140+
}
141+
142+
return ['complaints' => $rows, 'count' => count($rows)];
143+
}//end overdueRows()
144+
}//end class

‎lib/Service/ComplaintService.php‎

Lines changed: 19 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525

2626
use OCA\Dossiq\Kernel\AppIdentity;
2727
use OCA\Dossiq\Kernel\Contracts\ComplaintServiceInterface;
28+
use OCA\Dossiq\Service\Complaint\ComplaintDeadlineAlerts;
2829
use OCA\Dossiq\Service\Support\CallerIdentity;
2930
use OCA\Dossiq\Service\Support\SearchesObjects;
30-
use OCA\Dossiq\Service\Term\DayCount;
3131
use OCA\Dossiq\Service\Term\TermResolution;
3232
use OCA\OpenRegister\Kernel\Contracts\Value\ObjectFindTarget;
3333
use OCA\OpenRegister\Kernel\Contracts\Value\ObjectSaveOptions;
@@ -38,8 +38,6 @@
3838
/**
3939
* Service for complaint (klacht) management per Awb chapter 9.
4040
*
41-
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity) The total is the sum of small private steps; each method stays under the method thresholds.
42-
*
4341
* @spec openspec/changes/archive/2026-06-13-complaint-management/tasks.md#task-TASK-CM-02
4442
*/
4543
class ComplaintService implements ComplaintServiceInterface {
@@ -99,6 +97,13 @@ class ComplaintService implements ComplaintServiceInterface {
9997
*/
10098
private const AWB_VERDAGING_WEEKS = 4;
10199

100+
/**
101+
* Sorts complaints by their deadlines and projects the overdue list.
102+
*
103+
* @var ComplaintDeadlineAlerts
104+
*/
105+
private readonly ComplaintDeadlineAlerts $alerts;
106+
102107
/**
103108
* Constructor.
104109
*
@@ -110,16 +115,19 @@ class ComplaintService implements ComplaintServiceInterface {
110115
* @param TermResolution|null $resolution The case type's own first-response
111116
* term, which wins over the Awb
112117
* default when one is declared.
113-
* @param DayCount $days Counts the days between two moments.
118+
* @param ComplaintDeadlineAlerts|null $alerts Sorts complaints by their
119+
* deadlines; built over the same
120+
* date path when not given.
114121
*/
115122
public function __construct(
116123
private readonly SettingsService $settingsService,
117124
private readonly LoggerInterface $logger,
118125
private readonly WorkingDayCalculator $workingDays,
119126
private readonly CaseDateNormaliser $dates,
120127
private readonly ?TermResolution $resolution = null,
121-
private readonly DayCount $days = new DayCount(),
128+
?ComplaintDeadlineAlerts $alerts = null,
122129
) {
130+
$this->alerts = ($alerts ?? new ComplaintDeadlineAlerts(dates: $this->dates));
123131
}//end __construct()
124132

125133
/**
@@ -473,52 +481,17 @@ public function linkEscalatedCase(string $complaintId, string $caseId): array {
473481
*/
474482
public function getDeadlineAlerts(int $warningDays = 3): array {
475483
$activeStatuses = ['received', 'receipt_confirmed', 'in_handling', 'hoorgesprek_planned', 'hoorgesprek_completed'];
476-
$all = $this->listComplaints(filters: ['status' => $activeStatuses]);
477-
$today = $this->dates->today();
478-
$overdue = [];
479-
$warning = [];
480-
481-
foreach ($all as $complaint) {
482-
$deadlineDate = $this->dates->tryParse($complaint['afhandelDeadline'] ?? null);
483-
if ($deadlineDate === null) {
484-
continue;
485-
}
486484

487-
$diff = $this->days->between(from: $today, to: $deadlineDate);
488-
$isPast = $today > $deadlineDate;
489-
490-
if ($isPast === true) {
491-
$overdue[] = $complaint;
492-
} elseif ($diff <= $warningDays) {
493-
$warning[] = $complaint;
494-
}
495-
}
496-
497-
return ['overdue' => $overdue, 'warning' => $warning];
485+
return $this->alerts->grouped(
486+
complaints: $this->listComplaints(filters: ['status' => $activeStatuses]),
487+
warningDays: $warningDays
488+
);
498489
}//end getDeadlineAlerts()
499490

500-
/**
501-
* Fields of a complaint an assistant may see in a list (REQ-MCP-203).
502-
*
503-
* `complainant` is the citizen and is never one of them.
504-
*
505-
* @var array<string>
506-
*/
507-
private const OVERDUE_PROJECTION = [
508-
'id',
509-
'complaintNumber',
510-
'subject',
511-
'category',
512-
'status',
513-
'handler',
514-
'acknowledgementOfReceiptDeadline',
515-
'afhandelDeadline',
516-
];
517-
518491
/**
519492
* The complaints past their handling deadline, without the complainant.
520493
*
521-
* The projection is applied HERE, on the way out, because the dialect has
494+
* The projection is applied on the way out (in ComplaintDeadlineAlerts), because the dialect has
522495
* no field projection and `complaint` stays get-only there. A row is
523496
* rebuilt from an allowlist rather than stripped of a denylist, so a field
524497
* added to the schema later stays out until someone names it.
@@ -538,25 +511,7 @@ public function getDeadlineAlerts(int $warningDays = 3): array {
538511
annotations: ['outsideAgent' => true]
539512
)]
540513
public function listOverdueComplaints(): array {
541-
$today = $this->dates->today();
542-
$rows = [];
543-
foreach ($this->getDeadlineAlerts()['overdue'] as $complaint) {
544-
$row = [];
545-
foreach (self::OVERDUE_PROJECTION as $field) {
546-
if (array_key_exists($field, $complaint) === true) {
547-
$row[$field] = $complaint[$field];
548-
}
549-
}
550-
551-
$ackDeadline = $this->dates->tryParse($complaint['acknowledgementOfReceiptDeadline'] ?? null);
552-
$row['handlingOverdue'] = true;
553-
$row['acknowledgementOverdue'] = $ackDeadline !== null
554-
&& $today > $ackDeadline
555-
&& ($complaint['status'] ?? null) === 'received';
556-
$rows[] = $row;
557-
}
558-
559-
return ['complaints' => $rows, 'count' => count($rows)];
514+
return $this->alerts->overdueRows(overdue: $this->getDeadlineAlerts()['overdue']);
560515
}//end listOverdueComplaints()
561516

562517
/**

0 commit comments

Comments
 (0)