From e0f1906f8df9600504d39570ecabf289e3ba2529 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 1 Feb 2024 15:21:14 +0100 Subject: [PATCH 1/2] fix(CS): Prepare coding standard update Signed-off-by: Joas Schilling --- lib/Activity/Provider/Call.php | 2 +- lib/Activity/Provider/Invitation.php | 2 +- lib/Chat/SystemMessage/Listener.php | 2 +- .../Resources/ConversationProvider.php | 2 +- lib/Controller/ChatController.php | 4 +-- lib/Controller/RoomController.php | 9 +++--- lib/Flow/Operation.php | 4 +-- lib/Manager.php | 2 +- lib/Middleware/InjectionMiddleware.php | 2 +- .../Version13000Date20210625232111.php | 4 +-- .../Version18000Date20231024141626.php | 2 +- lib/Service/BreakoutRoomService.php | 28 +++++++++---------- lib/Service/RecordingService.php | 4 +-- lib/Service/RoomService.php | 10 +++---- lib/Share/RoomShareProvider.php | 2 +- tests/php/Recording/BackendNotifierTest.php | 2 +- tests/php/bootstrap.php | 2 +- 17 files changed, 41 insertions(+), 42 deletions(-) diff --git a/lib/Activity/Provider/Call.php b/lib/Activity/Provider/Call.php index a850f594803..59e5006f7a7 100644 --- a/lib/Activity/Provider/Call.php +++ b/lib/Activity/Provider/Call.php @@ -35,7 +35,7 @@ class Call extends Base { * @throws \InvalidArgumentException * @since 11.0.0 */ - public function parse($language, IEvent $event, IEvent $previousEvent = null): IEvent { + public function parse($language, IEvent $event, ?IEvent $previousEvent = null): IEvent { $event = $this->preParse($event); if ($event->getSubject() === 'call') { diff --git a/lib/Activity/Provider/Invitation.php b/lib/Activity/Provider/Invitation.php index bf870c73415..bd75646cade 100644 --- a/lib/Activity/Provider/Invitation.php +++ b/lib/Activity/Provider/Invitation.php @@ -35,7 +35,7 @@ class Invitation extends Base { * @throws \InvalidArgumentException * @since 11.0.0 */ - public function parse($language, IEvent $event, IEvent $previousEvent = null): IEvent { + public function parse($language, IEvent $event, ?IEvent $previousEvent = null): IEvent { $event = $this->preParse($event); if ($event->getSubject() === 'invitation') { diff --git a/lib/Chat/SystemMessage/Listener.php b/lib/Chat/SystemMessage/Listener.php index 8bc0a07ff2a..52513ba74ed 100644 --- a/lib/Chat/SystemMessage/Listener.php +++ b/lib/Chat/SystemMessage/Listener.php @@ -426,7 +426,7 @@ protected function attendeesRemovedEvent(AttendeesRemovedEvent $event): void { } } - protected function sendSystemMessage(Room $room, string $message, array $parameters = [], Participant $participant = null, bool $shouldSkipLastMessageUpdate = false, bool $silent = false, bool $forceSystemAsActor = false): IComment { + protected function sendSystemMessage(Room $room, string $message, array $parameters = [], ?Participant $participant = null, bool $shouldSkipLastMessageUpdate = false, bool $silent = false, bool $forceSystemAsActor = false): IComment { if ($participant instanceof Participant) { $actorType = $participant->getAttendee()->getActorType(); $actorId = $participant->getAttendee()->getActorId(); diff --git a/lib/Collaboration/Resources/ConversationProvider.php b/lib/Collaboration/Resources/ConversationProvider.php index 89022c2ea59..72d08be8323 100644 --- a/lib/Collaboration/Resources/ConversationProvider.php +++ b/lib/Collaboration/Resources/ConversationProvider.php @@ -75,7 +75,7 @@ public function getResourceRichObject(IResource $resource): array { } } - public function canAccessResource(IResource $resource, IUser $user = null): bool { + public function canAccessResource(IResource $resource, ?IUser $user = null): bool { $userId = $user instanceof IUser ? $user->getUID() : null; if ($userId === null) { throw new ResourceException('Guests are not supported at the moment'); diff --git a/lib/Controller/ChatController.php b/lib/Controller/ChatController.php index f62d76f64f4..829b8778e2f 100644 --- a/lib/Controller/ChatController.php +++ b/lib/Controller/ChatController.php @@ -103,7 +103,7 @@ public function __construct( private ParticipantService $participantService, private SessionService $sessionService, protected AttachmentService $attachmentService, - protected avatarService $avatarService, + protected AvatarService $avatarService, protected ReminderService $reminderService, private GuestManager $guestManager, private MessageParser $messageParser, @@ -150,7 +150,7 @@ protected function getActorInfo(string $actorDisplayName = ''): array { /** * @return DataResponse */ - protected function parseCommentToResponse(IComment $comment, Message $parentMessage = null): DataResponse { + protected function parseCommentToResponse(IComment $comment, ?Message $parentMessage = null): DataResponse { $chatMessage = $this->messageParser->createMessage($this->room, $this->participant, $comment, $this->l); $this->messageParser->parseMessage($chatMessage); diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php index e29e2ed5b72..6f5818275d3 100644 --- a/lib/Controller/RoomController.php +++ b/lib/Controller/RoomController.php @@ -28,7 +28,6 @@ namespace OCA\Talk\Controller; -use InvalidArgumentException; use OCA\Talk\Config; use OCA\Talk\Events\AAttendeeRemovedEvent; use OCA\Talk\Events\BeforeRoomsFetchEvent; @@ -282,7 +281,7 @@ public function getListedRooms(string $searchTerm = ''): DataResponse { public function getBreakoutRooms(): DataResponse { try { $rooms = $this->breakoutRoomService->getBreakoutRooms($this->room, $this->participant); - } catch (InvalidArgumentException $e) { + } catch (\InvalidArgumentException $e) { return new DataResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST); } @@ -534,7 +533,7 @@ protected function createOneToOneRoom(string $targetUserId): DataResponse { $this->formatRoom($room, $this->participantService->getParticipant($room, $currentUser->getUID(), false)), Http::STATUS_CREATED ); - } catch (InvalidArgumentException $e) { + } catch (\InvalidArgumentException $e) { // Same current and target user return new DataResponse([], Http::STATUS_FORBIDDEN); } catch (RoomNotFoundException $e) { @@ -642,7 +641,7 @@ protected function createEmptyRoom(string $roomName, bool $public = true, string // Create the room try { $room = $this->roomService->createConversation($roomType, $roomName, $currentUser, $objectType, $objectId); - } catch (InvalidArgumentException $e) { + } catch (\InvalidArgumentException $e) { return new DataResponse([], Http::STATUS_BAD_REQUEST); } @@ -852,7 +851,7 @@ public function getBreakoutRoomParticipants(bool $includeStatus = false): DataRe try { $breakoutRooms = $this->breakoutRoomService->getBreakoutRooms($this->room, $this->participant); - } catch (InvalidArgumentException $e) { + } catch (\InvalidArgumentException $e) { return new DataResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST); } diff --git a/lib/Flow/Operation.php b/lib/Flow/Operation.php index cd368080305..caf0753a6ce 100644 --- a/lib/Flow/Operation.php +++ b/lib/Flow/Operation.php @@ -88,7 +88,7 @@ public function isAvailableForScope(int $scope): bool { * @since 9.1 */ public function validateOperation(string $name, array $checks, string $operation): void { - list($mode, $token) = $this->parseOperationConfig($operation); + [$mode, $token] = $this->parseOperationConfig($operation); $this->validateOperationConfig($mode, $token, $this->getUser()->getUID()); } @@ -96,7 +96,7 @@ public function onEvent(string $eventName, Event $event, IRuleMatcher $ruleMatch $flows = $ruleMatcher->getFlows(false); foreach ($flows as $flow) { try { - list($mode, $token) = $this->parseOperationConfig($flow['operation']); + [$mode, $token] = $this->parseOperationConfig($flow['operation']); $uid = $flow['scope_actor_id']; $this->validateOperationConfig($mode, $token, $uid); diff --git a/lib/Manager.php b/lib/Manager.php index e8adc5f6ba9..581f8fcca53 100644 --- a/lib/Manager.php +++ b/lib/Manager.php @@ -273,7 +273,7 @@ public function resetAssignedSignalingServers(ICache $cache): void { * @param int|null $offset * @return Room[] */ - public function searchRoomsByToken(string $searchToken = '', int $limit = null, int $offset = null): array { + public function searchRoomsByToken(string $searchToken = '', ?int $limit = null, ?int $offset = null): array { $query = $this->db->getQueryBuilder(); $helper = new SelectHelper(); $helper->selectRoomsTable($query); diff --git a/lib/Middleware/InjectionMiddleware.php b/lib/Middleware/InjectionMiddleware.php index df5b27688fd..66b04e12332 100644 --- a/lib/Middleware/InjectionMiddleware.php +++ b/lib/Middleware/InjectionMiddleware.php @@ -309,7 +309,7 @@ public function afterException(Controller $controller, string $methodName, \Exce $protection = $attribute->newInstance(); $action = $protection->getAction(); - if ('talkRoomToken' === $action) { + if ($action === 'talkRoomToken') { try { $this->throttler->sleepDelayOrThrowOnMax($this->request->getRemoteAddress(), $action); } catch (MaxDelayReached $e) { diff --git a/lib/Migration/Version13000Date20210625232111.php b/lib/Migration/Version13000Date20210625232111.php index c630d70294c..83d863a874e 100644 --- a/lib/Migration/Version13000Date20210625232111.php +++ b/lib/Migration/Version13000Date20210625232111.php @@ -68,8 +68,8 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt ]); } - /** Removed in {@see \OCA\Talk\Migration\Version18000Date20231024141626} */ - /** Recreated in {@see \OCA\Talk\Migration\Version18000Date20231024141627} */ + /** Removed in {@see Version18000Date20231024141626} */ + /** Recreated in {@see Version18000Date20231024141627} */ // if (!$schema->hasTable('talk_invitations')) { // $table = $schema->createTable('talk_invitations'); // $table->addColumn('id', Types::BIGINT, [ diff --git a/lib/Migration/Version18000Date20231024141626.php b/lib/Migration/Version18000Date20231024141626.php index a9a7325b713..0992dffa6a9 100644 --- a/lib/Migration/Version18000Date20231024141626.php +++ b/lib/Migration/Version18000Date20231024141626.php @@ -43,7 +43,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt $schema = $schemaClosure(); if ($schema->hasTable('talk_invitations')) { - /** Recreated in {@see \OCA\Talk\Migration\Version18000Date20231024141627} */ + /** Recreated in {@see Version18000Date20231024141627} */ $schema->dropTable('talk_invitations'); return $schema; } diff --git a/lib/Service/BreakoutRoomService.php b/lib/Service/BreakoutRoomService.php index c4765459d2d..238b6120313 100644 --- a/lib/Service/BreakoutRoomService.php +++ b/lib/Service/BreakoutRoomService.php @@ -229,7 +229,7 @@ public function applyAttendeeMap(Room $parent, string $attendeeMap): array { if ($attendee->getActorType() === Attendee::ACTOR_USERS && in_array($attendee->getActorId(), $userIds, true)) { if ($participant->hasModeratorPermissions()) { // Can not remove moderators with this method - throw new \InvalidArgumentException('moderator'); + throw new InvalidArgumentException('moderator'); } $removals[] = [ @@ -357,7 +357,7 @@ protected function deleteBreakoutRooms(Room $parent): void { */ public function broadcastChatMessage(Room $parent, Participant $participant, string $message): array { if ($parent->getBreakoutRoomMode() === BreakoutRoom::MODE_NOT_CONFIGURED) { - throw new \InvalidArgumentException('mode'); + throw new InvalidArgumentException('mode'); } $breakoutRooms = $this->manager->getMultipleRoomsByObject(BreakoutRoom::PARENT_OBJECT_TYPE, $parent->getToken()); @@ -391,18 +391,18 @@ public function resetRequestForAssistance(Room $breakoutRoom): void { protected function setAssistanceRequest(Room $breakoutRoom, int $status): void { if ($breakoutRoom->getObjectType() !== BreakoutRoom::PARENT_OBJECT_TYPE) { - throw new \InvalidArgumentException('room'); + throw new InvalidArgumentException('room'); } if ($breakoutRoom->getLobbyState() !== Webinary::LOBBY_NONE) { - throw new \InvalidArgumentException('room'); + throw new InvalidArgumentException('room'); } if (!in_array($status, [ BreakoutRoom::STATUS_ASSISTANCE_RESET, BreakoutRoom::STATUS_ASSISTANCE_REQUESTED, ], true)) { - throw new \InvalidArgumentException('status'); + throw new InvalidArgumentException('status'); } $this->roomService->setBreakoutRoomStatus($breakoutRoom, $status); @@ -415,7 +415,7 @@ protected function setAssistanceRequest(Room $breakoutRoom, int $status): void { */ public function startBreakoutRooms(Room $parent): array { if ($parent->getBreakoutRoomMode() === BreakoutRoom::MODE_NOT_CONFIGURED) { - throw new \InvalidArgumentException('mode'); + throw new InvalidArgumentException('mode'); } $breakoutRooms = $this->manager->getMultipleRoomsByObject(BreakoutRoom::PARENT_OBJECT_TYPE, $parent->getToken(), true); @@ -434,7 +434,7 @@ public function startBreakoutRooms(Room $parent): array { */ public function stopBreakoutRooms(Room $parent): array { if ($parent->getBreakoutRoomMode() === BreakoutRoom::MODE_NOT_CONFIGURED) { - throw new \InvalidArgumentException('mode'); + throw new InvalidArgumentException('mode'); } $this->roomService->setBreakoutRoomStatus($parent, BreakoutRoom::STATUS_STOPPED); @@ -453,16 +453,16 @@ public function stopBreakoutRooms(Room $parent): array { public function switchBreakoutRoom(Room $parent, Participant $participant, string $targetToken): Room { if ($parent->getBreakoutRoomMode() !== BreakoutRoom::MODE_FREE) { - throw new \InvalidArgumentException('mode'); + throw new InvalidArgumentException('mode'); } if ($parent->getBreakoutRoomStatus() !== BreakoutRoom::STATUS_STARTED) { - throw new \InvalidArgumentException('status'); + throw new InvalidArgumentException('status'); } if ($participant->hasModeratorPermissions()) { // Moderators don't switch, they are part of all breakout rooms - throw new \InvalidArgumentException('moderator'); + throw new InvalidArgumentException('moderator'); } $attendee = $participant->getAttendee(); @@ -478,7 +478,7 @@ public function switchBreakoutRoom(Room $parent, Participant $participant, strin } if ($target === null) { - throw new \InvalidArgumentException('target'); + throw new InvalidArgumentException('target'); } foreach ($breakoutRooms as $breakoutRoom) { @@ -525,11 +525,11 @@ public function switchBreakoutRoom(Room $parent, Participant $participant, strin */ public function getBreakoutRooms(Room $parent, Participant $participant): array { if ($parent->getBreakoutRoomMode() === BreakoutRoom::MODE_NOT_CONFIGURED) { - throw new \InvalidArgumentException('mode'); + throw new InvalidArgumentException('mode'); } if (!$participant->hasModeratorPermissions() && $parent->getBreakoutRoomStatus() !== BreakoutRoom::STATUS_STARTED) { - throw new \InvalidArgumentException('status'); + throw new InvalidArgumentException('status'); } $breakoutRooms = $this->manager->getMultipleRoomsByObject(BreakoutRoom::PARENT_OBJECT_TYPE, $parent->getToken(), true); @@ -574,7 +574,7 @@ public function removeAttendeeFromBreakoutRoom(Room $parent, string $actorType, ); if ($throwOnModerator && $participant->hasModeratorPermissions()) { - throw new \InvalidArgumentException('moderator'); + throw new InvalidArgumentException('moderator'); } $this->participantService->removeAttendee($breakoutRoom, $participant, AAttendeeRemovedEvent::REASON_REMOVED); diff --git a/lib/Service/RecordingService.php b/lib/Service/RecordingService.php index 999514cc9a1..dd6f528589a 100644 --- a/lib/Service/RecordingService.php +++ b/lib/Service/RecordingService.php @@ -287,7 +287,7 @@ private function getRecordingFolder(string $owner, string $token): Folder { $userFolder = $this->rootFolder->getUserFolder($owner); $recordingRootFolderName = $this->config->getRecordingFolder($owner); try { - /** @var \OCP\Files\Folder */ + /** @var Folder */ $recordingRootFolder = $userFolder->get($recordingRootFolderName); if ($recordingRootFolder->isShared()) { $this->logger->error('Talk attachment folder for user {userId} is set to a shared folder. Resetting to their root.', [ @@ -297,7 +297,7 @@ private function getRecordingFolder(string $owner, string $token): Folder { $this->serverConfig->setUserValue($owner, 'spreed', 'attachment_folder', '/'); } } catch (NotFoundException $e) { - /** @var \OCP\Files\Folder */ + /** @var Folder */ $recordingRootFolder = $userFolder->newFolder($recordingRootFolderName); } try { diff --git a/lib/Service/RoomService.php b/lib/Service/RoomService.php index cadffa2b86c..1173d359aa0 100644 --- a/lib/Service/RoomService.php +++ b/lib/Service/RoomService.php @@ -280,7 +280,7 @@ public function setSIPEnabled(Room $room, int $newSipEnabled): bool { /** * @psalm-param RecordingService::CONSENT_REQUIRED_* $recordingConsent - * @throws \InvalidArgumentException When the room has an active call or the value is invalid + * @throws InvalidArgumentException When the room has an active call or the value is invalid */ public function setRecordingConsent(Room $room, int $recordingConsent, bool $allowUpdatingBreakoutRooms = false): void { $oldRecordingConsent = $room->getRecordingConsent(); @@ -435,8 +435,8 @@ public function setAvatar(Room $room, string $avatar): bool { * @param integer $status 0 none|1 video|2 audio * @param Participant|null $participant the Participant that changed the * state, null for the current user - * @throws \InvalidArgumentException When the status is invalid, not Room::RECORDING_* - * @throws \InvalidArgumentException When trying to start + * @throws InvalidArgumentException When the status is invalid, not Room::RECORDING_* + * @throws InvalidArgumentException When trying to start */ public function setCallRecording(Room $room, int $status = Room::RECORDING_NONE, ?Participant $participant = null): void { if (!$this->config->isRecordingEnabled() && $status !== Room::RECORDING_NONE) { @@ -728,11 +728,11 @@ public function verifyPassword(Room $room, string $password): array { } /** - * @throws \InvalidArgumentException When the room is a breakout room + * @throws InvalidArgumentException When the room is a breakout room */ public function setMessageExpiration(Room $room, int $seconds): void { if ($room->getObjectType() === BreakoutRoom::PARENT_OBJECT_TYPE) { - throw new \InvalidArgumentException('room'); + throw new InvalidArgumentException('room'); } $oldExpiration = $room->getMessageExpiration(); diff --git a/lib/Share/RoomShareProvider.php b/lib/Share/RoomShareProvider.php index 5919900c3d1..caf249b137f 100644 --- a/lib/Share/RoomShareProvider.php +++ b/lib/Share/RoomShareProvider.php @@ -1091,7 +1091,7 @@ public function getChildren(IShare $parent): array { * @param string $roomToken * @param string|null $user */ - public function deleteInRoom(string $roomToken, string $user = null): void { + public function deleteInRoom(string $roomToken, ?string $user = null): void { $this->cleanSharesByIdCache(); //First delete all custom room shares for the original shares to be removed diff --git a/tests/php/Recording/BackendNotifierTest.php b/tests/php/Recording/BackendNotifierTest.php index 5aefd4d9acf..56874dfb2e6 100644 --- a/tests/php/Recording/BackendNotifierTest.php +++ b/tests/php/Recording/BackendNotifierTest.php @@ -75,7 +75,7 @@ class BackendNotifierTest extends TestCase { private ?ISecureRandom $secureRandom = null; /** @var IURLGenerator|MockObject */ private $urlGenerator; - private ?\OCA\Talk\Tests\php\Recording\CustomBackendNotifier $backendNotifier = null; + private ?CustomBackendNotifier $backendNotifier = null; /** @var ParticipantService|MockObject */ private $participantService; diff --git a/tests/php/bootstrap.php b/tests/php/bootstrap.php index 71e40d9c8b7..f5e21224f9c 100644 --- a/tests/php/bootstrap.php +++ b/tests/php/bootstrap.php @@ -28,4 +28,4 @@ if (!class_exists('\PHPUnit\Framework\TestCase')) { require_once('PHPUnit/Autoload.php'); } -OC_Hook::clear(); +\OC_Hook::clear(); From 8d0a280d131bb230a5ca902c1f1d636d54210ac0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 1 Feb 2024 15:23:13 +0100 Subject: [PATCH 2/2] fix(CS): Prepare path to config Signed-off-by: Joas Schilling --- .php-cs-fixer.dist.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 60ba8432c06..67bcaf3465c 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -2,7 +2,7 @@ declare(strict_types=1); -require_once './vendor/autoload.php'; +require_once './vendor-bin/csfixer/vendor/autoload.php'; use Nextcloud\CodingStandard\Config;