Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/codestyle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches:
- master
pull_request:

permissions:
contents: read
Expand Down
17 changes: 14 additions & 3 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php
$finder = PhpCsFixer\Finder::create()
->exclude('*/vendor/*')
->in(__DIR__.'/files/');
->in(__DIR__ . '/files/');

return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@PER-CS2.0' => true,
'single_line_empty_body' => false,
'@PSR1' => true,
'@PSR2' => true,

'array_push' => true,
'backtick_to_shell_exec' => true,
Expand All @@ -25,18 +25,23 @@

'non_printable_character' => ['use_escape_sequences_in_strings' => true],

'lowercase_static_reference' => true,
'magic_constant_casing' => true,
'magic_method_casing' => true,
'native_function_casing' => true,
'native_function_type_declaration_casing' => true,

'cast_spaces' => ['space' => 'none'],
'lowercase_cast' => true,
'no_unset_cast' => true,
'short_scalar_cast' => true,

'class_attributes_separation' => true,
'no_blank_lines_after_class_opening' => true,
'no_null_property_initialization' => true,
'self_accessor' => true,
'single_class_element_per_statement' => true,
'single_trait_insert_per_statement' => true,

'no_empty_comment' => true,
'single_line_comment_style' => ['comment_types' => ['hash']],
Expand All @@ -55,12 +60,15 @@
'native_function_invocation' => ['include' => ['@internal']],
'no_unreachable_default_argument_value' => true,
'nullable_type_declaration_for_default_null_value' => true,
'return_type_declaration' => true,
'static_lambda' => true,

'fully_qualified_strict_types' => ['leading_backslash_in_global_namespace' => true],
'no_leading_import_slash' => true,
'no_unused_imports' => true,
'ordered_imports' => true,

'declare_equal_normalize' => true,
'dir_constant' => true,
'explicit_indirect_variable' => true,
'function_to_constant' => true,
Expand All @@ -71,6 +79,7 @@

'clean_namespace' => true,
'no_leading_namespace_whitespace' => true,
'single_blank_line_before_namespace' => true,

'no_homoglyph_names' => true,

Expand All @@ -82,6 +91,7 @@
'operator_linebreak' => true,
'standardize_increment' => true,
'standardize_not_equals' => true,
'ternary_operator_spaces' => true,
'ternary_to_elvis_operator' => true,
'ternary_to_null_coalescing' => true,
'unary_operator_spaces' => true,
Expand All @@ -102,6 +112,7 @@

'array_indentation' => true,
'blank_line_before_statement' => ['statements' => ['return', 'exit']],
'compact_nullable_typehint' => true,
'method_chaining_indentation' => true,
'no_extra_blank_lines' => ['tokens' => ['case', 'continue', 'curly_brace_block', 'default', 'extra', 'parenthesis_brace_block', 'square_brace_block', 'switch', 'throw', 'use']],
'no_spaces_around_offset' => true,
Expand Down
4 changes: 3 additions & 1 deletion .phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
<arg value="p"/>
<arg name="basepath" value="."/>

<rule ref="PSR12"/>
<rule ref="PSR12">
<exclude name="PSR1.Classes.ClassDeclaration.MultipleClasses"/>
</rule>
</ruleset>
8 changes: 8 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "woltlab/com.woltlab.wcf.conversation",
"type": "project",
"require-dev": {
"phpstan/phpstan": "^2.1"
},
"require": {}
}
77 changes: 77 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion files/lib/action/ConversationLabelFormAction.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
}

$data = $form->getData()['data'];
$deleteLabel = $label && $data['deleteLabel'] ?? false;
$deleteLabel = $label && ($data['deleteLabel'] ?? false);
unset($data['deleteLabel']);

