From 441846cfbdce0b368486f7d782c8ececb52b14c6 Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 13 Mar 2025 11:50:15 +0000 Subject: [PATCH] Fix return type or UserSession::getUserIDForVisitorContactID() --- src/Core/Session/Model/UserSession.php | 4 ++-- src/Object/Post.php | 2 +- tests/src/Core/Session/UserSessionTest.php | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Core/Session/Model/UserSession.php b/src/Core/Session/Model/UserSession.php index cc3db7f806..70370371ff 100644 --- a/src/Core/Session/Model/UserSession.php +++ b/src/Core/Session/Model/UserSession.php @@ -101,7 +101,7 @@ class UserSession implements IHandleUserSessions public function getUserIDForVisitorContactID(int $cid): int { if (empty($this->session->get('remote'))) { - return false; + return 0; } return array_search($cid, $this->session->get('remote')); @@ -142,7 +142,7 @@ class UserSession implements IHandleUserSessions { return !$this->session->get('authenticated', false); } - + /** {@inheritDoc} */ public function setVisitorsContacts(string $my_url) { diff --git a/src/Object/Post.php b/src/Object/Post.php index 4dd5cdea30..7c19a99842 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -71,7 +71,7 @@ class Post $this->setTemplate('wall'); $this->toplevel = $this->getId() == $this->getDataValue('parent'); - if (!empty(DI::userSession()->getUserIDForVisitorContactID($this->getDataValue('contact-id')))) { + if (DI::userSession()->getUserIDForVisitorContactID($this->getDataValue('contact-id')) !== 0) { $this->visiting = true; } diff --git a/tests/src/Core/Session/UserSessionTest.php b/tests/src/Core/Session/UserSessionTest.php index 64c7d8b950..cecae1d90c 100644 --- a/tests/src/Core/Session/UserSessionTest.php +++ b/tests/src/Core/Session/UserSessionTest.php @@ -152,13 +152,13 @@ class UserSessionTest extends MockedTestCase 'data' => [ 'remote' => ['3' => '21'], ], - 'expected' => false, + 'expected' => 0, ], 'empty' => [ 'cid' => 21, 'data' => [ ], - 'expected' => false, + 'expected' => 0, ], ]; } @@ -167,7 +167,7 @@ class UserSessionTest extends MockedTestCase public function testGetUserIdForVisitorContactID(int $cid, array $data, $expected) { $userSession = new UserSession(new ArraySession($data)); - $this->assertEquals($expected, $userSession->getUserIDForVisitorContactID($cid)); + $this->assertSame($expected, $userSession->getUserIDForVisitorContactID($cid)); } public function dataAuthenticated()