Skip to content

Commit

Permalink
Add various explicit return types
Browse files Browse the repository at this point in the history
  • Loading branch information
TimWolla committed Feb 1, 2023
1 parent 6e82777 commit beb426f
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 67 deletions.
42 changes: 12 additions & 30 deletions files/lib/data/conversation/Conversation.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ class Conversation extends DatabaseObject implements IPopoverObject, IRouteContr
/**
* @inheritDoc
*/
public function getTitle()
public function getTitle(): string
{
return $this->subject;
}

/**
* @inheritDoc
*/
public function getLink()
public function getLink(): string
{
return LinkHandler::getInstance()->getLink('Conversation', [
'object' => $this,
Expand All @@ -109,10 +109,8 @@ public function getLink()

/**
* Returns true if this conversation is new for the active user.
*
* @return bool
*/
public function isNew()
public function isNew(): bool
{
if (!$this->isDraft && $this->lastPostTime > $this->lastVisitTime) {
return true;
Expand All @@ -123,11 +121,8 @@ public function isNew()

/**
* Returns true if the active user doesn't have read the given message.
*
* @param ConversationMessage $message
* @return bool
*/
public function isNewMessage(ConversationMessage $message)
public function isNewMessage(ConversationMessage $message): bool
{
if (!$this->isDraft && $message->time > $this->lastVisitTime) {
return true;
Expand All @@ -138,10 +133,8 @@ public function isNewMessage(ConversationMessage $message)

/**
* Returns true if the conversation is not closed or the user was not removed.
*
* @return bool
*/
public function canReply()
public function canReply(): bool
{
if (!$this->canRead()) {
return false;
Expand Down Expand Up @@ -242,10 +235,8 @@ public static function getUserConversations(array $conversationIDs, $userID)

/**
* Returns true if the active user has the permission to read this conversation.
*
* @return bool
*/
public function canRead()
public function canRead(): bool
{
if (!WCF::getUser()->userID) {
return false;
Expand All @@ -264,10 +255,8 @@ public function canRead()

/**
* Returns true if the current user can add new participants to this conversation.
*
* @return bool
*/
public function canAddParticipants()
public function canAddParticipants(): bool
{
if ($this->isDraft) {
return false;
Expand Down Expand Up @@ -298,10 +287,8 @@ public function canAddParticipants()

/**
* Returns true if the current user can add participants without limitations.
*
* @return bool
*/
public function canAddParticipantsUnrestricted()
public function canAddParticipantsUnrestricted(): bool
{
if ($this->canAddUnrestricted === null) {
$this->canAddUnrestricted = false;
Expand Down Expand Up @@ -405,10 +392,8 @@ public function getParticipantNames($excludeSelf = false, $leftByOwnChoice = fal

/**
* Returns false if the active user is the last participant of this conversation.
*
* @return bool
*/
public function hasOtherParticipants()
public function hasOtherParticipants(): bool
{
if ($this->userID == WCF::getUser()->userID) {
// author
Expand Down Expand Up @@ -447,10 +432,8 @@ public function hasOtherParticipants()

/**
* Returns true if the current user is an active participant of this conversation.
*
* @return bool
*/
public function isActiveParticipant()
public function isActiveParticipant(): bool
{
if ($this->isActiveParticipant === null) {
$sql = "SELECT leftAt
Expand All @@ -473,7 +456,7 @@ public function isActiveParticipant()
/**
* @inheritDoc
*/
public function getPopoverLinkClass()
public function getPopoverLinkClass(): string
{
return 'conversationLink';
}
Expand All @@ -484,9 +467,8 @@ public function getPopoverLinkClass()
*
* @param int[] $conversationIDs
* @param int $userID
* @return bool
*/
public static function isParticipant(array $conversationIDs, $userID = null)
public static function isParticipant(array $conversationIDs, $userID = null): bool
{
if ($userID === null) {
$userID = WCF::getUser()->userID;
Expand Down
14 changes: 7 additions & 7 deletions files/lib/data/conversation/FeedConversation.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class FeedConversation extends DatabaseObjectDecorator implements IFeedEntry
/**
* @inheritDoc
*/
public function getLink()
public function getLink(): string
{
return LinkHandler::getInstance()->getLink('Conversation', [
'object' => $this->getDecoratedObject(),
Expand All @@ -37,31 +37,31 @@ public function getLink()
/**
* @inheritDoc
*/
public function getTitle()
public function getTitle(): string
{
return $this->getDecoratedObject()->getTitle();
}

/**
* @inheritDoc
*/
public function getFormattedMessage()
public function getFormattedMessage(): string
{
return '';
}

/**
* @inheritDoc
*/
public function getMessage()
public function getMessage(): string
{
return '';
}

/**
* @inheritDoc
*/
public function getExcerpt($maxLength = 255)
public function getExcerpt($maxLength = 255): string
{
return '';
}
Expand All @@ -77,7 +77,7 @@ public function getUserID()
/**
* @inheritDoc
*/
public function getUsername()
public function getUsername(): string
{
return $this->getDecoratedObject()->lastPoster;
}
Expand All @@ -93,7 +93,7 @@ public function getTime()
/**
* @inheritDoc
*/
public function __toString()
public function __toString(): string
{
return $this->getFormattedMessage();
}
Expand Down
25 changes: 10 additions & 15 deletions files/lib/data/conversation/message/ConversationMessage.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ConversationMessage extends DatabaseObject implements IMessage
/**
* @inheritDoc
*/
public function getFormattedMessage()
public function getFormattedMessage(): string
{
$processor = new HtmlOutputProcessor();
$processor->process($this->message, 'com.woltlab.wcf.conversation.message', $this->messageID);
Expand All @@ -55,10 +55,8 @@ public function getFormattedMessage()

/**
* Returns a simplified version of the formatted message.
*
* @return string
*/
public function getSimplifiedFormattedMessage()
public function getSimplifiedFormattedMessage(): string
{
$processor = new HtmlOutputProcessor();
$processor->setOutputType('text/simplified-html');
Expand Down Expand Up @@ -97,7 +95,7 @@ public function getAttachments($ignoreCache = false)
/**
* @inheritDoc
*/
public function getExcerpt($maxLength = 255)
public function getExcerpt($maxLength = 255): string
{
return StringUtil::truncateHTML($this->getSimplifiedFormattedMessage(), $maxLength);
}
Expand All @@ -106,9 +104,8 @@ public function getExcerpt($maxLength = 255)
* Returns a version of this message optimized for use in emails.
*
* @param string $mimeType Either 'text/plain' or 'text/html'
* @return string
*/
public function getMailText($mimeType = 'text/plain')
public function getMailText($mimeType = 'text/plain'): string
{
switch ($mimeType) {
case 'text/plain':
Expand Down Expand Up @@ -152,10 +149,8 @@ public function setConversation(Conversation $conversation)

/**
* Returns true if current user may edit this message.
*
* @return bool
*/
public function canEdit()
public function canEdit(): bool
{
return WCF::getUser()->userID == $this->userID
&& (
Expand All @@ -168,15 +163,15 @@ public function canEdit()
/**
* @inheritDoc
*/
public function getMessage()
public function getMessage(): string
{
return $this->message;
}

/**
* @inheritDoc
*/
public function getLink()
public function getLink(): string
{
return LinkHandler::getInstance()->getLink('Conversation', [
'object' => $this->getConversation(),
Expand All @@ -188,7 +183,7 @@ public function getLink()
/**
* @inheritDoc
*/
public function getTitle()
public function getTitle(): string
{
if ($this->messageID == $this->getConversation()->firstMessageID) {
return $this->getConversation()->subject;
Expand All @@ -200,15 +195,15 @@ public function getTitle()
/**
* @inheritDoc
*/
public function isVisible()
public function isVisible(): bool
{
return true;
}

/**
* @inheritDoc
*/
public function __toString()
public function __toString(): string
{
return $this->getFormattedMessage();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ConversationMessageUserNotificationEvent extends AbstractUserNotificationE
/**
* @inheritDoc
*/
public function getTitle()
public function getTitle(): string
{
$count = \count($this->getAuthors());
if ($count > 1) {
Expand All @@ -45,7 +45,7 @@ public function getTitle()
/**
* @inheritDoc
*/
public function getMessage()
public function getMessage(): string
{
$authors = \array_values($this->getAuthors());
$count = \count($authors);
Expand Down Expand Up @@ -93,7 +93,7 @@ public function getEmailMessage($notificationType = 'instant')
* @inheritDoc
* @since 5.2
*/
public function getEmailTitle()
public function getEmailTitle(): string
{
if (\count($this->getAuthors()) > 1) {
return parent::getEmailTitle();
Expand All @@ -109,23 +109,23 @@ public function getEmailTitle()
/**
* @inheritDoc
*/
public function getLink()
public function getLink(): string
{
return $this->getUserNotificationObject()->getLink();
}

/**
* @inheritDoc
*/
public function getEventHash()
public function getEventHash(): string
{
return \sha1($this->eventID . '-' . $this->getUserNotificationObject()->conversationID);
}

/**
* @inheritDoc
*/
public function checkAccess()
public function checkAccess(): bool
{
return $this->getUserNotificationObject()->getConversation()->canRead();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ class ConversationUserNotificationEvent extends AbstractUserNotificationEvent im
/**
* @inheritDoc
*/
public function getTitle()
public function getTitle(): string
{
return $this->getLanguage()->get('wcf.user.notification.conversation.title');
}

/**
* @inheritDoc
*/
public function getMessage()
public function getMessage(): string
{
return $this->getLanguage()->getDynamicVariable('wcf.user.notification.conversation.message', [
'author' => $this->author,
Expand Down Expand Up @@ -58,7 +58,7 @@ public function getEmailMessage($notificationType = 'instant')
* @inheritDoc
* @since 5.2
*/
public function getEmailTitle()
public function getEmailTitle(): string
{
return $this->getLanguage()->getDynamicVariable('wcf.user.notification.conversation.mail.title', [
'author' => $this->author,
Expand All @@ -69,15 +69,15 @@ public function getEmailTitle()
/**
* @inheritDoc
*/
public function getLink()
public function getLink(): string
{
return $this->getUserNotificationObject()->getLink();
}

/**
* @inheritDoc
*/
public function checkAccess()
public function checkAccess(): bool
{
return $this->getUserNotificationObject()->canRead();
}
Expand Down

0 comments on commit beb426f

Please sign in to comment.