if ($deleteLabel) {
Expand Down
64 changes: 26 additions & 38 deletions files/lib/data/conversation/Conversation.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,9 @@ public function canReply(): bool
/**
* Overrides the last message data, used when `leftAt < lastPostTime`.
*
* @param int $userID
* @param string $username
* @param int $time
* @return void
*/
public function setLastMessage($userID, $username, $time)
public function setLastMessage(?int $userID, string $username, int $time)
{
$this->data['lastPostTime'] = $time;
$this->data['lastPosterID'] = $userID;
Expand All @@ -156,9 +154,9 @@ public function setLastMessage($userID, $username, $time)
* Loads participation data for given user id (default: current user) on runtime.
* You should use Conversation::getUserConversation() instead if possible.
*
* @param int $userID
* @return void
*/
public function loadUserParticipation($userID = null)
public function loadUserParticipation(?int $userID = null)
{
if ($userID === null) {
$userID = WCF::getUser()->userID;
Expand All @@ -179,11 +177,9 @@ public function loadUserParticipation($userID = null)
/**
* Returns a specific user conversation.
*
* @param int $conversationID
* @param int $userID
* @return null|Conversation
* @return ?Conversation
*/
public static function getUserConversation($conversationID, $userID)
public static function getUserConversation(int $conversationID, int $userID)
{
$sql = "SELECT conversation_to_user.*, conversation.*
FROM wcf1_conversation conversation
Expand All @@ -205,10 +201,9 @@ public static function getUserConversation($conversationID, $userID)
* Returns a list of user conversations.
*
* @param int[] $conversationIDs
* @param int $userID
* @return Conversation[]
* @return Conversation[]
*/
public static function getUserConversations(array $conversationIDs, $userID)
public static function getUserConversations(array $conversationIDs, int $userID)
{
$conditionBuilder = new PreparedStatementConditionBuilder();
$conditionBuilder->add('conversation.conversationID IN (?)', [$conversationIDs]);
Expand Down Expand Up @@ -316,10 +311,9 @@ public function getFirstMessage(): ?ConversationMessage
/**
* Returns a list of the ids of all participants.
*
* @param bool $excludeLeftParticipants
* @return int[]
* @return int[]
*/
public function getParticipantIDs($excludeLeftParticipants = false)
public function getParticipantIDs(bool $excludeLeftParticipants = false)
{
$conditions = new PreparedStatementConditionBuilder();
$conditions->add("conversationID = ?", [$this->conversationID]);
Expand All @@ -340,11 +334,9 @@ public function getParticipantIDs($excludeLeftParticipants = false)
/**
* Returns a list of the usernames of all participants.
*
* @param bool $excludeSelf
* @param bool $leftByOwnChoice
* @return string[]
* @return string[]
*/
public function getParticipantNames($excludeSelf = false, $leftByOwnChoice = false, bool $isAuthor = false)
public function getParticipantNames(bool $excludeSelf = false, bool $leftByOwnChoice = false, bool $isAuthor = false)
{
$conditions = new PreparedStatementConditionBuilder();
$conditions->add("conversationID = ?", [$this->conversationID]);
Expand Down Expand Up @@ -422,9 +414,8 @@ public function getPopoverLinkClass(): string
* of all given conversation ids.
*
* @param int[] $conversationIDs
* @param int $userID
*/
public static function isParticipant(array $conversationIDs, $userID = null): bool
public static function isParticipant(array $conversationIDs, ?int $userID = null): bool
{
if ($userID === null) {
$userID = WCF::getUser()->userID;
Expand Down Expand Up @@ -473,15 +464,14 @@ public static function isParticipant(array $conversationIDs, $userID = null): bo
/**
* Validates the participants.
*
* @param mixed $participants
* @param string $field
* @param string[]|string $participants
* @param int[] $existingParticipants
* @return array $result
* @throws UserInputException
* @return list<int>
* @throws UserInputException
*/
public static function validateParticipants(
$participants,
$field = 'participants',
array|string $participants,
string $field = 'participants',
array $existingParticipants = []
) {
$result = [];
Expand Down Expand Up @@ -534,14 +524,13 @@ public static function validateParticipants(
/**
* Validates the group participants.
*
* @param mixed $participants
* @param string $field
* @param string[]|string $participants
* @param int[] $existingParticipants
* @return array $result
* @return list<int>
*/
public static function validateGroupParticipants(
$participants,
$field = 'participants',
array|string $participants,
string $field = 'participants',
array $existingParticipants = []
) {
$groupIDs = \is_array($participants) ? $participants : ArrayUtil::toIntegerArray(\explode(',', $participants));
Expand All @@ -550,7 +539,7 @@ public static function validateGroupParticipants(

foreach ($groupIDs as $groupID) {
$group = UserGroup::getGroupByID($groupID);
/** @noinspection PhpUndefinedFieldInspection */
// @phpstan-ignore property.notFound
if ($group !== null && $group->canBeAddedAsConversationParticipant) {
$validGroupIDs[] = $groupID;
}
Expand Down Expand Up @@ -599,11 +588,10 @@ public static function validateGroupParticipants(
/**
* Validates the given participant.
*
* @param UserProfile $user
* @param string $field
* @throws UserInputException
* @return void
* @throws UserInputException
*/
public static function validateParticipant(UserProfile $user, $field = 'participants')
public static function validateParticipant(UserProfile $user, string $field = 'participants')
{
// check participant's settings and permissions
if (!$user->getPermission('user.conversation.canUseConversation')) {
Expand Down
Loading