@@ -84,21 +84,22 @@ public function __construct(Composer $composer, IOInterface $io)
84
84
}
85
85
86
86
/**
87
- * @return array<string , string>
87
+ * @return array<int , string>
88
88
*/
89
- private function getPreferredInstall (): array
89
+ private function getPreferredInstallChanged (): array
90
90
{
91
91
$ config = $ this ->configFile ->read ();
92
92
93
93
if (
94
94
!is_array ($ config )
95
- || !is_array ($ config [self ::CONFIG ] ?? null )
96
- || !is_array ($ config [self ::CONFIG ][self ::CONFIG_PREFERRED_INSTALL ] ?? null )
95
+ || !is_array ($ config [self ::EXTRA ] ?? null )
96
+ || !is_array ($ config [self ::EXTRA ][self ::EXTRA_BASE ] ?? null )
97
+ || !is_array ($ config [self ::EXTRA ][self ::EXTRA_BASE ][self ::EXTRA_PREFERRED_INSTALL_CHANGED ] ?? null )
97
98
) {
98
99
return [];
99
100
}
100
101
101
- return $ config [self ::CONFIG ][self ::CONFIG_PREFERRED_INSTALL ];
102
+ return $ config [self ::EXTRA ][self ::EXTRA_BASE ][ self :: EXTRA_PREFERRED_INSTALL_CHANGED ];
102
103
}
103
104
104
105
/**
@@ -121,93 +122,75 @@ private function getAppliedChanges(): array
121
122
}
122
123
123
124
/**
124
- * @return array<int, string>
125
- */
126
- private function getPreferredInstallChanged (): array
127
- {
128
- $ config = $ this ->configFile ->read ();
129
-
130
- if (
131
- !is_array ($ config )
132
- || !is_array ($ config [self ::EXTRA ] ?? null )
133
- || !is_array ($ config [self ::EXTRA ][self ::EXTRA_BASE ] ?? null )
134
- || !is_array ($ config [self ::EXTRA ][self ::EXTRA_BASE ][self ::EXTRA_PREFERRED_INSTALL_CHANGED ] ?? null )
135
- ) {
136
- return [];
137
- }
138
-
139
- return $ config [self ::EXTRA ][self ::EXTRA_BASE ][self ::EXTRA_PREFERRED_INSTALL_CHANGED ];
140
- }
141
-
142
- /**
143
- * @return array<string, array<string, string>>
125
+ * @return array<string, string>
144
126
*/
145
- private function getPatches (): array
127
+ private function getPreferredInstall (): array
146
128
{
147
129
$ config = $ this ->configFile ->read ();
148
130
149
131
if (
150
132
!is_array ($ config )
151
- || !is_array ($ config [self ::EXTRA ] ?? null )
152
- || !is_array ($ config [self ::EXTRA ][ ' patches ' ] ?? null )
133
+ || !is_array ($ config [self ::CONFIG ] ?? null )
134
+ || !is_array ($ config [self ::CONFIG ][ self :: CONFIG_PREFERRED_INSTALL ] ?? null )
153
135
) {
154
136
return [];
155
137
}
156
138
157
- return $ config [self ::EXTRA ]['patches ' ];
158
- }
159
-
160
- /**
161
- * @param array<string, array<string, string>> $patches
162
- */
163
- private function addPatchesToConfigFile (array $ patches ): void
164
- {
165
- foreach ($ patches as $ packageName => $ packagePatches ) {
166
- $ this ->configSource ->addProperty (sprintf ('extra.patches.%s ' , $ packageName ), $ packagePatches );
167
- }
168
- }
169
-
170
- /**
171
- * @param array<string, array<string, string>> $patches
172
- */
173
- private function removePatchesFromConfigFile (array $ patches ): void
174
- {
175
- foreach (array_keys ($ patches ) as $ packageName ) {
176
- $ this ->configSource ->removeProperty (sprintf ('extra.patches.%s ' , $ packageName ));
177
- }
139
+ return $ config [self ::CONFIG ][self ::CONFIG_PREFERRED_INSTALL ];
178
140
}
179
141
180
- private function setSourceInstall (string $ packageName ): void
142
+ private function addPreferredInstallChanged (string $ packageName ): void
181
143
{
182
- $ currentValue = $ this ->getPreferredInstall ();
144
+ $ currentValue = $ this ->getPreferredInstallChanged ();
183
145
184
- if (isset ( $ currentValue [ $ packageName]) && $ currentValue[ $ packageName ] === ' source ' ) {
185
- // source install for this package is already configured , skip it
146
+ if (in_array ( $ packageName, $ currentValue, true ) ) {
147
+ // the package is already listed , skip addition
186
148
return ;
187
149
}
188
150
189
- $ this ->configSource ->addConfigSetting (
190
- 'preferred-install. ' . $ packageName ,
191
- 'source '
192
- );
151
+ $ currentValue [] = $ packageName ;
152
+ sort ($ currentValue );
193
153
194
- $ this ->addPreferredInstallChanged ($ packageName );
154
+ $ this ->configSource ->addProperty (
155
+ sprintf (
156
+ 'extra.%s.%s ' ,
157
+ self ::EXTRA_BASE ,
158
+ self ::EXTRA_PREFERRED_INSTALL_CHANGED
159
+ ),
160
+ $ currentValue
161
+ );
195
162
}
196
163
197
- private function unsetSourceInstall (string $ packageName ): void
164
+ private function removePreferredInstallChanged (string $ packageName ): void
198
165
{
199
166
$ currentValue = $ this ->getPreferredInstallChanged ();
200
167
201
168
if (!in_array ($ packageName , $ currentValue , true )) {
202
- // source was not set by this package , skip removal
169
+ // the package is not listed , skip removal
203
170
return ;
204
171
}
205
172
206
- $ this ->configSource ->removeConfigSetting (
207
- 'preferred-install. ' . $ packageName
173
+ $ currentValue = array_filter ($ currentValue , fn ($ value ): bool => $ value !== $ packageName );
174
+ sort ($ currentValue );
175
+
176
+ $ this ->configSource ->addProperty (
177
+ sprintf (
178
+ 'extra.%s.%s ' ,
179
+ self ::EXTRA_BASE ,
180
+ self ::EXTRA_PREFERRED_INSTALL_CHANGED
181
+ ),
182
+ $ currentValue
208
183
);
184
+ }
209
185
210
- $ this ->removePreferredInstallChanged ($ packageName );
186
+ /**
187
+ * @param array<string, array<string, string>> $patches
188
+ */
189
+ private function addPatchesToConfigFile (array $ patches ): void
190
+ {
191
+ foreach ($ patches as $ packageName => $ packagePatches ) {
192
+ $ this ->configSource ->addProperty (sprintf ('extra.patches.%s ' , $ packageName ), $ packagePatches );
193
+ }
211
194
}
212
195
213
196
private function addAppliedChange (int $ numericId ): void
@@ -232,67 +215,84 @@ private function addAppliedChange(int $numericId): void
232
215
);
233
216
}
234
217
235
- private function removeAppliedChange ( int $ numericId ): void
218
+ private function setSourceInstall ( string $ packageName ): void
236
219
{
237
- $ currentValue = $ this ->getAppliedChanges ();
220
+ $ currentValue = $ this ->getPreferredInstall ();
238
221
239
- if (! in_array ( $ numericId , $ currentValue, true ) ) {
240
- // the package is not listed , skip removal
222
+ if (isset ( $ currentValue [ $ packageName ]) && $ currentValue[ $ packageName ] === ' source ' ) {
223
+ // source install for this package is already configured , skip it
241
224
return ;
242
225
}
243
226
244
- $ currentValue = array_filter ($ currentValue , fn ($ value ): bool => $ value !== $ numericId );
245
- sort ($ currentValue );
246
-
247
- $ this ->configSource ->addProperty (
248
- sprintf (
249
- 'extra.%s.%s ' ,
250
- self ::EXTRA_BASE ,
251
- self ::EXTRA_APPLIED_CHANGES
252
- ),
253
- $ currentValue
227
+ $ this ->configSource ->addConfigSetting (
228
+ 'preferred-install. ' . $ packageName ,
229
+ 'source '
254
230
);
231
+
232
+ $ this ->addPreferredInstallChanged ($ packageName );
255
233
}
256
234
257
- private function addPreferredInstallChanged (string $ packageName ): void
235
+ /**
236
+ * @return array<string, array<string, string>>
237
+ */
238
+ private function getPatches (): array
258
239
{
259
- $ currentValue = $ this ->getPreferredInstallChanged ();
240
+ $ config = $ this ->configFile -> read ();
260
241
261
- if (in_array ($ packageName , $ currentValue , true )) {
262
- // the package is already listed, skip addition
263
- return ;
242
+ if (
243
+ !is_array ($ config )
244
+ || !is_array ($ config [self ::EXTRA ] ?? null )
245
+ || !is_array ($ config [self ::EXTRA ]['patches ' ] ?? null )
246
+ ) {
247
+ return [];
264
248
}
265
249
266
- $ currentValue [] = $ packageName ;
267
- sort ( $ currentValue );
250
+ return $ config [ self :: EXTRA ][ ' patches ' ] ;
251
+ }
268
252
269
- $ this -> configSource -> addProperty (
270
- sprintf (
271
- ' extra.%s.%s ' ,
272
- self :: EXTRA_BASE ,
273
- self :: EXTRA_PREFERRED_INSTALL_CHANGED
274
- ),
275
- $ currentValue
276
- );
253
+ /**
254
+ * @param array<string, array<string, string>> $patches
255
+ */
256
+ private function removePatchesFromConfigFile ( array $ patches ): void
257
+ {
258
+ foreach ( array_keys ( $ patches ) as $ packageName ) {
259
+ $ this -> configSource -> removeProperty ( sprintf ( ' extra.patches.%s ' , $ packageName ));
260
+ }
277
261
}
278
262
279
- private function removePreferredInstallChanged (string $ packageName ): void
263
+ private function unsetSourceInstall (string $ packageName ): void
280
264
{
281
265
$ currentValue = $ this ->getPreferredInstallChanged ();
282
266
283
267
if (!in_array ($ packageName , $ currentValue , true )) {
268
+ // source was not set by this package, skip removal
269
+ return ;
270
+ }
271
+
272
+ $ this ->configSource ->removeConfigSetting (
273
+ 'preferred-install. ' . $ packageName
274
+ );
275
+
276
+ $ this ->removePreferredInstallChanged ($ packageName );
277
+ }
278
+
279
+ private function removeAppliedChange (int $ numericId ): void
280
+ {
281
+ $ currentValue = $ this ->getAppliedChanges ();
282
+
283
+ if (!in_array ($ numericId , $ currentValue , true )) {
284
284
// the package is not listed, skip removal
285
285
return ;
286
286
}
287
287
288
- $ currentValue = array_filter ($ currentValue , fn ($ value ): bool => $ value !== $ packageName );
288
+ $ currentValue = array_filter ($ currentValue , fn ($ value ): bool => $ value !== $ numericId );
289
289
sort ($ currentValue );
290
290
291
291
$ this ->configSource ->addProperty (
292
292
sprintf (
293
293
'extra.%s.%s ' ,
294
294
self ::EXTRA_BASE ,
295
- self ::EXTRA_PREFERRED_INSTALL_CHANGED
295
+ self ::EXTRA_APPLIED_CHANGES
296
296
),
297
297
$ currentValue
298
298
);
0 commit comments