Skip to content
Snippets Groups Projects

Issue #3262807 Deprecate module_config_sort()

4 unresolved threads

Issue #3262807 by kim.pepper, andypost, Mile23, Spokje, Ratan Priya, quietone, NivethaSubramaniyan, smustgrave, catch, voleger, larowlan, alexpott: Deprecate module_config_sort()

Closes #3262807

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Dave Long resolved all threads

    resolved all threads

  • Dave Long added 1 commit

    added 1 commit

    • 661fa154 - Apply 1 suggestion(s) to 1 file(s)

    Compare with previous version

  • Kim Pepper added 54 commits

    added 54 commits

    Compare with previous version

  • Jess
    Jess @xjm started a thread on the diff
  • 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
      Maintainer
      Suggested change
      134 * - value: A numeric value. Recommended to use integer values, floats will
      135 * work but are not supported.
      134 * - value: A numeric value. Integer values are recommended. Floats will
      135 * work but are not supported.

      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
    • Please register or sign in to reply
  • Jess
  • Jess
    Jess @xjm started a thread on the diff
  • 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 }
    • Comment on lines +137 to +139
      Maintainer

      module_config_sort() has all sorts of logic about the maximum PHP integer weight and positive versus negative weights. What's happening to all that with this change? Why is it no longer needed?

    • Please register or sign in to reply
  • Jess
  • Jess
  • Jess
  • Jess
    Jess @xjm started a thread on the diff
  • 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
      Maintainer

      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 of int format, so there's at least that behavior change between module_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 to int?

    • Please register or sign in to reply
  • Jess
    Jess @xjm started a thread on the diff
  • 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 {
    • Maintainer

      So "numeric" in PHP includes numeric strings. However, per the test cases, numeric strings currently behave differently than their integer counterparts. I think we should either make the method handle numeric strings, or rename it.

    • Please register or sign in to reply
  • Jess
  • added 1 commit

    Compare with previous version

  • Andrey Postnikov added 779 commits

    added 779 commits

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • Please register or sign in to reply
    Loading