Skip to content

Commit 16f7c52

Browse files
committed
Pass PHPStan on level 6
1 parent 9cd1eca commit 16f7c52

File tree

50 files changed

+298
-253
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+298
-253
lines changed

files/lib/action/ConversationLabelFormAction.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
7474
}
7575

7676
$data = $form->getData()['data'];
77-
$deleteLabel = $label && $data['deleteLabel'] ?? false;
77+
$deleteLabel = $label && ($data['deleteLabel'] ?? false);
7878
unset($data['deleteLabel']);
7979

8080
if ($deleteLabel) {

files/lib/data/conversation/Conversation.class.php

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,9 @@ public function canReply(): bool
141141
/**
142142
* Overrides the last message data, used when `leftAt < lastPostTime`.
143143
*
144-
* @param int $userID
145-
* @param string $username
146-
* @param int $time
144+
* @return void
147145
*/
148-
public function setLastMessage($userID, $username, $time)
146+
public function setLastMessage(?int $userID, string $username, int $time)
149147
{
150148
$this->data['lastPostTime'] = $time;
151149
$this->data['lastPosterID'] = $userID;
@@ -156,9 +154,9 @@ public function setLastMessage($userID, $username, $time)
156154
* Loads participation data for given user id (default: current user) on runtime.
157155
* You should use Conversation::getUserConversation() instead if possible.
158156
*
159-
* @param int $userID
157+
* @return void
160158
*/
161-
public function loadUserParticipation($userID = null)
159+
public function loadUserParticipation(?int $userID = null)
162160
{
163161
if ($userID === null) {
164162
$userID = WCF::getUser()->userID;
@@ -179,11 +177,9 @@ public function loadUserParticipation($userID = null)
179177
/**
180178
* Returns a specific user conversation.
181179
*
182-
* @param int $conversationID
183-
* @param int $userID
184-
* @return null|Conversation
180+
* @return ?Conversation
185181
*/
186-
public static function getUserConversation($conversationID, $userID)
182+
public static function getUserConversation(int $conversationID, int $userID)
187183
{
188184
$sql = "SELECT conversation_to_user.*, conversation.*
189185
FROM wcf1_conversation conversation
@@ -205,10 +201,9 @@ public static function getUserConversation($conversationID, $userID)
205201
* Returns a list of user conversations.
206202
*
207203
* @param int[] $conversationIDs
208-
* @param int $userID
209-
* @return Conversation[]
204+
* @return Conversation[]
210205
*/
211-
public static function getUserConversations(array $conversationIDs, $userID)
206+
public static function getUserConversations(array $conversationIDs, int $userID)
212207
{
213208
$conditionBuilder = new PreparedStatementConditionBuilder();
214209
$conditionBuilder->add('conversation.conversationID IN (?)', [$conversationIDs]);
@@ -316,10 +311,9 @@ public function getFirstMessage(): ?ConversationMessage
316311
/**
317312
* Returns a list of the ids of all participants.
318313
*
319-
* @param bool $excludeLeftParticipants
320-
* @return int[]
314+
* @return int[]
321315
*/
322-
public function getParticipantIDs($excludeLeftParticipants = false)
316+
public function getParticipantIDs(bool $excludeLeftParticipants = false)
323317
{
324318
$conditions = new PreparedStatementConditionBuilder();
325319
$conditions->add("conversationID = ?", [$this->conversationID]);
@@ -340,11 +334,9 @@ public function getParticipantIDs($excludeLeftParticipants = false)
340334
/**
341335
* Returns a list of the usernames of all participants.
342336
*
343-
* @param bool $excludeSelf
344-
* @param bool $leftByOwnChoice
345-
* @return string[]
337+
* @return string[]
346338
*/
347-
public function getParticipantNames($excludeSelf = false, $leftByOwnChoice = false, bool $isAuthor = false)
339+
public function getParticipantNames(bool $excludeSelf = false, bool $leftByOwnChoice = false, bool $isAuthor = false)
348340
{
349341
$conditions = new PreparedStatementConditionBuilder();
350342
$conditions->add("conversationID = ?", [$this->conversationID]);
@@ -422,9 +414,8 @@ public function getPopoverLinkClass(): string
422414
* of all given conversation ids.
423415
*
424416
* @param int[] $conversationIDs
425-
* @param int $userID
426417
*/
427-
public static function isParticipant(array $conversationIDs, $userID = null): bool
418+
public static function isParticipant(array $conversationIDs, ?int $userID = null): bool
428419
{
429420
if ($userID === null) {
430421
$userID = WCF::getUser()->userID;
@@ -473,15 +464,14 @@ public static function isParticipant(array $conversationIDs, $userID = null): bo
473464
/**
474465
* Validates the participants.
475466
*
476-
* @param mixed $participants
477-
* @param string $field
467+
* @param string[]|string $participants
478468
* @param int[] $existingParticipants
479-
* @return array $result
480-
* @throws UserInputException
469+
* @return list<int>
470+
* @throws UserInputException
481471
*/
482472
public static function validateParticipants(
483-
$participants,
484-
$field = 'participants',
473+
array|string $participants,
474+
string $field = 'participants',
485475
array $existingParticipants = []
486476
) {
487477
$result = [];
@@ -534,14 +524,13 @@ public static function validateParticipants(
534524
/**
535525
* Validates the group participants.
536526
*
537-
* @param mixed $participants
538-
* @param string $field
527+
* @param string[]|string $participants
539528
* @param int[] $existingParticipants
540-
* @return array $result
529+
* @return list<int>
541530
*/
542531
public static function validateGroupParticipants(
543-
$participants,
544-
$field = 'participants',
532+
array|string $participants,
533+
string $field = 'participants',
545534
array $existingParticipants = []
546535
) {
547536
$groupIDs = \is_array($participants) ? $participants : ArrayUtil::toIntegerArray(\explode(',', $participants));
@@ -550,7 +539,7 @@ public static function validateGroupParticipants(
550539

551540
foreach ($groupIDs as $groupID) {
552541
$group = UserGroup::getGroupByID($groupID);
553-
/** @noinspection PhpUndefinedFieldInspection */
542+
// @phpstan-ignore property.notFound
554543
if ($group !== null && $group->canBeAddedAsConversationParticipant) {
555544
$validGroupIDs[] = $groupID;
556545
}
@@ -599,11 +588,10 @@ public static function validateGroupParticipants(
599588
/**
600589
* Validates the given participant.
601590
*
602-
* @param UserProfile $user
603-
* @param string $field
604-
* @throws UserInputException
591+
* @return void
592+
* @throws UserInputException
605593
*/
606-
public static function validateParticipant(UserProfile $user, $field = 'participants')
594+
public static function validateParticipant(UserProfile $user, string $field = 'participants')
607595
{
608596
// check participant's settings and permissions
609597
if (!$user->getPermission('user.conversation.canUseConversation')) {

0 commit comments

Comments
 (0)