Skip to content

Commit

Permalink
Fixing incorrect datatypes and type incompatibilities
Browse files Browse the repository at this point in the history
  • Loading branch information
pH-7 committed Jun 27, 2022
1 parent 4bc0ae7 commit 619ac1b
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 86 deletions.
20 changes: 5 additions & 15 deletions _protected/app/includes/classes/ProfileBaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ abstract public function index(): void;

/**
* Add CSS files for the profile page's design.
*
* @return void
*/
abstract protected function addCssFiles();
abstract protected function addCssFiles(): void;

public function __construct()
{
Expand Down Expand Up @@ -90,27 +88,19 @@ protected function setVisitorId($iVisitorId): void
$this->iVisitorId = (int)$iVisitorId;
}

/**
* @return int
*/
public function getProfileId()
public function getProfileId(): int
{
return $this->iProfileId;
}

/**
* @return int
*/
public function getVisitorId()
public function getVisitorId(): int
{
return $this->iVisitorId;
}

/**
* Privacy Profile.
*
* @param stdClass $oUser
*
* @throws Framework\File\IOException
*/
protected function initPrivacy(stdClass $oUser): void
Expand Down Expand Up @@ -158,7 +148,7 @@ protected function setMenuBar(string $sFirstName, stdClass $oUser): void
/**
* Set the Google Maps code to the view.
*/
protected function setMap(string $sCity, string $sCountry, stdClass $oUser)
protected function setMap(string $sCity, string $sCountry, stdClass $oUser): void
{
$sFullAddress = $sCity . ' ' . t($sCountry);
$sMarkerText = t('Meet <b>%0%</b> near here!', $oUser->username);
Expand Down Expand Up @@ -253,7 +243,7 @@ protected function getMessengerLink($sFirstName, stdClass $oUser): string
*
* @return string The correct anchor "Manage Friend" link.
*/
protected function getFriendLink(string $sFirstName, stdClass $oUser)
protected function getFriendLink(string $sFirstName, stdClass $oUser): string
{
$sCsrfToken = (new Token)->generate('friend');

Expand Down
3 changes: 2 additions & 1 deletion _protected/app/system/core/models/UserCoreModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,8 @@ public function search(array $aParams, $bCount, $iOffset, $iLimit)

$aRow = $rStmt->fetchAll(PDO::FETCH_OBJ);
Db::free($rStmt);
return $aRow;

return (array)$aRow;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct()
$this->setVisitorId($this->session->get('member_id'));
}

public function index()
public function index(): void
{
$this->addCssFiles();
$this->addAdditionalAssetFiles();
Expand Down Expand Up @@ -120,10 +120,8 @@ public function index()

/**
* Add the General and Tabs Menu stylesheets.
*
* @return void
*/
protected function addCssFiles()
protected function addCssFiles(): void
{
$this->design->addCss(
PH7_LAYOUT . PH7_SYS . PH7_MOD . $this->registry->module . PH7_SH . PH7_TPL . PH7_TPL_MOD_NAME . PH7_SH . PH7_CSS,
Expand Down
31 changes: 13 additions & 18 deletions _protected/app/system/modules/mail/controllers/MainController.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function inbox()
self::EMAILS_PER_PAGE
);
$this->view->current_page = $this->oPage->getCurrentPage();
$oMail = $this->oMailModel->search(
$aMail = $this->oMailModel->search(
null,
false,
SearchCoreModel::SEND_DATE,
Expand All @@ -131,13 +131,13 @@ public function inbox()
MailModel::INBOX
);

if (empty($oMail)) {
if (empty($aMail)) {
$this->sTitle = t('No messages in your inbox');
$this->notFound();
// We modify the default error message
$this->view->error = t("You don't have any new messages ☹ Go <a href='%0%'>speak with others</a>!", Uri::get('user', 'browse', 'index'));
} else {
$this->view->msgs = $oMail;
$this->view->msgs = $aMail;
}

$this->manualTplInclude('msglist.inc.tpl');
Expand Down Expand Up @@ -180,7 +180,7 @@ public function outbox()
self::EMAILS_PER_PAGE
);
$this->view->current_page = $this->oPage->getCurrentPage();
$oMail = $this->oMailModel->search(
$aMail = $this->oMailModel->search(
null,
false,
SearchCoreModel::SEND_DATE,
Expand All @@ -191,13 +191,13 @@ public function outbox()
MailModel::OUTBOX
);

if (empty($oMail)) {
if (empty($aMail)) {
$this->sTitle = t('Not Found!');
$this->notFound();
// We modify the default error message
$this->view->error = t('No messages found.');
} else {
$this->view->msgs = $oMail;
$this->view->msgs = $aMail;
}

$this->manualTplInclude('msglist.inc.tpl');
Expand Down Expand Up @@ -242,7 +242,7 @@ public function trash()
self::EMAILS_PER_PAGE
);
$this->view->current_page = $this->oPage->getCurrentPage();
$oMail = $this->oMailModel->search(
$aMail = $this->oMailModel->search(
null,
false,
SearchCoreModel::SEND_DATE,
Expand All @@ -253,13 +253,13 @@ public function trash()
MailModel::TRASH
);

if (empty($oMail)) {
if (empty($aMail)) {
$this->sTitle = t('Not Found!');
$this->notFound();
// We modify the default 404 error message
$this->view->error = t('Trash is empty!');
} else {
$this->view->msgs = $oMail;
$this->view->msgs = $aMail;
}

$this->manualTplInclude('msglist.inc.tpl');
Expand Down Expand Up @@ -298,7 +298,7 @@ public function result()
self::EMAILS_PER_PAGE
);
$this->view->current_page = $this->oPage->getCurrentPage();
$oSearch = $this->oMailModel->search(
$aSearch = $this->oMailModel->search(
$sKeywords,
false,
$sOrder,
Expand All @@ -309,15 +309,15 @@ public function result()
$iType
);

if (empty($oSearch)) {
if (empty($aSearch)) {
$this->sTitle = t("Your search didn't match any of your messages.");
$this->notFound();
} else {
$this->sTitle = t('Messages - Search Results');
$this->view->page_title = $this->sTitle;
$this->view->h2_title = $this->sTitle;
$this->view->h3_title = nt('%n% message found!', '%n% messages found!', $this->iTotalMails);
$this->view->msgs = $oSearch;
$this->view->msgs = $aSearch;
}

$this->manualTplInclude('msglist.inc.tpl');
Expand Down Expand Up @@ -525,12 +525,7 @@ private function getStatusType()
return $this->bStatus ? Design::SUCCESS_TYPE : Design::ERROR_TYPE;
}

/**
* @param stdClass $oMsg
*
* @return void
*/
private function setRead(stdClass $oMsg)
private function setRead(stdClass $oMsg): void
{
if ($oMsg->status == MailModel::UNREAD_STATUS) {
$this->oMailModel->setReadMsg($oMsg->messageId);
Expand Down
8 changes: 2 additions & 6 deletions _protected/app/system/modules/mail/models/MailModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public function setTo($iProfileId, $iMessageId, $sMode)
* @param int|null $iProfileId
* @param int $iType
*
* @return int|stdClass
* @return int|array
*/
public function search($mLooking, $bCount, $sOrderBy, $iSort, $iOffset, $iLimit, $iProfileId = null, $iType = self::ALL)
{
Expand Down Expand Up @@ -287,11 +287,7 @@ public function search($mLooking, $bCount, $sOrderBy, $iSort, $iOffset, $iLimit,

$rStmt->execute();

if (!$bCount) {
$mData = $rStmt->fetchAll(PDO::FETCH_OBJ);
} else {
$mData = (int)$rStmt->fetchColumn();
}
$mData = $bCount ? (int)$rStmt->fetchColumn() : $rStmt->fetchAll(PDO::FETCH_OBJ);

Db::free($rStmt);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PH7\Framework\Mvc\Router\Uri;
use PH7\Framework\Navigation\Page;
use PH7\Framework\Url\Header;
use stdClass;

class BrowseController extends Controller
{
Expand Down Expand Up @@ -41,14 +42,14 @@ public function index(): void
self::MAX_PROFILES_PER_PAGE
);
$this->view->current_page = $this->oPage->getCurrentPage();
$oUsers = $this->oUserModel->search(
$aUsers = $this->oUserModel->search(
$_GET,
false,
$this->oPage->getFirstItem(),
$this->oPage->getNbItemsPerPage()
);

if (empty($oUsers)) {
if (!empty($aUsers) && $this->isSearch()) {
Header::redirect(
Uri::get('user', 'browse', 'index'),
t('No results. Please try again with wider or different search criteria.'),
Expand All @@ -63,8 +64,13 @@ public function index(): void
$this->view->h3_title = t('Meet new People with %0%', '<span class="pH0">' . $this->registry->site_name . '</span>');
$this->view->meta_description = t('Meet new People and Friends near you with %site_name% - Browse Members');
$this->view->avatarDesign = new AvatarDesignCore;
$this->view->users = $oUsers;
$this->view->users = $aUsers;
$this->output();
}
}

private function isSearch(): bool
{
return !empty($_GET) && count($_GET) > 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ class ProfileController extends ProfileBaseController
const MAP_WIDTH_SIZE = '100%';
const MAP_HEIGHT_SIZE = '300px';

/** @var string */
private $sUsername;
private string $sUsername;

public function __construct()
{
Expand All @@ -40,7 +39,7 @@ public function __construct()
$this->setVisitorId($this->session->get('member_id'));
}

public function index()
public function index(): void
{
$this->addCssFiles();
$this->addAdditionalAssetFiles();
Expand Down Expand Up @@ -140,13 +139,7 @@ public function index()
$this->output();
}

/**
* @param string $sFirstName
* @param stdClass $oUser
*
* @return void
*/
protected function setMenuBar($sFirstName, stdClass $oUser)
protected function setMenuBar(string $sFirstName, stdClass $oUser): void
{
parent::setMenuBar($sFirstName, $oUser);

Expand All @@ -161,21 +154,16 @@ protected function setMenuBar($sFirstName, stdClass $oUser)

/**
* Add the General and Tabs Menu stylesheets.
*
* @return void
*/
protected function addCssFiles()
protected function addCssFiles(): void
{
$this->design->addCss(
PH7_LAYOUT,
PH7_TPL . PH7_TPL_NAME . PH7_SH . PH7_CSS . 'tabs.css,' . PH7_SYS . PH7_MOD . $this->registry->module . PH7_SH . PH7_TPL . PH7_TPL_MOD_NAME . PH7_SH . PH7_CSS . 'general.css'
);
}

/**
* @return string
*/
private function getFriendLinkName()
private function getFriendLinkName(): string
{
$iNbFriend = FriendCoreModel::total($this->iProfileId);
$sNbFriend = $iNbFriend > 0 ? ' (' . $iNbFriend . ')' : '';
Expand All @@ -184,10 +172,7 @@ private function getFriendLinkName()
return $sFriendTxt . $sNbFriend;
}

/**
* @return string
*/
private function getMutualFriendLinkName()
private function getMutualFriendLinkName(): string
{
$iNbMutFriend = (new FriendCoreModel)->get(
$this->iVisitorId,
Expand All @@ -205,12 +190,7 @@ private function getMutualFriendLinkName()
return $sMutFriendTxt . $sNbMutFriend;
}

/**
* @param stdClass $oUser
*
* @return bool
*/
private function doesProfileExist(stdClass $oUser)
private function doesProfileExist(stdClass $oUser): bool
{
return !empty($oUser->username) && $this->str->equalsIgnoreCase($this->sUsername, $oUser->username);
}
Expand All @@ -219,17 +199,15 @@ private function doesProfileExist(stdClass $oUser)
/**
* @return bool TRUE if the admin is not logged in (TRUE as well if the admin use "login as user").
*/
private function isNotAdmin()
private function isNotAdmin(): bool
{
return !AdminCore::auth() || UserCore::isAdminLoggedAs();
}

/**
* @return void
*
* @throws Framework\File\IOException
*/
private function redirectToCoolProfileStyle()
private function redirectToCoolProfileStyle(): void
{
Header::redirect(
Uri::get(
Expand All @@ -244,11 +222,9 @@ private function redirectToCoolProfileStyle()
/**
* Show a Not Found page.
*
* @return void
*
* @throws Framework\Http\Exception
*/
private function notFound()
private function notFound(): void
{
Http::setHeadersByCode(StatusCode::NOT_FOUND);

Expand Down
Loading

0 comments on commit 619ac1b

Please sign in to comment.