Skip to content

Commit

Permalink
MDL-70897 various: uasort callback can not return bool
Browse files Browse the repository at this point in the history
Co-authored-by: Ruslan Kabalin <ruslan.kabalin@gmail.com>
  • Loading branch information
marinaglancy and kabalin committed Apr 20, 2021
1 parent 0fd37bf commit 881b425
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions course/classes/local/service/content_item_service.php
Expand Up @@ -225,7 +225,7 @@ private function export_content_items(\stdClass $user, $contentitems) {

// Sort by title for return.
usort($exported->content_items, function($a, $b) {
return $a->title > $b->title;
return strcmp($a->title, $b->title);
});

return $exported->content_items;
Expand Down Expand Up @@ -301,7 +301,7 @@ public function get_content_items_for_user_in_course(\stdClass $user, \stdClass

// Sort by title for return.
usort($exported->content_items, function($a, $b) {
return $a->title > $b->title;
return strcmp($a->title, $b->title);
});

return $exported->content_items;
Expand Down
2 changes: 1 addition & 1 deletion message/tests/api_test.php
Expand Up @@ -1327,7 +1327,7 @@ public function test_get_conversations_some_muted() {
$conversations = \core_message\api::get_conversations($user1->id);

usort($conversations, function($first, $second){
return $first->id > $second->id;
return $first->id <=> $second->id;
});

// Consider first conversations is self-conversation.
Expand Down
10 changes: 5 additions & 5 deletions message/tests/externallib_test.php
Expand Up @@ -2091,7 +2091,7 @@ public function test_message_search_users_messagingallusers_disabled() {
$this->assertCount(2, $contacts[0]['conversations']);
// We can't rely on the ordering of conversations within the results, so sort by id first.
usort($contacts[0]['conversations'], function($a, $b) {
return $a['id'] < $b['id'];
return $b['id'] <=> $a['id'];
});
$this->assertEquals(\core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP, $contacts[0]['conversations'][0]['type']);
$this->assertEquals(\core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL, $contacts[0]['conversations'][1]['type']);
Expand Down Expand Up @@ -2187,7 +2187,7 @@ public function test_message_search_users_messagingallusers_enabled() {
$this->assertCount(2, $contacts[0]['conversations']);
// We can't rely on the ordering of conversations within the results, so sort by id first.
usort($contacts[0]['conversations'], function($a, $b) {
return $a['id'] < $b['id'];
return $b['id'] <=> $a['id'];
});
$this->assertEquals(\core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP, $contacts[0]['conversations'][0]['type']);
$this->assertEquals(\core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL, $contacts[0]['conversations'][1]['type']);
Expand Down Expand Up @@ -3538,7 +3538,7 @@ public function test_get_user_message_preferences_permissions() {
* @return bool
*/
protected static function sort_contacts($a, $b) {
return $a['userid'] > $b['userid'];
return $a['userid'] <=> $b['userid'];
}

/**
Expand All @@ -3549,7 +3549,7 @@ protected static function sort_contacts($a, $b) {
* @return bool
*/
protected static function sort_contacts_id($a, $b) {
return $a['id'] > $b['id'];
return $a['id'] <=> $b['id'];
}

/**
Expand Down Expand Up @@ -4422,7 +4422,7 @@ public function test_get_conversations_some_muted() {
$conversations = $result['conversations'];

usort($conversations, function($first, $second){
return $first['id'] > $second['id'];
return $first['id'] <=> $second['id'];
});

$selfconversation = array_shift($conversations);
Expand Down
5 changes: 3 additions & 2 deletions message/tests/privacy_provider_test.php
Expand Up @@ -2904,7 +2904,7 @@ private function create_notification(int $useridfrom, int $useridto, int $timecr
* @return bool
*/
protected static function sort_messages($a, $b) {
return $a->message > $b->message;
return strcmp($a->message, $b->message);
}

/**
Expand All @@ -2915,7 +2915,8 @@ protected static function sort_messages($a, $b) {
* @return bool
*/
protected static function sort_contacts($a, $b) {
return $a->contact > $b->contact;
// Contact attribute contains user id.
return $a->contact <=> $b->contact;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion search/classes/manager.php
Expand Up @@ -480,7 +480,7 @@ public static function get_search_area_categories() {

// Sort categories by order.
uasort($categories, function($category1, $category2) {
return $category1->get_order() > $category2->get_order();
return $category1->get_order() <=> $category2->get_order();
});

static::$searchareacategories = $categories;
Expand Down

0 comments on commit 881b425

Please sign in to comment.