Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(CS): Prepare coding standard update #11510

Merged
merged 2 commits into from
Feb 2, 2024
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
2 changes: 1 addition & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion lib/Activity/Provider/Call.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
2 changes: 1 addition & 1 deletion lib/Activity/Provider/Invitation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
2 changes: 1 addition & 1 deletion lib/Chat/SystemMessage/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion lib/Collaboration/Resources/ConversationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions lib/Controller/ChatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -150,7 +150,7 @@ protected function getActorInfo(string $actorDisplayName = ''): array {
/**
* @return DataResponse<Http::STATUS_CREATED, ?TalkChatMessageWithParent, array{X-Chat-Last-Common-Read?: numeric-string}>
*/
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);

Expand Down
9 changes: 4 additions & 5 deletions lib/Controller/RoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

namespace OCA\Talk\Controller;

use InvalidArgumentException;
use OCA\Talk\Config;
use OCA\Talk\Events\AAttendeeRemovedEvent;
use OCA\Talk\Events\BeforeRoomsFetchEvent;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Flow/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ 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());
}

public function onEvent(string $eventName, Event $event, IRuleMatcher $ruleMatcher): void {
$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);

Expand Down
2 changes: 1 addition & 1 deletion lib/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/Middleware/InjectionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Migration/Version13000Date20210625232111.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, [
Expand Down
2 changes: 1 addition & 1 deletion lib/Migration/Version18000Date20231024141626.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
28 changes: 14 additions & 14 deletions lib/Service/BreakoutRoomService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions lib/Service/RecordingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.', [
Expand All @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions lib/Service/RoomService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion lib/Share/RoomShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Recording/BackendNotifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/php/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
if (!class_exists('\PHPUnit\Framework\TestCase')) {
require_once('PHPUnit/Autoload.php');
}
OC_Hook::clear();
\OC_Hook::clear();
Loading