@@ -212,44 +212,39 @@ protected function getDefaultFormats()
212
212
private static function mergeFormats (array $ formats , array $ newFormats )
213
213
{
214
214
$ added = array ();
215
+ $ integers = array ('flags ' , 'type ' );
216
+ $ strings = array ('html ' , 'cli ' , 'function ' );
215
217
218
+ /* Sanitize the array so that we do not have to care later */
219
+ foreach ($ newFormats as $ j => $ new ) {
220
+ foreach ($ integers as $ name ) {
221
+ if (! isset ($ new [$ name ])) {
222
+ $ newFormats [$ j ][$ name ] = 0 ;
223
+ }
224
+ }
225
+ foreach ($ strings as $ name ) {
226
+ if (! isset ($ new [$ name ])) {
227
+ $ newFormats [$ j ][$ name ] = '' ;
228
+ }
229
+ }
230
+ }
231
+
232
+ /* Process changes to existing formats */
216
233
foreach ($ formats as $ i => $ original ) {
217
234
foreach ($ newFormats as $ j => $ new ) {
218
- if (isset ($ new ['type ' ])
219
- && $ new ['type ' ] === $ original ['type ' ]
220
- && (
221
- (
222
- isset ($ new ['flags ' ])
223
- && $ original ['flags ' ] === $ new ['flags ' ]
224
- )
225
- || (
226
- !isset ($ new ['flags ' ])
227
- && $ original ['flags ' ] == 0
228
- )
229
- )
235
+ if ($ new ['type ' ] === $ original ['type ' ]
236
+ && $ original ['flags ' ] === $ new ['flags ' ]
230
237
) {
231
- $ formats [$ i ] = array (
232
- 'type ' => $ original ['type ' ],
233
- 'flags ' => isset ($ new ['flags ' ]) ? $ new ['flags ' ] : 0 ,
234
- 'html ' => isset ($ new ['html ' ]) ? $ new ['html ' ] : '' ,
235
- 'cli ' => isset ($ new ['cli ' ]) ? $ new ['cli ' ] : '' ,
236
- 'function ' => isset ($ new ['function ' ]) ? $ new ['function ' ] : '' ,
237
- );
238
-
238
+ $ formats [$ i ] = $ new ;
239
239
$ added [] = $ j ;
240
240
}
241
241
}
242
242
}
243
243
244
+ /* Add not already handled formats */
244
245
foreach ($ newFormats as $ j => $ new ) {
245
- if (!in_array ($ j , $ added ) && isset ($ new ['type ' ])) {
246
- $ formats [] = array (
247
- 'type ' => $ new ['type ' ],
248
- 'flags ' => isset ($ new ['flags ' ]) ? $ new ['flags ' ] : 0 ,
249
- 'html ' => isset ($ new ['html ' ]) ? $ new ['html ' ] : '' ,
250
- 'cli ' => isset ($ new ['cli ' ]) ? $ new ['cli ' ] : '' ,
251
- 'function ' => isset ($ new ['function ' ]) ? $ new ['function ' ] : '' ,
252
- );
246
+ if (! in_array ($ j , $ added )) {
247
+ $ formats [] = $ new ;
253
248
}
254
249
}
255
250
0 commit comments