From e22742b9101af27666af86f296987323cca930a6 Mon Sep 17 00:00:00 2001 From: Hamid Dehnavi Date: Sat, 8 Jul 2023 20:26:32 +0330 Subject: [PATCH 1/2] Refactor contactsinteraction app Signed-off-by: Hamid Dehnavi --- apps/contactsinteraction/lib/AddressBook.php | 21 ++++++------- .../lib/AddressBookProvider.php | 13 +++----- .../lib/BackgroundJob/CleanupJob.php | 10 +++--- apps/contactsinteraction/lib/Card.php | 15 ++++----- .../Listeners/ContactInteractionListener.php | 31 ++++++------------- 5 files changed, 33 insertions(+), 57 deletions(-) diff --git a/apps/contactsinteraction/lib/AddressBook.php b/apps/contactsinteraction/lib/AddressBook.php index 518e39942d953..d830146cfc62a 100644 --- a/apps/contactsinteraction/lib/AddressBook.php +++ b/apps/contactsinteraction/lib/AddressBook.php @@ -44,22 +44,17 @@ class AddressBook extends ExternalAddressBook implements IACL { public const URI = 'recent'; - private RecentContactMapper $mapper; - private IL10N $l10n; - private string $principalUri; - - public function __construct(RecentContactMapper $mapper, - IL10N $l10n, - string $principalUri) { + public function __construct( + private RecentContactMapper $mapper, + private IL10N $l10n, + private string $principalUri, + ) { parent::__construct(Application::APP_ID, self::URI); - - $this->mapper = $mapper; - $this->l10n = $l10n; - $this->principalUri = $principalUri; } /** * @inheritDoc + * @throws Exception */ public function delete(): void { throw new Exception("This addressbook is immutable"); @@ -67,6 +62,7 @@ public function delete(): void { /** * @inheritDoc + * @throws Exception */ public function createFile($name, $data = null) { throw new Exception("This addressbook is immutable"); @@ -131,6 +127,7 @@ public function getLastModified(): ?int { /** * @inheritDoc + * @throws Exception */ public function propPatch(PropPatch $propPatch) { throw new Exception("This addressbook is immutable"); @@ -139,7 +136,7 @@ public function propPatch(PropPatch $propPatch) { /** * @inheritDoc */ - public function getProperties($properties) { + public function getProperties($properties): array { return [ 'principaluri' => $this->principalUri, '{DAV:}displayname' => $this->l10n->t('Recently contacted'), diff --git a/apps/contactsinteraction/lib/AddressBookProvider.php b/apps/contactsinteraction/lib/AddressBookProvider.php index 74d472d421b1f..835d2d25652fd 100644 --- a/apps/contactsinteraction/lib/AddressBookProvider.php +++ b/apps/contactsinteraction/lib/AddressBookProvider.php @@ -33,15 +33,10 @@ class AddressBookProvider implements IAddressBookProvider { - /** @var RecentContactMapper */ - private $mapper; - - /** @var IL10N */ - private $l10n; - - public function __construct(RecentContactMapper $mapper, IL10N $l10n) { - $this->mapper = $mapper; - $this->l10n = $l10n; + public function __construct( + private RecentContactMapper $mapper, + private IL10N $l10n, + ) { } /** diff --git a/apps/contactsinteraction/lib/BackgroundJob/CleanupJob.php b/apps/contactsinteraction/lib/BackgroundJob/CleanupJob.php index e728342e9b084..f23eaa6e1d378 100644 --- a/apps/contactsinteraction/lib/BackgroundJob/CleanupJob.php +++ b/apps/contactsinteraction/lib/BackgroundJob/CleanupJob.php @@ -31,19 +31,19 @@ use OCP\BackgroundJob\TimedJob; class CleanupJob extends TimedJob { - private RecentContactMapper $mapper; - public function __construct(ITimeFactory $time, - RecentContactMapper $mapper) { + public function __construct( + ITimeFactory $time, + private RecentContactMapper $mapper, + ) { parent::__construct($time); $this->setInterval(24 * 60 * 60); $this->setTimeSensitivity(IJob::TIME_INSENSITIVE); - $this->mapper = $mapper; } - protected function run($argument) { + protected function run($argument): void { $time = $this->time->getDateTime(); $time->modify('-7days'); $this->mapper->cleanUp($time->getTimestamp()); diff --git a/apps/contactsinteraction/lib/Card.php b/apps/contactsinteraction/lib/Card.php index aa73d0e2122b8..f39396a7326a1 100644 --- a/apps/contactsinteraction/lib/Card.php +++ b/apps/contactsinteraction/lib/Card.php @@ -36,14 +36,11 @@ class Card implements ICard, IACL { use ACLTrait; - private RecentContact $contact; - private string $principal; - private array $acls; - - public function __construct(RecentContact $contact, string $principal, array $acls) { - $this->contact = $contact; - $this->principal = $principal; - $this->acls = $acls; + public function __construct( + private RecentContact $contact, + private string $principal, + private array $acls, + ) { } /** @@ -77,7 +74,7 @@ public function put($data): ?string { /** * @inheritDoc */ - public function get() { + public function get(): string { return $this->contact->getCard(); } diff --git a/apps/contactsinteraction/lib/Listeners/ContactInteractionListener.php b/apps/contactsinteraction/lib/Listeners/ContactInteractionListener.php index 2064136c392cf..000954a901659 100644 --- a/apps/contactsinteraction/lib/Listeners/ContactInteractionListener.php +++ b/apps/contactsinteraction/lib/Listeners/ContactInteractionListener.php @@ -46,28 +46,15 @@ class ContactInteractionListener implements IEventListener { use TTransactional; - private RecentContactMapper $mapper; - private CardSearchDao $cardSearchDao; - private IUserManager $userManager; - private IDBConnection $dbConnection; - private ITimeFactory $timeFactory; - private IL10N $l10n; - private LoggerInterface $logger; - - public function __construct(RecentContactMapper $mapper, - CardSearchDao $cardSearchDao, - IUserManager $userManager, - IDBConnection $connection, - ITimeFactory $timeFactory, - IL10N $l10nFactory, - LoggerInterface $logger) { - $this->mapper = $mapper; - $this->cardSearchDao = $cardSearchDao; - $this->userManager = $userManager; - $this->dbConnection = $connection; - $this->timeFactory = $timeFactory; - $this->l10n = $l10nFactory; - $this->logger = $logger; + public function __construct( + private RecentContactMapper $mapper, + private CardSearchDao $cardSearchDao, + private IUserManager $userManager, + private IDBConnection $dbConnection, + private ITimeFactory $timeFactory, + private IL10N $l10n, + private LoggerInterface $logger, + ) { } public function handle(Event $event): void { From e1b33e6cd073c187ef50e36fef389f41583b8f76 Mon Sep 17 00:00:00 2001 From: Hamid Dehnavi Date: Sun, 16 Jul 2023 15:57:15 +0330 Subject: [PATCH 2/2] Make adjustments based on the psalm messages Signed-off-by: Hamid Dehnavi --- apps/contactsinteraction/lib/BackgroundJob/CleanupJob.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/contactsinteraction/lib/BackgroundJob/CleanupJob.php b/apps/contactsinteraction/lib/BackgroundJob/CleanupJob.php index f23eaa6e1d378..0291f8ae6bc75 100644 --- a/apps/contactsinteraction/lib/BackgroundJob/CleanupJob.php +++ b/apps/contactsinteraction/lib/BackgroundJob/CleanupJob.php @@ -43,7 +43,7 @@ public function __construct( } - protected function run($argument): void { + protected function run(mixed $argument): void { $time = $this->time->getDateTime(); $time->modify('-7days'); $this->mapper->cleanUp($time->getTimestamp());