Improve sorting based on a second array with Arr::sort() - #790
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the array sorting logic in Arr::sort() and improves PHPDoc type annotations for sorting methods across the codebase. The changes replace the complex array_multisort() implementation with a more explicit approach that includes better error handling and validation.
- Refactored
Arr::sort()to use explicit sorting logic with early returns for different$sortByscenarios - Added validation to ensure
$sortByarray matches the target array in count and keys - Updated PHPDoc annotations to use more precise union types for sorting constants
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| formwork/src/Utils/Arr.php | Refactored sorting logic to replace array_multisort() with explicit handling of different $sortBy scenarios; added validation for array count and key matching; updated PHPDoc with precise type annotations |
| formwork/src/Data/AbstractCollection.php | Updated PHPDoc annotations for sort() and sortBy() methods with precise union types for sorting constants |
Comments suppressed due to low confidence (1)
formwork/src/Utils/Arr.php:1
- The parameter order in the PHPDoc doesn't match the actual function signature. In the PHPDoc,
$sortByis listed before$caseSensitive(lines 643-644), but in the function signature (lines 655-661), the order is$direction,$type,$sortBy,$caseSensitive,$preserveKeys. The PHPDoc should list parameters in the same order as the function signature for clarity.
<?php
馃挕 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
giuscris
force-pushed
the
improve-arr-sort
branch
from
November 18, 2025 22:07
bb33960 to
8f55eca
Compare
giuscris
marked this pull request as ready for review
November 18, 2025 22:10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request improves the type annotations and logic for sorting methods in the codebase, with a focus on clarifying parameters and enhancing array sorting behavior. The main updates include more precise PHPDoc types for sorting options, better handling of the
$sortByparameter, and improved error checking in the array sorting utility.Type annotation improvements:
AbstractCollection.phpandArr.phpto specify accepted types for sorting parameters such as$direction,$type, and$sortBy, making the documentation clearer and more accurate. [1] [2] [3]Array sorting logic enhancements:
Arr::sort()to handle the$sortByparameter more robustly, including:$sortByand the array to sort have mismatched counts.$sortByis not present in the array.$preserveKeysflag.