]> source.dussan.org Git - nextcloud-server.git/commitdiff
Refactors lib/private/Calendar. 38990/head
authorFaraz Samapoor <fsa@adlas.at>
Sun, 25 Jun 2023 10:28:30 +0000 (13:58 +0330)
committerFaraz Samapoor <fsa@adlas.at>
Sun, 25 Jun 2023 10:28:30 +0000 (13:58 +0330)
Mainly using PHP8's constructor property promotion.

Signed-off-by: Faraz Samapoor <fsa@adlas.at>
lib/private/Calendar/CalendarQuery.php
lib/private/Calendar/Manager.php
lib/private/Calendar/Resource/Manager.php
lib/private/Calendar/Room/Manager.php

index 64f74c2728b1a63b82a0c3ccca09b65b3c3f9a81..b06220e3ce495c9e5753446429994c77777bf414 100644 (file)
@@ -28,33 +28,24 @@ namespace OC\Calendar;
 use OCP\Calendar\ICalendarQuery;
 
 class CalendarQuery implements ICalendarQuery {
-       /** @var string */
-       private $principalUri;
+       public array $searchProperties = [];
 
-       /** @var array */
-       public $searchProperties;
+       private ?string $searchPattern;
 
-       /** @var string|null */
-       private $searchPattern;
+       private array $options = [
+               'types' => [],
+       ];
 
-       /** @var array */
-       private $options;
+       private ?int $offset;
 
-       /** @var int|null */
-       private $offset;
-
-       /** @var int|null */
-       private $limit;
+       private ?int $limit;
 
        /** @var string[] */
-       private $calendarUris = [];
+       private array $calendarUris = [];
 
-       public function __construct(string $principalUri) {
-               $this->principalUri = $principalUri;
-               $this->searchProperties = [];
-               $this->options = [
-                       'types' => [],
-               ];
+       public function __construct(
+               private string $principalUri,
+       ) {
        }
 
        public function getPrincipalUri(): string {
index 7ef9dc585ae3c24a197336add93e3f1855ca96b2..f29920e17939f77923f1b0ea3f4be0595092c8de 100644 (file)
@@ -50,33 +50,19 @@ class Manager implements IManager {
        /**
         * @var ICalendar[] holds all registered calendars
         */
-       private $calendars = [];
+       private array $calendars = [];
 
        /**
         * @var \Closure[] to call to load/register calendar providers
         */
-       private $calendarLoaders = [];
-
-       /** @var Coordinator */
-       private $coordinator;
-
-       /** @var ContainerInterface */
-       private $container;
-
-       /** @var LoggerInterface */
-       private $logger;
-
-       private ITimeFactory $timeFactory;
-
-
-       public function __construct(Coordinator $coordinator,
-                                                               ContainerInterface $container,
-                                                               LoggerInterface $logger,
-                                                               ITimeFactory $timeFactory) {
-               $this->coordinator = $coordinator;
-               $this->container = $container;
-               $this->logger = $logger;
-               $this->timeFactory = $timeFactory;
+       private array $calendarLoaders = [];
+
+       public function __construct(
+               private Coordinator $coordinator,
+               private ContainerInterface $container,
+               private LoggerInterface $logger,
+               private ITimeFactory $timeFactory,
+       ) {
        }
 
        /**
@@ -92,7 +78,13 @@ class Manager implements IManager {
         * @return array an array of events/journals/todos which are arrays of arrays of key-value-pairs
         * @since 13.0.0
         */
-       public function search($pattern, array $searchProperties = [], array $options = [], $limit = null, $offset = null) {
+       public function search(
+               $pattern,
+               array $searchProperties = [],
+               array $options = [],
+               $limit = null,
+               $offset = null,
+       ): array {
                $this->loadCalendars();
                $result = [];
                foreach ($this->calendars as $calendar) {
@@ -112,29 +104,25 @@ class Manager implements IManager {
         * @return bool true if enabled, false if not
         * @since 13.0.0
         */
-       public function isEnabled() {
+       public function isEnabled(): bool {
                return !empty($this->calendars) || !empty($this->calendarLoaders);
        }
 
        /**
         * Registers a calendar
         *
-        * @param ICalendar $calendar
-        * @return void
         * @since 13.0.0
         */
-       public function registerCalendar(ICalendar $calendar) {
+       public function registerCalendar(ICalendar $calendar): void {
                $this->calendars[$calendar->getKey()] = $calendar;
        }
 
        /**
         * Unregisters a calendar
         *
-        * @param ICalendar $calendar
-        * @return void
         * @since 13.0.0
         */
-       public function unregisterCalendar(ICalendar $calendar) {
+       public function unregisterCalendar(ICalendar $calendar): void {
                unset($this->calendars[$calendar->getKey()]);
        }
 
@@ -142,19 +130,18 @@ class Manager implements IManager {
         * In order to improve lazy loading a closure can be registered which will be called in case
         * calendars are actually requested
         *
-        * @param \Closure $callable
-        * @return void
         * @since 13.0.0
         */
-       public function register(\Closure $callable) {
+       public function register(\Closure $callable): void {
                $this->calendarLoaders[] = $callable;
        }
 
        /**
         * @return ICalendar[]
+        *
         * @since 13.0.0
         */
-       public function getCalendars() {
+       public function getCalendars(): array {
                $this->loadCalendars();
 
                return array_values($this->calendars);
@@ -162,10 +149,10 @@ class Manager implements IManager {
 
        /**
         * removes all registered calendar instances
-        * @return void
+        *
         * @since 13.0.0
         */
-       public function clear() {
+       public function clear(): void {
                $this->calendars = [];
                $this->calendarLoaders = [];
        }
@@ -173,7 +160,7 @@ class Manager implements IManager {
        /**
         * loads all calendars
         */
-       private function loadCalendars() {
+       private function loadCalendars(): void {
                foreach ($this->calendarLoaders as $callable) {
                        $callable($this);
                }
@@ -181,8 +168,6 @@ class Manager implements IManager {
        }
 
        /**
-        * @param string $principalUri
-        * @param array $calendarUris
         * @return ICreateFromString[]
         */
        public function getCalendarsForPrincipal(string $principalUri, array $calendarUris = []): array {
@@ -240,7 +225,12 @@ class Manager implements IManager {
        /**
         * @throws \OCP\DB\Exception
         */
-       public function handleIMipReply(string $principalUri, string $sender, string $recipient, string $calendarData): bool {
+       public function handleIMipReply(
+               string $principalUri,
+               string $sender,
+               string $recipient,
+               string $calendarData,
+       ): bool {
                /** @var VCalendar $vObject */
                $vObject = Reader::read($calendarData);
                /** @var VEvent $vEvent */
@@ -309,7 +299,13 @@ class Manager implements IManager {
         * @since 25.0.0
         * @throws \OCP\DB\Exception
         */
-       public function handleIMipCancel(string $principalUri, string $sender, ?string $replyTo, string $recipient, string $calendarData): bool {
+       public function handleIMipCancel(
+               string $principalUri,
+               string $sender,
+               ?string $replyTo,
+               string $recipient,
+               string $calendarData,
+       ): bool {
                $vObject = Reader::read($calendarData);
                /** @var VEvent $vEvent */
                $vEvent = $vObject->{'VEVENT'};
index ebde4ac5eb5d5bc5597063d24794f938cefe32dc..88e733f3f24d0090ff8a24cf96490a9fd9692ab4 100644 (file)
@@ -33,46 +33,38 @@ use OCP\Calendar\Resource\IManager;
 use OCP\IServerContainer;
 
 class Manager implements IManager {
-       private Coordinator $bootstrapCoordinator;
-
-       private IServerContainer $server;
-
        private bool $bootstrapBackendsLoaded = false;
 
        /**
         * @var string[] holds all registered resource backends
         * @psalm-var class-string<IBackend>[]
         */
-       private $backends = [];
+       private array $backends = [];
 
        /** @var IBackend[] holds all backends that have been initialized already */
-       private $initializedBackends = [];
+       private array $initializedBackends = [];
 
-       public function __construct(Coordinator $bootstrapCoordinator,
-                                                               IServerContainer $server) {
-               $this->bootstrapCoordinator = $bootstrapCoordinator;
-               $this->server = $server;
+       public function __construct(
+               private Coordinator $bootstrapCoordinator,
+               private IServerContainer $server,
+       ) {
        }
 
        /**
         * Registers a resource backend
         *
-        * @param string $backendClass
-        * @return void
         * @since 14.0.0
         */
-       public function registerBackend(string $backendClass) {
+       public function registerBackend(string $backendClass): void {
                $this->backends[$backendClass] = $backendClass;
        }
 
        /**
         * Unregisters a resource backend
         *
-        * @param string $backendClass
-        * @return void
         * @since 14.0.0
         */
-       public function unregisterBackend(string $backendClass) {
+       public function unregisterBackend(string $backendClass): void {
                unset($this->backends[$backendClass], $this->initializedBackends[$backendClass]);
        }
 
@@ -114,9 +106,8 @@ class Manager implements IManager {
        /**
         * @param string $backendId
         * @throws \OCP\AppFramework\QueryException
-        * @return IBackend|null
         */
-       public function getBackend($backendId) {
+       public function getBackend($backendId): ?IBackend {
                $backends = $this->getBackends();
                foreach ($backends as $backend) {
                        if ($backend->getBackendIdentifier() === $backendId) {
@@ -129,10 +120,10 @@ class Manager implements IManager {
 
        /**
         * removes all registered backend instances
-        * @return void
+        *
         * @since 14.0.0
         */
-       public function clear() {
+       public function clear(): void {
                $this->backends = [];
                $this->initializedBackends = [];
        }
index 7e6af2823a3ef3c778096ffb7b0fa828a1c271dd..d7ecdfd8b366301467236849558dfad7b4d671f9 100644 (file)
@@ -33,10 +33,6 @@ use OCP\Calendar\Room\IManager;
 use OCP\IServerContainer;
 
 class Manager implements IManager {
-       private Coordinator $bootstrapCoordinator;
-
-       private IServerContainer $server;
-
        private bool $bootstrapBackendsLoaded = false;
 
        /**
@@ -48,20 +44,18 @@ class Manager implements IManager {
        /** @var IBackend[] holds all backends that have been initialized already */
        private array $initializedBackends = [];
 
-       public function __construct(Coordinator $bootstrapCoordinator,
-                                                               IServerContainer $server) {
-               $this->bootstrapCoordinator = $bootstrapCoordinator;
-               $this->server = $server;
+       public function __construct(
+               private Coordinator $bootstrapCoordinator,
+               private IServerContainer $server,
+       ) {
        }
 
        /**
         * Registers a resource backend
         *
-        * @param string $backendClass
-        * @return void
         * @since 14.0.0
         */
-       public function registerBackend(string $backendClass) {
+       public function registerBackend(string $backendClass): void {
                $this->backends[$backendClass] = $backendClass;
        }
 
@@ -69,10 +63,9 @@ class Manager implements IManager {
         * Unregisters a resource backend
         *
         * @param string $backendClass
-        * @return void
         * @since 14.0.0
         */
-       public function unregisterBackend(string $backendClass) {
+       public function unregisterBackend(string $backendClass): void {
                unset($this->backends[$backendClass], $this->initializedBackends[$backendClass]);
        }
 
@@ -120,9 +113,8 @@ class Manager implements IManager {
        /**
         * @param string $backendId
         * @throws \OCP\AppFramework\QueryException
-        * @return IBackend|null
         */
-       public function getBackend($backendId) {
+       public function getBackend($backendId): ?IBackend {
                $backends = $this->getBackends();
                foreach ($backends as $backend) {
                        if ($backend->getBackendIdentifier() === $backendId) {
@@ -135,10 +127,10 @@ class Manager implements IManager {
 
        /**
         * removes all registered backend instances
-        * @return void
+        *
         * @since 14.0.0
         */
-       public function clear() {
+       public function clear(): void {
                $this->backends = [];
                $this->initializedBackends = [];
        }