Skip to content

Commit

Permalink
correct named parameters on sort functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubmisek committed Aug 5, 2024
1 parent edc6317 commit 0ce3e25
Showing 1 changed file with 41 additions and 41 deletions.
82 changes: 41 additions & 41 deletions src/Peachpie.Library/Arrays.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1162,18 +1162,18 @@ public static PhpArray range(Context ctx, PhpValue low, PhpValue high, PhpValue
/// </summary>
/// <param name="ctx">Current runtime context.</param>
/// <param name="array">The array to be sorted.</param>
/// <param name="comparisonMethod">The method to be used for comparison of values.</param>
/// <param name="flags">The method to be used for comparison of values.</param>
/// <remarks>Resets <paramref name="array"/>'s intrinsic enumerator.</remarks>
/// <returns>True on success, False on failure.</returns>
public static bool sort(Context ctx, [In, Out, PhpRw] PhpArray array, ComparisonMethod comparisonMethod = ComparisonMethod.Regular)
public static bool sort(Context ctx, [In, Out, PhpRw] PhpArray array, ComparisonMethod flags = ComparisonMethod.Regular)
{
if (array == null)
{
PhpException.ArgumentNull(nameof(array));
return false;
}

array.Sort(GetComparer(ctx, comparisonMethod, SortingOrder.Ascending, false));
array.Sort(GetComparer(ctx, flags, SortingOrder.Ascending, false));
array.ReindexAll();
array.RestartIntrinsicEnumerator();

Expand All @@ -1185,18 +1185,18 @@ public static bool sort(Context ctx, [In, Out, PhpRw] PhpArray array, Comparison
/// </summary>
/// <param name="ctx">Current runtime context.</param>
/// <param name="array">The array to be sorted.</param>
/// <param name="comparisonMethod">The method to be used for comparison of values.</param>
/// <param name="flags">The method to be used for comparison of values.</param>
/// <remarks>Resets <paramref name="array"/>'s intrinsic enumerator.</remarks>
/// <returns>True on success, False on failure.</returns>
public static bool asort(Context ctx, [In, Out, PhpRw] PhpArray array, ComparisonMethod comparisonMethod = ComparisonMethod.Regular)
public static bool asort(Context ctx, [In, Out, PhpRw] PhpArray array, ComparisonMethod flags = ComparisonMethod.Regular)
{
if (array == null)
{
PhpException.ArgumentNull(nameof(array));
return false;
}

array.Sort(GetComparer(ctx, comparisonMethod, SortingOrder.Ascending, false));
array.Sort(GetComparer(ctx, flags, SortingOrder.Ascending, false));
array.RestartIntrinsicEnumerator();

return true;
Expand All @@ -1207,18 +1207,18 @@ public static bool asort(Context ctx, [In, Out, PhpRw] PhpArray array, Compariso
/// </summary>
/// <param name="ctx">Current runtime context.</param>
/// <param name="array">The array to be sorted.</param>
/// <param name="comparisonMethod">The method to be used for comparison of keys.</param>
/// <param name="flags">The method to be used for comparison of keys.</param>
/// <remarks>Resets <paramref name="array"/>'s intrinsic enumerator.</remarks>
/// <returns>True on success, False on failure.</returns>
public static bool ksort(Context ctx, [In, Out, PhpRw] PhpArray array, ComparisonMethod comparisonMethod = ComparisonMethod.Regular)
public static bool ksort(Context ctx, [In, Out, PhpRw] PhpArray array, ComparisonMethod flags = ComparisonMethod.Regular)
{
if (array == null)
{
PhpException.ArgumentNull(nameof(array));
return false;
}

array.Sort(GetComparer(ctx, comparisonMethod, SortingOrder.Ascending, true));
array.Sort(GetComparer(ctx, flags, SortingOrder.Ascending, true));
array.RestartIntrinsicEnumerator();

return true;
Expand All @@ -1229,18 +1229,18 @@ public static bool ksort(Context ctx, [In, Out, PhpRw] PhpArray array, Compariso
/// </summary>
/// <param name="ctx">Current runtime context.</param>
/// <param name="array">The array to be sorted.</param>
/// <param name="comparisonMethod">The method to be used for comparison of keys.</param>
/// <param name="flags">The method to be used for comparison of keys.</param>
/// <remarks>Resets <paramref name="array"/>'s intrinsic enumerator.</remarks>
/// <returns>True on success, False on failure.</returns>
public static bool rsort(Context ctx, [In, Out, PhpRw] PhpArray array, ComparisonMethod comparisonMethod = ComparisonMethod.Regular)
public static bool rsort(Context ctx, [In, Out, PhpRw] PhpArray array, ComparisonMethod flags = ComparisonMethod.Regular)
{
if (array == null)
{
PhpException.ArgumentNull(nameof(array));
return false;
}

array.Sort(GetComparer(ctx, comparisonMethod, SortingOrder.Descending, false));
array.Sort(GetComparer(ctx, flags, SortingOrder.Descending, false));
array.ReindexAll();
array.RestartIntrinsicEnumerator();

Expand All @@ -1253,18 +1253,18 @@ public static bool rsort(Context ctx, [In, Out, PhpRw] PhpArray array, Compariso
/// </summary>
/// <param name="ctx">Current runtime context.</param>
/// <param name="array">The array to be sorted.</param>
/// <param name="comparisonMethod">The method to be used for comparison of values.</param>
/// <param name="flags">The method to be used for comparison of values.</param>
/// <remarks>Resets <paramref name="array"/>'s intrinsic enumerator.</remarks>
/// <returns>True on success, False on failure.</returns>
public static bool arsort(Context ctx, [In, Out, PhpRw] PhpArray array, ComparisonMethod comparisonMethod = ComparisonMethod.Regular)
public static bool arsort(Context ctx, [In, Out, PhpRw] PhpArray array, ComparisonMethod flags = ComparisonMethod.Regular)
{
if (array == null)
{
PhpException.ArgumentNull(nameof(array));
return false;
}

array.Sort(GetComparer(ctx, comparisonMethod, SortingOrder.Descending, false));
array.Sort(GetComparer(ctx, flags, SortingOrder.Descending, false));
array.RestartIntrinsicEnumerator();

return true;
Expand All @@ -1275,18 +1275,18 @@ public static bool arsort(Context ctx, [In, Out, PhpRw] PhpArray array, Comparis
/// </summary>
/// <param name="ctx">Current runtime context.</param>
/// <param name="array">The array to be sorted.</param>
/// <param name="comparisonMethod">The method to be used for comparison of keys.</param>
/// <param name="flags">The method to be used for comparison of keys.</param>
/// <remarks>Resets <paramref name="array"/>'s intrinsic enumerator.</remarks>
/// <returns>True on success, False on failure.</returns>
public static bool krsort(Context ctx, [In, Out, PhpRw] PhpArray array, ComparisonMethod comparisonMethod = ComparisonMethod.Regular)
public static bool krsort(Context ctx, [In, Out, PhpRw] PhpArray array, ComparisonMethod flags = ComparisonMethod.Regular)
{
if (array == null)
{
PhpException.ArgumentNull(nameof(array));
return false;
}

array.Sort(GetComparer(ctx, comparisonMethod, SortingOrder.Descending, true));
array.Sort(GetComparer(ctx, flags, SortingOrder.Descending, true));
array.RestartIntrinsicEnumerator();

return true;
Expand All @@ -1301,20 +1301,20 @@ public static bool krsort(Context ctx, [In, Out, PhpRw] PhpArray array, Comparis
/// </summary>
/// <param name="ctx">Current runtime context.</param>
/// <param name="array">The array to be sorted.</param>
/// <param name="compare">The user callback to be used for comparison of values.</param>
/// <param name="callback">The user callback to be used for comparison of values.</param>
/// <remarks>Resets <paramref name="array"/>'s intrinsic enumerator.</remarks>
/// <returns>True on success, False on failure.</returns>
public static bool usort(Context ctx /*, caller*/, [In, Out, PhpRw] PhpArray array, IPhpCallable compare)
public static bool usort(Context ctx /*, caller*/, [In, Out, PhpRw] PhpArray array, IPhpCallable callback)
{
if (array == null)
{
PhpException.ArgumentNull(nameof(array));
return false;
}
if (!PhpVariable.IsValidCallback(compare)) return false;
if (!PhpVariable.IsValidCallback(callback)) return false;

// sorts array using callback for comparisons:
array.Sort(new ValueComparer(new PhpUserComparer(ctx, compare), false));
array.Sort(new ValueComparer(new PhpUserComparer(ctx, callback), false));

array.ReindexAll();
array.RestartIntrinsicEnumerator();
Expand All @@ -1327,20 +1327,20 @@ public static bool usort(Context ctx /*, caller*/, [In, Out, PhpRw] PhpArray arr
/// </summary>
/// <param name="ctx">Current runtime context.</param>
/// <param name="array">The array to be sorted.</param>
/// <param name="compare">The user callback to be used for comparison of values.</param>
/// <param name="callback">The user callback to be used for comparison of values.</param>
/// <remarks>Resets <paramref name="array"/>'s intrinsic enumerator.</remarks>
/// <returns>True on success, False on failure.</returns>
public static bool uasort(Context ctx /*, caller*/, [In, Out, PhpRw] PhpArray array, IPhpCallable compare)
public static bool uasort(Context ctx /*, caller*/, [In, Out, PhpRw] PhpArray array, IPhpCallable callback)
{
if (array == null)
{
PhpException.ArgumentNull(nameof(array));
return false;
}
if (!PhpVariable.IsValidCallback(compare)) return false;
if (!PhpVariable.IsValidCallback(callback)) return false;

// sorts array using callback for comparisons:
array.Sort(new ValueComparer(new PhpUserComparer(ctx, compare), false));
array.Sort(new ValueComparer(new PhpUserComparer(ctx, callback), false));

return true;
}
Expand All @@ -1350,19 +1350,19 @@ public static bool uasort(Context ctx /*, caller*/, [In, Out, PhpRw] PhpArray ar
/// </summary>
/// <param name="ctx">Current runtime context.</param>
/// <param name="array">The array to be sorted.</param>
/// <param name="compare">The user callback to be used for comparison of values.</param>
/// <param name="callback">The user callback to be used for comparison of values.</param>
/// <remarks>Resets <paramref name="array"/>'s intrinsic enumerator.</remarks>
/// <returns>True on success, False on failure.</returns>
public static bool uksort(Context ctx /*, caller*/, [In, Out, PhpRw] PhpArray array, IPhpCallable compare)
public static bool uksort(Context ctx /*, caller*/, [In, Out, PhpRw] PhpArray array, IPhpCallable callback)
{
if (array == null)
{
PhpException.ArgumentNull(nameof(array));
return false;
}
if (!PhpVariable.IsValidCallback(compare)) return false;
if (!PhpVariable.IsValidCallback(callback)) return false;

array.Sort(new KeyComparer(new PhpUserComparer(ctx, compare), false));
array.Sort(new KeyComparer(new PhpUserComparer(ctx, callback), false));

return true;
}
Expand Down Expand Up @@ -1535,29 +1535,29 @@ private static int MultiSortResolveArgs(
/// Sort multiple arrays.
/// </summary>
/// <param name="ctx">Current runtime context.</param>
/// <param name="first">The first array to be sorted.</param>
/// <param name="array1">The first array to be sorted.</param>
/// <param name="args">Arrays to be sorted along with flags affecting sort order and
/// comparison methods to be used. See PHP manual for more details.</param>
/// <returns>Whether arrays were sorted successfully.</returns>
/// <remarks>Reindexes integer keys in the sorted arrays and restarts their intrinsic enumerators.</remarks>
/// <exception cref="PhpException"><paramref name="first"/> is a <B>null</B> reference (Warning).</exception>
/// <exception cref="PhpException"><paramref name="array1"/> is a <B>null</B> reference (Warning).</exception>
/// <exception cref="PhpException">Arrays has different lengths (Warning).</exception>
/// <exception cref="PhpException">Invalid sorting flags (Warning).</exception>
/// <exception cref="PhpException">Multiple sorting flags applied on single array (Warning).</exception>
public static bool array_multisort(Context ctx, [In, Out, PhpRw] PhpArray first, params PhpValue[] args)
public static bool array_multisort(Context ctx, [In, Out, PhpRw] PhpArray array1, params PhpValue[] args)
{
// some "args" are also [PhpRw] but which ones is compile time unknown
// but it is not neccessary to mark them since this attribute has no important effect

if (first == null)
if (array1 == null)
{
PhpException.ArgumentNull(nameof(first));
PhpException.ArgumentNull(nameof(array1));
return false;
}

IComparer<KeyValuePair<IntStringKey, PhpValue>>[] comparers;
PhpArray[] arrays;
int length = MultiSortResolveArgs(ctx, first, args, null, null);
int length = MultiSortResolveArgs(ctx, array1, args, null, null);

if (length == 0)
{
Expand All @@ -1566,16 +1566,16 @@ public static bool array_multisort(Context ctx, [In, Out, PhpRw] PhpArray first,
if (length == 1)
{
comparers = new IComparer<KeyValuePair<IntStringKey, PhpValue>>[1];
MultiSortResolveArgs(ctx, first, args, null, comparers);
first.Sort(comparers[0]);
first.ReindexIntegers(0);
first.RestartIntrinsicEnumerator();
MultiSortResolveArgs(ctx, array1, args, null, comparers);
array1.Sort(comparers[0]);
array1.ReindexIntegers(0);
array1.RestartIntrinsicEnumerator();
return true;
}

arrays = new PhpArray[length];
comparers = new IComparer<KeyValuePair<IntStringKey, PhpValue>>[length];
MultiSortResolveArgs(ctx, first, args, arrays, comparers);
MultiSortResolveArgs(ctx, array1, args, arrays, comparers);
PhpHashtable.Sort(arrays, comparers); // + reindex + restart intrinsic

return true;
Expand Down

0 comments on commit 0ce3e25

Please sign in to comment.