]> source.dussan.org Git - nextcloud-server.git/commitdiff
Refactors controllers by using PHP8's constructor property promotion.
authorFaraz Samapoor <f.samapoor@gmail.com>
Sun, 4 Jun 2023 20:16:27 +0000 (23:46 +0330)
committerLouis <6653109+artonge@users.noreply.github.com>
Fri, 16 Jun 2023 17:29:40 +0000 (19:29 +0200)
Signed-off-by: Faraz Samapoor <f.samapoor@gmail.com>
core/Controller/JsController.php
core/Controller/LoginController.php
core/Controller/LostController.php
core/Controller/NavigationController.php
core/Controller/OCSController.php
core/Controller/PreviewController.php
core/Controller/ProfileApiController.php
core/Controller/ProfilePageController.php
core/Controller/RecommendedAppsController.php
core/Controller/ReferenceApiController.php
core/Controller/ReferenceController.php

index 6b3e7ff2ed2af6f4183b06f227aae953253bd89b..8a361dae67f56db6f4ab7db2e80bba6bcf8cea6c 100644 (file)
@@ -45,13 +45,14 @@ use OCP\IRequest;
 
 class JsController extends Controller {
        protected IAppData $appData;
-       protected ITimeFactory $timeFactory;
 
-       public function __construct($appName, IRequest $request, Factory $appDataFactory, ITimeFactory $timeFactory) {
+       public function __construct(string $appName,
+                                                               IRequest $request,
+                                                               Factory $appDataFactory,
+                                                               protected ITimeFactory $timeFactory) {
                parent::__construct($appName, $request);
 
                $this->appData = $appDataFactory->get('js');
-               $this->timeFactory = $timeFactory;
        }
 
        /**
index 9c64204b8980d48e78c3a3aee66b44427d9a4a62..4c3d07c6cf210a10cc6b411f784ddf9b8cded2c5 100644 (file)
@@ -63,44 +63,20 @@ class LoginController extends Controller {
        public const LOGIN_MSG_INVALIDPASSWORD = 'invalidpassword';
        public const LOGIN_MSG_USERDISABLED = 'userdisabled';
 
-       private IUserManager $userManager;
-       private IConfig $config;
-       private ISession $session;
-       /** @var Session */
-       private $userSession;
-       private IURLGenerator $urlGenerator;
-       private Defaults $defaults;
-       private Throttler $throttler;
-       private IInitialStateService $initialStateService;
-       private WebAuthnManager $webAuthnManager;
-       private IManager $manager;
-       private IL10N $l10n;
-
        public function __construct(?string $appName,
                                                                IRequest $request,
-                                                               IUserManager $userManager,
-                                                               IConfig $config,
-                                                               ISession $session,
-                                                               IUserSession $userSession,
-                                                               IURLGenerator $urlGenerator,
-                                                               Defaults $defaults,
-                                                               Throttler $throttler,
-                                                               IInitialStateService $initialStateService,
-                                                               WebAuthnManager $webAuthnManager,
-                                                               IManager $manager,
-                                                               IL10N $l10n) {
+                                                               private IUserManager $userManager,
+                                                               private IConfig $config,
+                                                               private ISession $session,
+                                                               private IUserSession $userSession,
+                                                               private IURLGenerator $urlGenerator,
+                                                               private Defaults $defaults,
+                                                               private Throttler $throttler,
+                                                               private IInitialStateService $initialStateService,
+                                                               private WebAuthnManager $webAuthnManager,
+                                                               private IManager $manager,
+                                                               private IL10N $l10n) {
                parent::__construct($appName, $request);
-               $this->userManager = $userManager;
-               $this->config = $config;
-               $this->session = $session;
-               $this->userSession = $userSession;
-               $this->urlGenerator = $urlGenerator;
-               $this->defaults = $defaults;
-               $this->throttler = $throttler;
-               $this->initialStateService = $initialStateService;
-               $this->webAuthnManager = $webAuthnManager;
-               $this->manager = $manager;
-               $this->l10n = $l10n;
        }
 
        /**
index 127c6310f6b3e1989bf91e69e380992382181617..1b773b344af507bdeae929c53ef3152701d9c107 100644 (file)
@@ -73,54 +73,26 @@ use function reset;
  * @package OC\Core\Controller
  */
 class LostController extends Controller {
-       protected IURLGenerator $urlGenerator;
-       protected IUserManager $userManager;
-       protected Defaults $defaults;
-       protected IL10N $l10n;
        protected string $from;
-       protected IManager $encryptionManager;
-       protected IConfig $config;
-       protected IMailer $mailer;
-       private LoggerInterface $logger;
-       private Manager $twoFactorManager;
-       private IInitialState $initialState;
-       private IVerificationToken $verificationToken;
-       private IEventDispatcher $eventDispatcher;
-       private Limiter $limiter;
-
-       public function __construct(
-               string $appName,
-               IRequest $request,
-               IURLGenerator $urlGenerator,
-               IUserManager $userManager,
-               Defaults $defaults,
-               IL10N $l10n,
-               IConfig $config,
-               string $defaultMailAddress,
-               IManager $encryptionManager,
-               IMailer $mailer,
-               LoggerInterface $logger,
-               Manager $twoFactorManager,
-               IInitialState $initialState,
-               IVerificationToken $verificationToken,
-               IEventDispatcher $eventDispatcher,
-               Limiter $limiter
-       ) {
+
+       public function __construct(string $appName,
+                                                               IRequest $request,
+                                                               private IURLGenerator $urlGenerator,
+                                                               private IUserManager $userManager,
+                                                               private Defaults $defaults,
+                                                               private IL10N $l10n,
+                                                               private IConfig $config,
+                                                               string $defaultMailAddress,
+                                                               private IManager $encryptionManager,
+                                                               private IMailer $mailer,
+                                                               private LoggerInterface $logger,
+                                                               private Manager $twoFactorManager,
+                                                               private IInitialState $initialState,
+                                                               private IVerificationToken $verificationToken,
+                                                               private IEventDispatcher $eventDispatcher,
+                                                               private Limiter $limiter) {
                parent::__construct($appName, $request);
-               $this->urlGenerator = $urlGenerator;
-               $this->userManager = $userManager;
-               $this->defaults = $defaults;
-               $this->l10n = $l10n;
                $this->from = $defaultMailAddress;
-               $this->encryptionManager = $encryptionManager;
-               $this->config = $config;
-               $this->mailer = $mailer;
-               $this->logger = $logger;
-               $this->twoFactorManager = $twoFactorManager;
-               $this->initialState = $initialState;
-               $this->verificationToken = $verificationToken;
-               $this->eventDispatcher = $eventDispatcher;
-               $this->limiter = $limiter;
        }
 
        /**
index a1c3f917fe35003468253e8fe20eb4f326aed752..68a9bf98037746338db3564027794098dc46a606 100644 (file)
@@ -30,13 +30,11 @@ use OCP\IRequest;
 use OCP\IURLGenerator;
 
 class NavigationController extends OCSController {
-       private INavigationManager $navigationManager;
-       private IURLGenerator $urlGenerator;
-
-       public function __construct(string $appName, IRequest $request, INavigationManager $navigationManager, IURLGenerator $urlGenerator) {
+       public function __construct(string $appName,
+                                                               IRequest $request,
+                                                               private INavigationManager $navigationManager,
+                                                               private IURLGenerator $urlGenerator) {
                parent::__construct($appName, $request);
-               $this->navigationManager = $navigationManager;
-               $this->urlGenerator = $urlGenerator;
        }
 
        /**
index b40776fcfb824c65f615a9aa4fca20e55b0a79ba..c4ae91b4db1a2e5e0b1aa6afc4007e6d4c7bd875 100644 (file)
@@ -35,22 +35,13 @@ use OCP\IUserManager;
 use OCP\IUserSession;
 
 class OCSController extends \OCP\AppFramework\OCSController {
-       private CapabilitiesManager $capabilitiesManager;
-       private IUserSession $userSession;
-       private IUserManager $userManager;
-       private Manager $keyManager;
-
        public function __construct(string $appName,
                                                                IRequest $request,
-                                                               CapabilitiesManager $capabilitiesManager,
-                                                               IUserSession $userSession,
-                                                               IUserManager $userManager,
-                                                               Manager $keyManager) {
+                                                               private CapabilitiesManager $capabilitiesManager,
+                                                               private IUserSession $userSession,
+                                                               private IUserManager $userManager,
+                                                               private Manager $keyManager) {
                parent::__construct($appName, $request);
-               $this->capabilitiesManager = $capabilitiesManager;
-               $this->userSession = $userSession;
-               $this->userManager = $userManager;
-               $this->keyManager = $keyManager;
        }
 
        /**
index 118f1b47752d65359fa65d59d403cf8758517a91..d742af20e1d8527585248e9af8a5942452992ddb 100644 (file)
@@ -40,21 +40,12 @@ use OCP\IPreview;
 use OCP\IRequest;
 
 class PreviewController extends Controller {
-       private ?string $userId;
-       private IRootFolder $root;
-       private IPreview $preview;
-
        public function __construct(string $appName,
                                                                IRequest $request,
-                                                               IPreview $preview,
-                                                               IRootFolder $root,
-                                                               ?string $userId
-       ) {
+                                                               private IPreview $preview,
+                                                               private IRootFolder $root,
+                                                               private ?string $userId) {
                parent::__construct($appName, $request);
-
-               $this->preview = $preview;
-               $this->root = $root;
-               $this->userId = $userId;
        }
 
        /**
index 6d1b856929ad141971bb350d9acf8c69d9726621..8fde293d5c95c07bb1a8774fd31d299fbbeaf5fa 100644 (file)
@@ -38,23 +38,12 @@ use OCP\IUserSession;
 use OC\Profile\ProfileManager;
 
 class ProfileApiController extends OCSController {
-       private ProfileConfigMapper $configMapper;
-       private ProfileManager $profileManager;
-       private IUserManager $userManager;
-       private IUserSession $userSession;
-
-       public function __construct(
-               IRequest $request,
-               ProfileConfigMapper $configMapper,
-               ProfileManager $profileManager,
-               IUserManager $userManager,
-               IUserSession $userSession
-       ) {
+       public function __construct(IRequest $request,
+                                                               private ProfileConfigMapper $configMapper,
+                                                               private ProfileManager $profileManager,
+                                                               private IUserManager $userManager,
+                                                               private IUserSession $userSession) {
                parent::__construct('core', $request);
-               $this->configMapper = $configMapper;
-               $this->profileManager = $profileManager;
-               $this->userManager = $userManager;
-               $this->userSession = $userSession;
        }
 
        /**
index 4b710911482e48d8573c743fdf916692c62d8d3f..3e9478ba65cccd3448a342bd51c56011332ebd25 100644 (file)
@@ -40,33 +40,16 @@ use OCP\UserStatus\IManager as IUserStatusManager;
 use OCP\EventDispatcher\IEventDispatcher;
 
 class ProfilePageController extends Controller {
-       private IInitialState $initialStateService;
-       private ProfileManager $profileManager;
-       private IShareManager $shareManager;
-       private IUserManager $userManager;
-       private IUserSession $userSession;
-       private IUserStatusManager $userStatusManager;
-       private IEventDispatcher $eventDispatcher;
-
-       public function __construct(
-               $appName,
-               IRequest $request,
-               IInitialState $initialStateService,
-               ProfileManager $profileManager,
-               IShareManager $shareManager,
-               IUserManager $userManager,
-               IUserSession $userSession,
-               IUserStatusManager $userStatusManager,
-               IEventDispatcher $eventDispatcher
-       ) {
+       public function __construct(string $appName,
+                                                               IRequest $request,
+                                                               private IInitialState $initialStateService,
+                                                               private ProfileManager $profileManager,
+                                                               private IShareManager $shareManager,
+                                                               private IUserManager $userManager,
+                                                               private IUserSession $userSession,
+                                                               private IUserStatusManager $userStatusManager,
+                                                               private IEventDispatcher $eventDispatcher) {
                parent::__construct($appName, $request);
-               $this->initialStateService = $initialStateService;
-               $this->profileManager = $profileManager;
-               $this->shareManager = $shareManager;
-               $this->userManager = $userManager;
-               $this->userSession = $userSession;
-               $this->userStatusManager = $userStatusManager;
-               $this->eventDispatcher = $eventDispatcher;
        }
 
        /**
index 5c73f3c5f5e766ac06e83f383f6e37e3d919652e..5c3d71012a71b445b2e78f21e18c048203f0e72e 100644 (file)
@@ -33,15 +33,10 @@ use OCP\IRequest;
 use OCP\IURLGenerator;
 
 class RecommendedAppsController extends Controller {
-       public IURLGenerator $urlGenerator;
-       private IInitialStateService $initialStateService;
-
        public function __construct(IRequest $request,
-                                                               IURLGenerator $urlGenerator,
-                                                               IInitialStateService $initialStateService) {
+                                                               public IURLGenerator $urlGenerator,
+                                                               private IInitialStateService $initialStateService) {
                parent::__construct('core', $request);
-               $this->urlGenerator = $urlGenerator;
-               $this->initialStateService = $initialStateService;
        }
 
        /**
index 6aba56d7e771652bd0080d320b37e74fe64c9de9..25d78e153e86f195a896b4266dd91e380411425d 100644 (file)
@@ -30,16 +30,11 @@ use OCP\Collaboration\Reference\IReferenceManager;
 use OCP\IRequest;
 
 class ReferenceApiController extends \OCP\AppFramework\OCSController {
-       private IReferenceManager $referenceManager;
-       private ?string $userId;
-
        public function __construct(string $appName,
                                                                IRequest $request,
-                                                               IReferenceManager $referenceManager,
-                                                               ?string $userId) {
+                                                               private IReferenceManager $referenceManager,
+                                                               private ?string $userId) {
                parent::__construct($appName, $request);
-               $this->referenceManager = $referenceManager;
-               $this->userId = $userId;
        }
 
        /**
index ae6aeeaa6cc5fc5d7d1ddaa5d55e4d8687e3d736..daebd89a94716994415fa80551eadc549ab8b07a 100644 (file)
@@ -36,13 +36,11 @@ use OCP\Files\NotPermittedException;
 use OCP\IRequest;
 
 class ReferenceController extends Controller {
-       private IReferenceManager $referenceManager;
-       private IAppDataFactory $appDataFactory;
-
-       public function __construct(string $appName, IRequest $request, IReferenceManager $referenceManager, IAppDataFactory $appDataFactory) {
+       public function __construct(string $appName,
+                                                               IRequest $request,
+                                                               private IReferenceManager $referenceManager,
+                                                               private IAppDataFactory $appDataFactory) {
                parent::__construct($appName, $request);
-               $this->referenceManager = $referenceManager;
-               $this->appDataFactory = $appDataFactory;
        }
 
        /**