MDL-70897 various: uasort callback can not return bool
authorMarina Glancy <marina@moodle.com>
Mon, 15 Feb 2021 14:15:35 +0000 (15:15 +0100)
committerRuslan Kabalin <ruslan.kabalin@gmail.com>
Tue, 20 Apr 2021 13:58:25 +0000 (14:58 +0100)
Co-authored-by: Ruslan Kabalin <ruslan.kabalin@gmail.com>
course/classes/local/service/content_item_service.php
message/tests/api_test.php
message/tests/externallib_test.php
message/tests/privacy_provider_test.php
search/classes/manager.php

index 832a7eb..a3cf2f4 100644 (file)
@@ -225,7 +225,7 @@ class content_item_service {
 
         // 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;
@@ -301,7 +301,7 @@ class content_item_service {
 
         // 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;
index 8654efe..3b367fb 100644 (file)
@@ -1327,7 +1327,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
         $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.
index b25174b..087b276 100644 (file)
@@ -2091,7 +2091,7 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
         $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']);
@@ -2187,7 +2187,7 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
         $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']);
@@ -3538,7 +3538,7 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
      * @return bool
      */
     protected static function sort_contacts($a, $b) {
-        return $a['userid'] > $b['userid'];
+        return $a['userid'] <=> $b['userid'];
     }
 
     /**
@@ -3549,7 +3549,7 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
      * @return bool
      */
     protected static function sort_contacts_id($a, $b) {
-        return $a['id'] > $b['id'];
+        return $a['id'] <=> $b['id'];
     }
 
     /**
@@ -4422,7 +4422,7 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
         $conversations = $result['conversations'];
 
         usort($conversations, function($first, $second){
-            return $first['id'] > $second['id'];
+            return $first['id'] <=> $second['id'];
         });
 
         $selfconversation = array_shift($conversations);
index 245049f..380a7c7 100644 (file)
@@ -2904,7 +2904,7 @@ class core_message_privacy_provider_testcase extends \core_privacy\tests\provide
      * @return  bool
      */
     protected static function sort_messages($a, $b) {
-        return $a->message > $b->message;
+        return strcmp($a->message, $b->message);
     }
 
     /**
@@ -2915,7 +2915,8 @@ class core_message_privacy_provider_testcase extends \core_privacy\tests\provide
      * @return  bool
      */
     protected static function sort_contacts($a, $b) {
-        return $a->contact > $b->contact;
+        // Contact attribute contains user id.
+        return $a->contact <=> $b->contact;
     }
 
     /**
index c0a1c5f..70f81f0 100644 (file)
@@ -480,7 +480,7 @@ class manager {
 
             // 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;