Fix ContactEndpoint & tests
authorPhilipp <admin@philipp.info>
Sat, 12 Sep 2020 08:01:13 +0000 (10:01 +0200)
committerPhilipp <admin@philipp.info>
Sat, 12 Sep 2020 08:01:13 +0000 (10:01 +0200)
src/Module/Api/Twitter/ContactEndpoint.php
src/Object/Api/Twitter/User.php
tests/src/Module/Api/Twitter/ContactEndpointTest.php

index f341019..58807e6 100644 (file)
@@ -73,7 +73,7 @@ abstract class ContactEndpoint extends BaseApi
                                throw new HTTPException\NotFoundException(DI::l10n()->t('User not found'));
                        }
 
-                       $uid = $user['uid'];
+                       $uid = (int)$user['uid'];
                }
 
                return $uid;
@@ -111,7 +111,7 @@ abstract class ContactEndpoint extends BaseApi
                        'next_cursor_str' => $return['next_cursor_str'],
                        'previous_cursor' => $return['previous_cursor'],
                        'previous_cursor_str' => $return['previous_cursor_str'],
-                       'total_count' => $return['total_count'],
+                       'total_count' => (int)$return['total_count'],
                ];
 
                return $return;
@@ -153,7 +153,7 @@ abstract class ContactEndpoint extends BaseApi
                                'pending' => false
                        ];
 
-                       $total_count = DBA::count('contact', $condition);
+                       $total_count = (int)DBA::count('contact', $condition);
 
                        if ($cursor !== -1) {
                                if ($cursor > 0) {
@@ -171,7 +171,7 @@ abstract class ContactEndpoint extends BaseApi
                        // Cursor is on the user-specific contact id since it's the sort field
                        if (count($ids)) {
                                $previous_cursor = -$ids[0];
-                               $next_cursor = $ids[count($ids) -1];
+                               $next_cursor = (int)$ids[count($ids) -1];
                        }
 
                        // No next page
index c646b49..1cdd699 100644 (file)
@@ -89,7 +89,7 @@ class User extends BaseEntity
         */
        public function __construct(array $publicContact, array $apcontact = [], array $userContact = [], $skip_status = false, $include_user_entities = true)
        {
-               $this->id                      = $publicContact['id'];
+               $this->id                      = (int)$publicContact['id'];
                $this->id_str                  = (string) $publicContact['id'];
                $this->name                    = $publicContact['name'];
                $this->screen_name             = $publicContact['nick'] ?: $publicContact['name'];
@@ -143,10 +143,10 @@ class User extends BaseEntity
                $this->notifications                  = false;
 
                // Friendica-specific
-               $this->uid                   = $userContact['uid'] ?? 0;
-               $this->cid                   = $userContact['id'] ?? 0;
-               $this->pid                   = $publicContact['id'];
-               $this->self                  = $userContact['self'] ?? false;
+               $this->uid                   = (int)$userContact['uid'] ?? 0;
+               $this->cid                   = (int)$userContact['id'] ?? 0;
+               $this->pid                   = (int)$publicContact['id'];
+               $this->self                  = (boolean)$userContact['self'] ?? false;
                $this->network               = $publicContact['network'];
                $this->statusnet_profile_url = $publicContact['url'];
        }
index cb8ec57..e23b836 100644 (file)
@@ -234,7 +234,7 @@ class ContactEndpointTest extends FixtureTest
                        'uid' => 42,
                        'cid' => 44,
                        'pid' => 45,
-                       'self' => 0,
+                       'self' => false,
                        'network' => 'dfrn',
                        'statusnet_profile_url' => 'http://localhost/profile/friendcontact',
                ];