From 5c9f030044e2ec0edf8b70d17d52b7a9ef85ce49 Mon Sep 17 00:00:00 2001 From: Claus-Justus Heine Date: Wed, 13 Mar 2024 09:41:27 +0100 Subject: [PATCH] Switch to CTOR property promotion --- lib/Controller/AuthenticationController.php | 19 ++-------- lib/Controller/PageController.php | 37 ++++--------------- lib/Controller/SettingsController.php | 20 +++------- .../LoadAdditionalScriptsEventListener.php | 8 +--- lib/Listener/UserLoggedOutEventListener.php | 8 +--- lib/Service/AssetService.php | 8 ++-- lib/Service/AuthDokuWiki.php | 31 +++------------- lib/Settings/Admin.php | 17 ++------- lib/Settings/AdminSection.php | 20 ++-------- 9 files changed, 38 insertions(+), 130 deletions(-) diff --git a/lib/Controller/AuthenticationController.php b/lib/Controller/AuthenticationController.php index 31d14c6..39fbb2a 100644 --- a/lib/Controller/AuthenticationController.php +++ b/lib/Controller/AuthenticationController.php @@ -3,7 +3,7 @@ * Nextcloud DokuWiki -- Embed DokuWiki into NextCloud with SSO. * * @author Claus-Justus Heine - * @copyright 2020, 2021, 2023 Claus-Justus Heine + * @copyright 2020-2024 Claus-Justus Heine * @license AGPL-3.0-or-later * * Nextcloud DokuWiki is free software: you can redistribute it and/or @@ -37,26 +37,15 @@ class AuthenticationController extends Controller { use \OCA\DokuWiki\Toolkit\Traits\LoggerTrait; - /** @var Authenticator */ - private $authenticator; - - /** @var string */ - private $userId; - // phpcs:disable Squiz.Commenting.FunctionComment.Missing public function __construct( string $appName, IRequest $request, - ?string $userId, - Authenticator $authenticator, - ILogger $logger, - IL10N $l10n, + private ?string $userId, + private Authenticator $authenticator, + protected ILogger $logger, ) { parent::__construct($appName, $request); - $this->userId = $userId; - $this->authenticator = $authenticator; - $this->logger = $logger; - $this->l = $l10n; } // phpcs:enable Squiz.Commenting.FunctionComment.Missing diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index d6c6f51..86310f2 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -3,7 +3,7 @@ * Nextcloud DokuWiki -- Embed DokuWiki into NextCloud with SSO. * * @author Claus-Justus Heine - * @copyright 2020, 2021, 2023 Claus-Justus Heine + * @copyright 2020-2024 Claus-Justus Heine * @license AGPL-3.0-or-later * * Nextcloud DokuWiki is free software: you can redistribute it and/or @@ -49,42 +49,19 @@ class PageController extends Controller const TEMPLATE = 'doku-wiki'; const ASSET = 'app'; - /** @var Authenticator */ - private $authenticator; - - /** @var AssetService */ - private $assetService; - - /** @var IConfig */ - private $config; - - /** @var IURLGenerator */ - private $urlGenerator; - - /** @var IInitialState */ - private $initialState; - // phpcs:disable Squiz.Commenting.FunctionComment.Missing public function __construct( string $appName, IRequest $request, - Authenticator $authenticator, - AssetService $assetService, - IConfig $config, - IURLGenerator $urlGenerator, - IInitialState $initialState, - ILogger $logger, - IL10N $l10n, + private Authenticator $authenticator, + private AssetService $assetService, + private IConfig $config, + private IURLGenerator $urlGenerator, + private IInitialState $initialState, + protected ILogger $logger, ) { parent::__construct($appName, $request); - $this->authenticator = $authenticator; $this->authenticator->errorReporting(Authenticator::ON_ERROR_THROW); - $this->assetService = $assetService; - $this->config = $config; - $this->urlGenerator = $urlGenerator; - $this->initialState = $initialState; - $this->logger = $logger; - $this->l = $l10n; } // phpcs:enable Squiz.Commenting.FunctionComment.Missing diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index 4d2b31b..3b89924 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -3,7 +3,7 @@ * Nextcloud DokuWiki -- Embed DokuWiki into NextCloud with SSO. * * @author Claus-Justus Heine - * @copyright 2020, 2021, 2022, 2023 Claus-Justus Heine + * @copyright 2020-2024 Claus-Justus Heine * @license AGPL-3.0-or-later * * Nextcloud DokuWiki is free software: you can redistribute it and/or @@ -71,26 +71,16 @@ class SettingsController extends Controller ], ]; - /** @var IConfig */ - private $config; - - /** @var IURLGenerator */ - private $urlGenerator; - // phpcs:ignore Squiz.Commenting.FunctionComment.Missing public function __construct( string $appName, IRequest $request, - LoggerInterface $logger, - IURLGenerator $urlGenerator, - IL10N $l10n, - IConfig $config, + protected LoggerInterface $logger, + private IURLGenerator $urlGenerator, + protected IL10N $l, + private IConfig $config, ) { parent::__construct($appName, $request); - $this->logger = $logger; - $this->urlGenerator = $urlGenerator; - $this->l = $l10n; - $this->config = $config; } // phpcs:enable diff --git a/lib/Listener/LoadAdditionalScriptsEventListener.php b/lib/Listener/LoadAdditionalScriptsEventListener.php index 76a91d3..f3ce87c 100644 --- a/lib/Listener/LoadAdditionalScriptsEventListener.php +++ b/lib/Listener/LoadAdditionalScriptsEventListener.php @@ -47,21 +47,15 @@ class LoadAdditionalScriptsEventListener implements IEventListener const EVENT = HandledEvent::class; - /** @var IAppContainer */ - private $appContainer; - // phpcs:disable Squiz.Commenting.FunctionComment.Missing - public function __construct(IAppContainer $appContainer) + public function __construct(private IAppContainer $appContainer) { - $this->appContainer = $appContainer; - $this->logger = $this->appContainer->get(ILogger::class); } // phpcs:enable Squiz.Commenting.FunctionComment.Missing /** {@inheritdoc} */ public function handle(Event $event):void { - $this->logger = $this->appContainer->get(ILogger::class); if (!($event instanceof HandledEvent)) { return; } diff --git a/lib/Listener/UserLoggedOutEventListener.php b/lib/Listener/UserLoggedOutEventListener.php index dc450ea..af18903 100644 --- a/lib/Listener/UserLoggedOutEventListener.php +++ b/lib/Listener/UserLoggedOutEventListener.php @@ -3,7 +3,7 @@ * Nextcloud DokuWiki -- Embed DokuWiki into NextCloud with SSO. * * @author Claus-Justus Heine - * @copyright 2020, 2021, 2022, 2023, 2023 Claus-Justus Heine + * @copyright 2020-2024 Claus-Justus Heine * @license AGPL-3.0-or-later * * Nextcloud DokuWiki is free software: you can redistribute it and/or @@ -43,13 +43,9 @@ class UserLoggedOutEventListener implements IEventListener const EVENT = HandledEvent::class; - /** @var IAppContainer */ - private $appContainer; - // phpcs:disable Squiz.Commenting.FunctionComment.Missing - public function __construct(IAppContainer $appContainer) + public function __construct(private IAppContainer $appContainer) { - $this->appContainer = $appContainer; } // phpcs:enable Squiz.Commenting.FunctionComment.Missing diff --git a/lib/Service/AssetService.php b/lib/Service/AssetService.php index ebe3ad9..271455b 100644 --- a/lib/Service/AssetService.php +++ b/lib/Service/AssetService.php @@ -1,7 +1,7 @@ - * @copyright 2021, 2022, 2023 Claus-Justus Heine + * @copyright 2021-2024 Claus-Justus Heine * @license AGPL-3.0-or-later * * This program is free software: you can redistribute it and/or modify @@ -41,8 +41,10 @@ class AssetService const CSS = Constants::CSS; // phpcs:disable Squiz.Commenting.FunctionComment.Missing - public function __construct(IL10N $l10n, LoggerInterface $logger) - { + public function __construct( + protected IL10N $l10n, + protected LoggerInterface $logger, + ) { $this->logger = $logger; $this->l = $l10n; $this->initializeAssets(__DIR__); diff --git a/lib/Service/AuthDokuWiki.php b/lib/Service/AuthDokuWiki.php index cee1c92..642b071 100644 --- a/lib/Service/AuthDokuWiki.php +++ b/lib/Service/AuthDokuWiki.php @@ -3,7 +3,7 @@ * Nextcloud DokuWiki -- Embed DokuWiki into NextCloud with SSO. * * @author Claus-Justus Heine - * @copyright 2020, 2021, 2022, 2023 Claus-Justus Heine + * @copyright 2020-2024 Claus-Justus Heine * @license AGPL-3.0-or-later * * Nextcloud DokuWiki is free software: you can redistribute it and/or @@ -65,18 +65,6 @@ class AuthDokuWiki /** @var string */ private $appName; - /** @var IConfig */ - private $config; - - /** @var IRequest */ - private $request; - - /** @var \OCP\IURLGeneator */ - private $urlGenerator; - - /** @var \OCP\Authentication\LoginCredentials\IStore */ - private $credentialsStore; - private $dwProto = null; private $dwHost = null; private $dwPort = null; @@ -103,20 +91,13 @@ class AuthDokuWiki // phpcs:disable Squiz.Commenting.FunctionComment.Missing public function __construct( Application $app, - IConfig $config, - IRequest $request, - ICredentialsStore $credentialsStore, - IURLGenerator $urlGenerator, - ILogger $logger, - IL10N $l10n, + private IConfig $config, + private IRequest $request, + private ICredentialsStore $credentialsStore, + private IURLGenerator $urlGenerator, + protected ILogger $logger, ) { $this->appName = $app->getAppName(); - $this->config = $config; - $this->request = $request; - $this->credentialsStore = $credentialsStore; - $this->urlGenerator = $urlGenerator; - $this->logger = $logger; - $this->l = $l10n; $this->errorReporting = self::ON_ERROR_RETURN; diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php index b4e70fc..8684a5a 100644 --- a/lib/Settings/Admin.php +++ b/lib/Settings/Admin.php @@ -3,7 +3,7 @@ * Nextcloud DokuWiki -- Embed DokuWiki into NextCloud with SSO. * * @author Claus-Justus Heine - * @copyright 2020, 2021, 2022, 2023 Claus-Justus Heine + * @copyright 2020-2024 Claus-Justus Heine * @license AGPL-3.0-or-later * * Nextcloud DokuWiki is free software: you can redistribute it and/or @@ -37,21 +37,12 @@ class Admin implements IDelegatedSettings const TEMPLATE = 'admin-settings'; const ASSET_NAME = 'admin-settings'; - /** @var IConfig */ - private $config; - - /** @var AssetService */ - private $assetService; - // phpcs:disable Squiz.Commenting.FunctionComment.Missing public function __construct( - string $appName, - IConfig $config, - AssetService $assetService, + private string $appName, + private IConfig $config, + private AssetService $assetService, ) { - $this->appName = $appName; - $this->config = $config; - $this->assetService = $assetService; } // phpcs:enable Squiz.Commenting.FunctionComment.Missing diff --git a/lib/Settings/AdminSection.php b/lib/Settings/AdminSection.php index f3e2137..86e486c 100644 --- a/lib/Settings/AdminSection.php +++ b/lib/Settings/AdminSection.php @@ -3,7 +3,7 @@ * Nextcloud DokuWiki -- Embed DokuWiki into NextCloud with SSO. * * @author Claus-Justus Heine - * @copyright 2020, 2021, 2023 Claus-Justus Heine + * @copyright 2020, 2021, 2023, 2024 Claus-Justus Heine * @license AGPL-3.0-or-later * * Nextcloud DokuWiki is free software: you can redistribute it and/or @@ -30,24 +30,12 @@ /** Admin settings section. */ class AdminSection implements IIconSection { - /** @var string */ - private $appName; - - /** @var \OCP\IURLGenerator */ - private $urlGenerator; - - /** @var \OCP\IL10N */ - private $l; - // phpcs:disable Squiz.Commenting.FunctionComment.Missing public function __construct( - string $appName, - IURLGenerator $urlGenerator, - IL10N $l10n, + private string $appName, + private IURLGenerator $urlGenerator, + private IL10N $l, ) { - $this->appName = $appName; - $this->urlGenerator = $urlGenerator; - $this->l = $l10n; } // phpcs:enable Squiz.Commenting.FunctionComment.Missing