@@ -31,18 +31,18 @@ class MapperService
31
31
public static function mapOfficesWithScope (ProviderList $ providerList ): OfficeList
32
32
{
33
33
$ offices = [];
34
- $ scopes = new ScopeList ( ZmsApiClientService::getScopes () ?? [] );
34
+ $ scopes = ZmsApiClientService::getScopes () ?? new ScopeList ( );
35
35
36
36
foreach ($ providerList as $ provider ) {
37
37
$ providerScope = ZmsApiFacadeService::getScopeForProvider ($ provider ->id , $ scopes );
38
38
39
39
$ offices [] = new Office (
40
- id: (int )$ provider ->id ,
40
+ id: (int ) $ provider ->id ,
41
41
name: $ provider ->displayName ?? $ provider ->name ,
42
42
address: $ provider ->data ['address ' ] ?? null ,
43
43
geo: $ provider ->data ['geo ' ] ?? null ,
44
44
scope: isset ($ providerScope ) && !isset ($ providerScope ['errors ' ]) ? new ThinnedScope (
45
- id: (int )($ providerScope ->id ?? 0 ),
45
+ id: (int ) ($ providerScope ->id ?? 0 ),
46
46
provider: $ providerScope ->provider ?? null ,
47
47
shortName: $ providerScope ->shortName ?? null ,
48
48
telephoneActivated: $ providerScope ->telephoneActivated ?? null ,
@@ -64,18 +64,27 @@ public static function mapCombinable(array $serviceCombinations): ?Combinable
64
64
return !empty ($ serviceCombinations ) ? new Combinable ($ serviceCombinations ) : null ;
65
65
}
66
66
67
+ /**
68
+ * Map services with combinations based on request and relation lists.
69
+ *
70
+ * @param RequestList $requestList
71
+ * @param RequestRelationList $relationList
72
+ * @return ServiceList
73
+ */
67
74
public static function mapServicesWithCombinations (RequestList $ requestList , RequestRelationList $ relationList ): ServiceList
68
75
{
76
+ /** @var array<string, array<int>> $servicesProviderIds */
69
77
$ servicesProviderIds = [];
70
78
foreach ($ relationList as $ relation ) {
71
- if (!isset ($ servicesProviderIds [$ relation ->request ->id ])) {
72
- $ servicesProviderIds [$ relation ->request ->id ] = [];
73
- }
74
- $ servicesProviderIds [$ relation ->request ->id ][] = $ relation ->provider ->id ;
79
+ $ serviceId = $ relation ->request ->id ;
80
+ $ servicesProviderIds [$ serviceId ] ??= [];
81
+ $ servicesProviderIds [$ serviceId ][] = $ relation ->provider ->id ;
75
82
}
76
83
84
+ /** @var Service[] $services */
77
85
$ services = [];
78
86
foreach ($ requestList as $ service ) {
87
+ /** @var array<string, array<int>> $serviceCombinations */
79
88
$ serviceCombinations = [];
80
89
$ combinableData = $ service ->getAdditionalData ()['combinable ' ] ?? [];
81
90
@@ -90,7 +99,7 @@ public static function mapServicesWithCombinations(RequestList $requestList, Req
90
99
$ combinable = self ::mapCombinable ($ serviceCombinations );
91
100
92
101
$ services [] = new Service (
93
- id: (int )$ service ->getId (),
102
+ id: (int ) $ service ->getId (),
94
103
name: $ service ->getName (),
95
104
maxQuantity: $ service ->getAdditionalData ()['maxQuantity ' ] ?? 1 ,
96
105
combinable: $ combinable ?? new Combinable ()
@@ -100,14 +109,13 @@ public static function mapServicesWithCombinations(RequestList $requestList, Req
100
109
return new ServiceList ($ services );
101
110
}
102
111
103
-
104
112
public static function mapRelations (RequestRelationList $ relationList ): OfficeServiceRelationList
105
113
{
106
114
$ relations = [];
107
115
foreach ($ relationList as $ relation ) {
108
116
$ relations [] = new OfficeServiceRelation (
109
- officeId: (string )$ relation ->provider ->id ,
110
- serviceId: (string )$ relation ->request ->id ,
117
+ officeId: (string ) $ relation ->provider ->id ,
118
+ serviceId: (string ) $ relation ->request ->id ,
111
119
slots: intval ($ relation ->slots )
112
120
);
113
121
}
@@ -287,7 +295,7 @@ public static function thinnedProcessToProcess(ThinnedProcess $thinnedProcess):
287
295
public static function providerToThinnedProvider (Provider $ provider ): ThinnedProvider
288
296
{
289
297
return new ThinnedProvider (
290
- id: isset ($ provider ->id ) ? (int )$ provider ->id : null ,
298
+ id: isset ($ provider ->id ) ? (int ) $ provider ->id : null ,
291
299
name: $ provider ->name ?? null ,
292
300
source: $ provider ->source ?? null ,
293
301
contact: $ provider ->contact ?? null ,
@@ -303,7 +311,7 @@ public static function providerToThinnedProvider(Provider $provider): ThinnedPro
303
311
public static function thinnedProviderToProvider (ThinnedProvider $ thinnedProvider ): Provider
304
312
{
305
313
$ provider = new Provider ();
306
- $ provider ->id = isset ($ thinnedProvider ->id ) ? (string )$ thinnedProvider ->id : null ; // Convert int ID to string
314
+ $ provider ->id = isset ($ thinnedProvider ->id ) ? (string ) $ thinnedProvider ->id : null ; // Convert int ID to string
307
315
$ provider ->name = $ thinnedProvider ->name ?? null ;
308
316
$ provider ->source = $ thinnedProvider ->source ?? null ;
309
317
0 commit comments