Issue #3262807 Deprecate module_config_sort()
Merge request reports
Activity
added 1 commit
- Resolved by Dave Long
added 54 commits
-
661fa154...4a02d925 - 52 commits from branch
project:11.x
- 8b51432f - Issue #3262807 by kim.pepper, andypost, Mile23, Spokje, Ratan Priya, quietone,...
- c0508059 - Apply 1 suggestion(s) to 1 file(s)
-
661fa154...4a02d925 - 52 commits from branch
125 125 return $a_weight <=> $b_weight; 126 126 } 127 127 128 /** 129 * Sorts an associative array by numeric value then key. 130 * 131 * @param int[] $array 132 * An associative array containing: 133 * - key: A string. 134 * - value: A numeric value. Recommended to use integer values, floats will 135 * work but are not supported. - Comment on lines +134 to +135
Also, this is confusing. I get that they work with the code but are not intentionally supported, but really, we should pick one or the other and enforce it. Either throw an exception if a float is passed, or formally support them. Edit: Or maybe an exception is too disruptive for code running in a low-level setting like config sorting; maybe it should be a typecast and/or other kind of error instead. Or callers should maybe catch any exception.
Edited by Jess
- Resolved by Andrey Postnikov
125 125 return $a_weight <=> $b_weight; 126 126 } 127 127 128 /** 129 * Sorts an associative array by numeric value then key. 130 * 131 * @param int[] $array 132 * An associative array containing: 133 * - key: A string. 134 * - value: A numeric value. Recommended to use integer values, floats will 135 * work but are not supported. 136 */ 137 public static function sortByNumericValueAndKey(array &$array): void { 138 array_multisort(array_values($array), SORT_ASC, SORT_NUMERIC, array_keys($array), SORT_ASC, SORT_NATURAL, $array); 139 } - Resolved by Andrey Postnikov
- Resolved by Andrey Postnikov
- Resolved by Andrey Postnikov
382 [ 383 'ccc' => -3, 384 'aaa' => -1, 385 'bbb' => -1, 386 ], 387 ]; 388 $tests['non_numeric_weights'] = [ 389 [ 390 'bbb' => '-1', 391 'aaa' => '-2', 392 'ccc' => -3, 393 ], 394 [ 395 'ccc' => -3, 396 'aaa' => '-2', 397 'bbb' => '-1', - Comment on lines +389 to +397
These are good cases to test but they raise another interesting question.
module_config_sort()
typecasts. It's probably very common for config data to be in string format instead ofint
format, so there's at least that behavior change betweenmodule_config_sort()
and the new API, and a behavior change in config sorting is a data integrity issue. Maybe instead of throwing an exception for floats as I suggested above, we should cast the value toint
?
125 125 return $a_weight <=> $b_weight; 126 126 } 127 127 128 /** 129 * Sorts an associative array by numeric value then key. 130 * 131 * @param int[] $array 132 * An associative array containing: 133 * - key: A string. 134 * - value: A numeric value. Recommended to use integer values, floats will 135 * work but are not supported. 136 */ 137 public static function sortByNumericValueAndKey(array &$array): void { - Resolved by Andrey Postnikov
added 779 commits
-
3cdf4c7b...803fa695 - 776 commits from branch
project:11.x
- d124edf7 - Issue #3262807 by kim.pepper, andypost, Mile23, Spokje, Ratan Priya, quietone,...
- 0d1304a7 - Apply 1 suggestion(s) to 1 file(s)
- 46120df7 - Fix wording
Toggle commit list-
3cdf4c7b...803fa695 - 776 commits from branch