From 0868b0bc401d5c069f21e47d8f9075dd13df401d Mon Sep 17 00:00:00 2001 From: Git'Fellow <12234510+solracsf@users.noreply.github.com> Date: Sun, 29 Mar 2026 21:21:15 +0200 Subject: [PATCH] refactor: Apply php8.2 optimizations Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com> --- composer.json | 2 +- lib/AppInfo/Application.php | 5 +- lib/Db/Assignment.php | 16 ++-- lib/Notification/NotificationHelper.php | 54 ++++--------- lib/Notification/Notifier.php | 31 ++------ lib/Search/DeckProvider.php | 13 +--- lib/Search/FilterStringParser.php | 11 +-- lib/Service/AssignmentService.php | 75 +++---------------- lib/Service/AttachmentService.php | 54 +++---------- lib/Service/ConfigService.php | 8 +- lib/Service/DefaultBoardService.php | 33 ++------ .../Importer/Systems/TrelloJsonService.php | 37 ++++----- lib/Service/SearchService.php | 42 ++--------- lib/Service/SessionService.php | 21 ++---- lib/Service/StackService.php | 59 ++++----------- 15 files changed, 111 insertions(+), 350 deletions(-) diff --git a/composer.json b/composer.json index d9d435358c..c7588048d1 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "bamarni/composer-bin-plugin": true }, "platform": { - "php": "8.1" + "php": "8.2" } }, "scripts": { diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 234af609fa..9a072988df 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -7,7 +7,6 @@ namespace OCA\Deck\AppInfo; -use Closure; use Exception; use OCA\Circles\Events\CircleDestroyedEvent; use OCA\Deck\Capabilities; @@ -99,8 +98,8 @@ public function __construct(array $urlParams = []) { } public function boot(IBootContext $context): void { - $context->injectFn(Closure::fromCallable([$this, 'registerCommentsEntity'])); - $context->injectFn(Closure::fromCallable([$this, 'registerCollaborationResources'])); + $context->injectFn($this->registerCommentsEntity(...)); + $context->injectFn($this->registerCollaborationResources(...)); $context->injectFn(function (IManager $shareManager) { $shareManager->registerShareProvider(DeckShareProvider::class); diff --git a/lib/Db/Assignment.php b/lib/Db/Assignment.php index 4160aed12d..fcc1b02470 100644 --- a/lib/Db/Assignment.php +++ b/lib/Db/Assignment.php @@ -26,15 +26,11 @@ public function __construct() { } public function getTypeString(): string { - switch ($this->getType()) { - case self::TYPE_USER: - return 'user'; - case self::TYPE_GROUP: - return 'group'; - case self::TYPE_CIRCLE: - return 'circle'; - } - - return 'unknown'; + return match ($this->getType()) { + self::TYPE_USER => 'user', + self::TYPE_GROUP => 'group', + self::TYPE_CIRCLE => 'circle', + default => 'unknown', + }; } } diff --git a/lib/Notification/NotificationHelper.php b/lib/Notification/NotificationHelper.php index d11b2201e7..0813111334 100644 --- a/lib/Notification/NotificationHelper.php +++ b/lib/Notification/NotificationHelper.php @@ -31,43 +31,19 @@ class NotificationHelper { - /** @var CardMapper */ - protected $cardMapper; - /** @var BoardMapper */ - protected $boardMapper; - /** @var AssignmentMapper */ - protected $assignmentMapper; - /** @var PermissionService */ - protected $permissionService; - /** @var IConfig */ - protected $config; - /** @var IManager */ - protected $notificationManager; - /** @var IGroupManager */ - protected $groupManager; - /** @var string */ - protected $currentUser; /** @var array */ - private $boards = []; + private array $boards = []; public function __construct( - CardMapper $cardMapper, - BoardMapper $boardMapper, - AssignmentMapper $assignmentMapper, - PermissionService $permissionService, - IConfig $config, - IManager $notificationManager, - IGroupManager $groupManager, - $userId, + protected readonly CardMapper $cardMapper, + protected readonly BoardMapper $boardMapper, + protected readonly AssignmentMapper $assignmentMapper, + protected readonly PermissionService $permissionService, + protected readonly IConfig $config, + protected readonly IManager $notificationManager, + protected readonly IGroupManager $groupManager, + protected readonly ?string $userId, ) { - $this->cardMapper = $cardMapper; - $this->boardMapper = $boardMapper; - $this->assignmentMapper = $assignmentMapper; - $this->permissionService = $permissionService; - $this->config = $config; - $this->notificationManager = $notificationManager; - $this->groupManager = $groupManager; - $this->currentUser = $userId; } /** @@ -145,7 +121,7 @@ public function sendCardAssigned(Card $card, string $userId): void { ->setSubject('card-assigned', [ $card->getTitle(), $board->getTitle(), - $this->currentUser + $this->userId ]); $this->notificationManager->notify($notification); } @@ -174,7 +150,7 @@ public function sendBoardShared(int $boardId, Acl $acl, bool $markAsRead = false $notification = $this->generateBoardShared($board, $acl->getParticipant()); if ($markAsRead) { $this->notificationManager->markProcessed($notification); - } elseif ($acl->getParticipant() !== $this->currentUser) { + } elseif ($acl->getParticipant() !== $this->userId) { $notification->setDateTime(new DateTime()); $this->notificationManager->notify($notification); } @@ -185,7 +161,7 @@ public function sendBoardShared(int $boardId, Acl $acl, bool $markAsRead = false return; } foreach ($group->getUsers() as $user) { - if ($user->getUID() === $this->currentUser) { + if ($user->getUID() === $this->userId) { continue; } $notification = $this->generateBoardShared($board, $user->getUID()); @@ -201,7 +177,7 @@ public function sendBoardShared(int $boardId, Acl $acl, bool $markAsRead = false public function sendMention(IComment $comment): void { foreach ($comment->getMentions() as $mention) { - if ((string)$mention['id'] === $this->currentUser) { + if ((string)$mention['id'] === $this->userId) { continue; } $card = $this->cardMapper->find($comment->getObjectId()); @@ -212,7 +188,7 @@ public function sendMention(IComment $comment): void { ->setUser((string)$mention['id']) ->setDateTime(new DateTime()) ->setObject('card', (string)$card->getId()) - ->setSubject('card-comment-mentioned', [$card->getTitle(), $boardId, $this->currentUser]) + ->setSubject('card-comment-mentioned', [$card->getTitle(), $boardId, $this->userId]) ->setMessage('{message}', ['message' => $comment->getMessage()]); $this->notificationManager->notify($notification); } @@ -235,7 +211,7 @@ private function generateBoardShared(Board $board, string $userId): INotificatio ->setApp('deck') ->setUser($userId) ->setObject('board', (string)$board->getId()) - ->setSubject('board-shared', [$board->getTitle(), $this->currentUser]); + ->setSubject('board-shared', [$board->getTitle(), $this->userId]); return $notification; } } diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index 379b059501..87ee25941e 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -19,33 +19,14 @@ use OCP\Notification\UnknownNotificationException; class Notifier implements INotifier { - /** @var IFactory */ - protected $l10nFactory; - /** @var IURLGenerator */ - protected $url; - /** @var IUserManager */ - protected $userManager; - /** @var CardMapper */ - protected $cardMapper; - /** @var StackMapper */ - protected $stackMapper; - /** @var BoardMapper */ - protected $boardMapper; - public function __construct( - IFactory $l10nFactory, - IURLGenerator $url, - IUserManager $userManager, - CardMapper $cardMapper, - StackMapper $stackMapper, - BoardMapper $boardMapper, + protected readonly IFactory $l10nFactory, + protected readonly IURLGenerator $url, + protected readonly IUserManager $userManager, + protected readonly CardMapper $cardMapper, + protected readonly StackMapper $stackMapper, + protected readonly BoardMapper $boardMapper, ) { - $this->l10nFactory = $l10nFactory; - $this->url = $url; - $this->userManager = $userManager; - $this->cardMapper = $cardMapper; - $this->stackMapper = $stackMapper; - $this->boardMapper = $boardMapper; } /** diff --git a/lib/Search/DeckProvider.php b/lib/Search/DeckProvider.php index e1f1811e6c..1d36612a3b 100644 --- a/lib/Search/DeckProvider.php +++ b/lib/Search/DeckProvider.php @@ -21,18 +21,11 @@ use OCP\Search\SearchResult; class DeckProvider implements IProvider { - private IL10N $l10n; - private SearchService $searchService; - private IURLGenerator $urlGenerator; - public function __construct( - SearchService $searchService, - IURLGenerator $urlGenerator, - IL10N $l10n, + private readonly SearchService $searchService, + private readonly IURLGenerator $urlGenerator, + private readonly IL10N $l10n, ) { - $this->l10n = $l10n; - $this->searchService = $searchService; - $this->urlGenerator = $urlGenerator; } public function getId(): string { diff --git a/lib/Search/FilterStringParser.php b/lib/Search/FilterStringParser.php index 23431131dd..abca69cc96 100644 --- a/lib/Search/FilterStringParser.php +++ b/lib/Search/FilterStringParser.php @@ -16,14 +16,9 @@ use OCP\IL10N; class FilterStringParser { - - /** - * @var IL10N - */ - private $l10n; - - public function __construct(IL10N $l10n) { - $this->l10n = $l10n; + public function __construct( + private readonly IL10N $l10n, + ) { } public function parse(?string $filter): SearchQuery { diff --git a/lib/Service/AssignmentService.php b/lib/Service/AssignmentService.php index 4d9a97486d..df422325f4 100644 --- a/lib/Service/AssignmentService.php +++ b/lib/Service/AssignmentService.php @@ -25,69 +25,18 @@ use OCP\EventDispatcher\IEventDispatcher; class AssignmentService { - - /** - * @var PermissionService - */ - private $permissionService; - /** - * @var CardMapper - */ - private $cardMapper; - /** - * @var AssignmentMapper - */ - private $assignedUsersMapper; - /** - * @var AclMapper - */ - private $aclMapper; - /** - * @var NotificationHelper - */ - private $notificationHelper; - /** - * @var ChangeHelper - */ - private $changeHelper; - /** - * @var ActivityManager - */ - private $activityManager; - /** - * @var IEventDispatcher - */ - private $eventDispatcher; - /** @var string|null */ - private $currentUser; - /** - * @var AssignmentServiceValidator - */ - private $assignmentServiceValidator; - - public function __construct( - PermissionService $permissionService, - CardMapper $cardMapper, - AssignmentMapper $assignedUsersMapper, - AclMapper $aclMapper, - NotificationHelper $notificationHelper, - ActivityManager $activityManager, - ChangeHelper $changeHelper, - IEventDispatcher $eventDispatcher, - AssignmentServiceValidator $assignmentServiceValidator, - $userId, + private readonly PermissionService $permissionService, + private readonly CardMapper $cardMapper, + private readonly AssignmentMapper $assignedUsersMapper, + private readonly AclMapper $aclMapper, + private readonly NotificationHelper $notificationHelper, + private readonly ActivityManager $activityManager, + private readonly ChangeHelper $changeHelper, + private readonly IEventDispatcher $eventDispatcher, + private readonly AssignmentServiceValidator $assignmentServiceValidator, + private readonly ?string $userId, ) { - $this->assignmentServiceValidator = $assignmentServiceValidator; - $this->permissionService = $permissionService; - $this->cardMapper = $cardMapper; - $this->assignedUsersMapper = $assignedUsersMapper; - $this->aclMapper = $aclMapper; - $this->notificationHelper = $notificationHelper; - $this->changeHelper = $changeHelper; - $this->activityManager = $activityManager; - $this->eventDispatcher = $eventDispatcher; - $this->currentUser = $userId; } /** @@ -122,7 +71,7 @@ public function assignUser(int $cardId, string $userId, int $type = Assignment:: } - if ($type === Assignment::TYPE_USER && $userId !== $this->currentUser) { + if ($type === Assignment::TYPE_USER && $userId !== $this->userId) { $this->notificationHelper->sendCardAssigned($card, $userId); } @@ -156,7 +105,7 @@ public function unassignUser(int $cardId, string $userId, int $type = 0): Assign $assignment = $this->assignedUsersMapper->delete($assignment); $card = $this->cardMapper->find($cardId); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_CARD_USER_UNASSIGN, ['assigneduser' => $userId]); - if ($type === Assignment::TYPE_USER && $userId !== $this->currentUser) { + if ($type === Assignment::TYPE_USER && $userId !== $this->userId) { $this->notificationHelper->markCardAssignedAsRead($card, $userId); } $this->changeHelper->cardChanged($cardId); diff --git a/lib/Service/AttachmentService.php b/lib/Service/AttachmentService.php index b01bb0ce0e..af778f143a 100644 --- a/lib/Service/AttachmentService.php +++ b/lib/Service/AttachmentService.php @@ -28,52 +28,22 @@ use Psr\Container\ContainerExceptionInterface; class AttachmentService { - private $attachmentMapper; - private $cardMapper; - private $permissionService; - private $userId; - /** @var IAttachmentService[] */ - private $services = []; - /** @var Application */ - private $application; - /** @var AttachmentCacheHelper */ - private $attachmentCacheHelper; - /** @var IL10N */ - private $l10n; - /** @var ActivityManager */ - private $activityManager; - /** @var ChangeHelper */ - private $changeHelper; - private IUserManager $userManager; - /** @var AttachmentServiceValidator */ - private AttachmentServiceValidator $attachmentServiceValidator; + private array $services = []; public function __construct( - AttachmentMapper $attachmentMapper, - CardMapper $cardMapper, - IUserManager $userManager, - ChangeHelper $changeHelper, - PermissionService $permissionService, - Application $application, - AttachmentCacheHelper $attachmentCacheHelper, - $userId, - IL10N $l10n, - ActivityManager $activityManager, - AttachmentServiceValidator $attachmentServiceValidator, + private readonly AttachmentMapper $attachmentMapper, + private readonly CardMapper $cardMapper, + private readonly IUserManager $userManager, + private readonly ChangeHelper $changeHelper, + private readonly PermissionService $permissionService, + private readonly Application $application, + private readonly AttachmentCacheHelper $attachmentCacheHelper, + private readonly ?string $userId, + private readonly IL10N $l10n, + private readonly ActivityManager $activityManager, + private readonly AttachmentServiceValidator $attachmentServiceValidator, ) { - $this->attachmentMapper = $attachmentMapper; - $this->cardMapper = $cardMapper; - $this->permissionService = $permissionService; - $this->userId = $userId; - $this->application = $application; - $this->attachmentCacheHelper = $attachmentCacheHelper; - $this->l10n = $l10n; - $this->activityManager = $activityManager; - $this->changeHelper = $changeHelper; - $this->userManager = $userManager; - $this->attachmentServiceValidator = $attachmentServiceValidator; - // Register shipped attachment services // TODO: move this to a plugin based approach once we have different types of attachments $this->registerAttachmentService('deck_file', FileService::class); diff --git a/lib/Service/ConfigService.php b/lib/Service/ConfigService.php index c63571d2c5..92880ff39e 100644 --- a/lib/Service/ConfigService.php +++ b/lib/Service/ConfigService.php @@ -25,16 +25,12 @@ class ConfigService { public const SETTING_BOARD_NOTIFICATION_DUE_ALL = 'all'; public const SETTING_BOARD_NOTIFICATION_DUE_DEFAULT = self::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED; - private IConfig $config; private ?string $userId = null; - private IGroupManager $groupManager; public function __construct( - IConfig $config, - IGroupManager $groupManager, + private readonly IConfig $config, + private readonly IGroupManager $groupManager, ) { - $this->groupManager = $groupManager; - $this->config = $config; } public function getUserId(): ?string { diff --git a/lib/Service/DefaultBoardService.php b/lib/Service/DefaultBoardService.php index 211c20070c..694b184003 100644 --- a/lib/Service/DefaultBoardService.php +++ b/lib/Service/DefaultBoardService.php @@ -16,33 +16,16 @@ use OCP\PreConditionNotMetException; class DefaultBoardService { - private $boardMapper; - private $boardService; - private $stackService; - private $cardService; - private $config; - private $l10n; - private LabelService $labelService; - private AttachmentService $attachmentService; - public function __construct( - IL10N $l10n, - BoardMapper $boardMapper, - BoardService $boardService, - StackService $stackService, - CardService $cardService, - IConfig $config, - LabelService $labelService, - AttachmentService $attachmentService, + private readonly IL10N $l10n, + private readonly BoardMapper $boardMapper, + private readonly BoardService $boardService, + private readonly StackService $stackService, + private readonly CardService $cardService, + private readonly IConfig $config, + private readonly LabelService $labelService, + private readonly AttachmentService $attachmentService, ) { - $this->boardService = $boardService; - $this->stackService = $stackService; - $this->cardService = $cardService; - $this->config = $config; - $this->boardMapper = $boardMapper; - $this->l10n = $l10n; - $this->labelService = $labelService; - $this->attachmentService = $attachmentService; } /** diff --git a/lib/Service/Importer/Systems/TrelloJsonService.php b/lib/Service/Importer/Systems/TrelloJsonService.php index dc7acd8b12..142ad242ff 100644 --- a/lib/Service/Importer/Systems/TrelloJsonService.php +++ b/lib/Service/Importer/Systems/TrelloJsonService.php @@ -318,30 +318,19 @@ public function getAclList(): array { } private function translateColor(?string $color): string { - switch ($color) { - case 'red': - return 'ff0000'; - case 'yellow': - return 'ffff00'; - case 'orange': - return 'ff6600'; - case 'green': - return '00ff00'; - case 'purple': - return '9900ff'; - case 'blue': - return '0000ff'; - case 'sky': - return '00ccff'; - case 'lime': - return '00ff99'; - case 'pink': - return 'ff66cc'; - case 'black': - return '000000'; - default: - return 'ffffff'; - } + return match ($color) { + 'red' => 'ff0000', + 'yellow' => 'ffff00', + 'orange' => 'ff6600', + 'green' => '00ff00', + 'purple' => '9900ff', + 'blue' => '0000ff', + 'sky' => '00ccff', + 'lime' => '00ff99', + 'pink' => 'ff66cc', + 'black' => '000000', + default => 'ffffff', + }; } private function replaceUsernames(string $text): string { diff --git a/lib/Service/SearchService.php b/lib/Service/SearchService.php index 3e06e253d6..383402abc9 100644 --- a/lib/Service/SearchService.php +++ b/lib/Service/SearchService.php @@ -21,42 +21,16 @@ use OCP\IUserManager; class SearchService { - - /** @var BoardService */ - private $boardService; - /** @var CardMapper */ - private $cardMapper; - /** @var CardService */ - private $cardService; - /** @var ICommentsManager */ - private $commentsManager; - /** @var FilterStringParser */ - private $filterStringParser; - /** @var IUserManager */ - private $userManager; - /** @var IL10N */ - private $l10n; - /** @var IURLGenerator */ - private $urlGenerator; - public function __construct( - BoardService $boardService, - CardMapper $cardMapper, - CardService $cardService, - ICommentsManager $commentsManager, - FilterStringParser $filterStringParser, - IUserManager $userManager, - IL10N $l10n, - IURLGenerator $urlGenerator, + private readonly BoardService $boardService, + private readonly CardMapper $cardMapper, + private readonly CardService $cardService, + private readonly ICommentsManager $commentsManager, + private readonly FilterStringParser $filterStringParser, + private readonly IUserManager $userManager, + private readonly IL10N $l10n, + private readonly IURLGenerator $urlGenerator, ) { - $this->boardService = $boardService; - $this->cardMapper = $cardMapper; - $this->cardService = $cardService; - $this->commentsManager = $commentsManager; - $this->filterStringParser = $filterStringParser; - $this->userManager = $userManager; - $this->l10n = $l10n; - $this->urlGenerator = $urlGenerator; } public function searchCards(string $term, ?int $limit = null, ?int $cursor = null): array { diff --git a/lib/Service/SessionService.php b/lib/Service/SessionService.php index 5a955270fc..9ba5312f23 100644 --- a/lib/Service/SessionService.php +++ b/lib/Service/SessionService.php @@ -22,24 +22,13 @@ class SessionService { public const SESSION_VALID_TIME = 92; - private SessionMapper $sessionMapper; - private ITimeFactory $timeFactory; - private $userId; - private IEventDispatcher $eventDispatcher; - private ISecureRandom $secureRandom; - public function __construct( - SessionMapper $sessionMapper, - ISecureRandom $secureRandom, - ITimeFactory $timeFactory, - $userId, - IEventDispatcher $eventDispatcher, + private readonly SessionMapper $sessionMapper, + private readonly ISecureRandom $secureRandom, + private readonly ITimeFactory $timeFactory, + private readonly ?string $userId, + private readonly IEventDispatcher $eventDispatcher, ) { - $this->sessionMapper = $sessionMapper; - $this->secureRandom = $secureRandom; - $this->timeFactory = $timeFactory; - $this->userId = $userId; - $this->eventDispatcher = $eventDispatcher; } public function initSession(int $boardId): Session { diff --git a/lib/Service/StackService.php b/lib/Service/StackService.php index 67202f7dbd..2515898be7 100644 --- a/lib/Service/StackService.php +++ b/lib/Service/StackService.php @@ -28,55 +28,26 @@ use Psr\Log\LoggerInterface; class StackService { - private StackMapper $stackMapper; - private CardMapper $cardMapper; - private BoardMapper $boardMapper; - private LabelMapper $labelMapper; - private PermissionService $permissionService; - private BoardService $boardService; - private CardService $cardService; - private AssignmentMapper $assignedUsersMapper; - private AttachmentService $attachmentService; - private ActivityManager $activityManager; - private ChangeHelper $changeHelper; - private LoggerInterface $logger; - private IEventDispatcher $eventDispatcher; - private StackServiceValidator $stackServiceValidator; - public function __construct( - StackMapper $stackMapper, - BoardMapper $boardMapper, - CardMapper $cardMapper, - LabelMapper $labelMapper, - PermissionService $permissionService, - BoardService $boardService, - CardService $cardService, - AssignmentMapper $assignedUsersMapper, - AttachmentService $attachmentService, - ActivityManager $activityManager, - ChangeHelper $changeHelper, - LoggerInterface $logger, - IEventDispatcher $eventDispatcher, - StackServiceValidator $stackServiceValidator, + private readonly StackMapper $stackMapper, + private readonly BoardMapper $boardMapper, + private readonly CardMapper $cardMapper, + private readonly LabelMapper $labelMapper, + private readonly PermissionService $permissionService, + private readonly BoardService $boardService, + private readonly CardService $cardService, + private readonly AssignmentMapper $assignedUsersMapper, + private readonly AttachmentService $attachmentService, + private readonly ActivityManager $activityManager, + private readonly ChangeHelper $changeHelper, + private readonly LoggerInterface $logger, + private readonly IEventDispatcher $eventDispatcher, + private readonly StackServiceValidator $stackServiceValidator, ) { - $this->stackMapper = $stackMapper; - $this->boardMapper = $boardMapper; - $this->cardMapper = $cardMapper; - $this->labelMapper = $labelMapper; - $this->permissionService = $permissionService; - $this->boardService = $boardService; - $this->cardService = $cardService; - $this->assignedUsersMapper = $assignedUsersMapper; - $this->attachmentService = $attachmentService; - $this->activityManager = $activityManager; - $this->changeHelper = $changeHelper; - $this->logger = $logger; - $this->eventDispatcher = $eventDispatcher; - $this->stackServiceValidator = $stackServiceValidator; } /** @param Stack[] $stacks */ - private function enrichStacksWithCards(array $stacks, $since = -1): void { + private function enrichStacksWithCards(array $stacks, int $since = -1): void { $cardsByStackId = $this->cardMapper->findAllForStacks(array_map(fn (Stack $stack) => $stack->getId(), $stacks), null, 0, $since); foreach ($cardsByStackId as $stackId => $cards) {