From a9ab6f88c72dbe6b9acebc15263c1cf97bad0e84 Mon Sep 17 00:00:00 2001 From: Faraz Samapoor Date: Thu, 2 May 2024 11:02:10 +0330 Subject: [PATCH] refactor: Improves readability mainly by utilizing PHP8's constructor property promotion feature. Signed-off-by: Faraz Samapoor --- apps/theming/lib/Settings/Admin.php | 1 - apps/theming/lib/Settings/AdminSection.php | 25 +++++-------- apps/theming/lib/Settings/Personal.php | 1 - apps/theming/lib/Settings/PersonalSection.php | 36 +++++-------------- .../lib/SetupChecks/PhpImagickModule.php | 8 +++-- 5 files changed, 23 insertions(+), 48 deletions(-) diff --git a/apps/theming/lib/Settings/Admin.php b/apps/theming/lib/Settings/Admin.php index dc5d9a2a6a443..3e3a42a40c168 100644 --- a/apps/theming/lib/Settings/Admin.php +++ b/apps/theming/lib/Settings/Admin.php @@ -40,7 +40,6 @@ use OCP\Util; class Admin implements IDelegatedSettings { - public function __construct( private string $appName, private IConfig $config, diff --git a/apps/theming/lib/Settings/AdminSection.php b/apps/theming/lib/Settings/AdminSection.php index 2fcc81a927924..94138111c43de 100644 --- a/apps/theming/lib/Settings/AdminSection.php +++ b/apps/theming/lib/Settings/AdminSection.php @@ -27,33 +27,26 @@ use OCP\Settings\IIconSection; class AdminSection implements IIconSection { - private string $appName; - private IL10N $l; - private IURLGenerator $url; - - public function __construct(string $appName, IURLGenerator $url, IL10N $l) { - $this->appName = $appName; - $this->url = $url; - $this->l = $l; + public function __construct( + private string $appName, + private IURLGenerator $url, + private IL10N $l, + ) { } /** * returns the ID of the section. It is supposed to be a lower case string, * e.g. 'ldap' - * - * @returns string */ - public function getID() { + public function getID(): string { return $this->appName; } /** * returns the translated name as it should be displayed, e.g. 'LDAP / AD * integration'. Use the L10N service to translate it. - * - * @return string */ - public function getName() { + public function getName(): string { return $this->l->t('Theming'); } @@ -64,14 +57,14 @@ public function getName() { * * E.g.: 70 */ - public function getPriority() { + public function getPriority(): int { return 30; } /** * {@inheritdoc} */ - public function getIcon() { + public function getIcon(): string { return $this->url->imagePath($this->appName, 'app-dark.svg'); } } diff --git a/apps/theming/lib/Settings/Personal.php b/apps/theming/lib/Settings/Personal.php index f24aaa2f8f83f..8dd73edd4ae0a 100644 --- a/apps/theming/lib/Settings/Personal.php +++ b/apps/theming/lib/Settings/Personal.php @@ -36,7 +36,6 @@ use OCP\Util; class Personal implements ISettings { - public function __construct( protected string $appName, private string $userId, diff --git a/apps/theming/lib/Settings/PersonalSection.php b/apps/theming/lib/Settings/PersonalSection.php index bfaa8bcaa3273..b3b127e6d4218 100644 --- a/apps/theming/lib/Settings/PersonalSection.php +++ b/apps/theming/lib/Settings/PersonalSection.php @@ -28,39 +28,23 @@ use OCP\Settings\IIconSection; class PersonalSection implements IIconSection { - - /** @var string */ - protected $appName; - - /** @var IURLGenerator */ - private $urlGenerator; - - /** @var IL10N */ - private $l; - /** * Personal Section constructor. - * - * @param string $appName - * @param IURLGenerator $urlGenerator - * @param IL10N $l */ - public function __construct(string $appName, - IURLGenerator $urlGenerator, - IL10N $l) { - $this->appName = $appName; - $this->urlGenerator = $urlGenerator; - $this->l = $l; + public function __construct( + protected string $appName, + private IURLGenerator $urlGenerator, + private IL10N $l, + ) { } /** * returns the relative path to an 16*16 icon describing the section. * e.g. '/core/img/places/files.svg' * - * @returns string * @since 13.0.0 */ - public function getIcon() { + public function getIcon(): string { return $this->urlGenerator->imagePath($this->appName, 'accessibility-dark.svg'); } @@ -68,10 +52,9 @@ public function getIcon() { * returns the ID of the section. It is supposed to be a lower case string, * e.g. 'ldap' * - * @returns string * @since 9.1 */ - public function getID() { + public function getID(): string { return $this->appName; } @@ -79,10 +62,9 @@ public function getID() { * returns the translated name as it should be displayed, e.g. 'LDAP / AD * integration'. Use the L10N service to translate it. * - * @return string * @since 9.1 */ - public function getName() { + public function getName(): string { return $this->l->t('Appearance and accessibility'); } @@ -94,7 +76,7 @@ public function getName() { * E.g.: 70 * @since 9.1 */ - public function getPriority() { + public function getPriority(): int { return 15; } } diff --git a/apps/theming/lib/SetupChecks/PhpImagickModule.php b/apps/theming/lib/SetupChecks/PhpImagickModule.php index 7d08aa8e954a3..aec8506b6f8ba 100644 --- a/apps/theming/lib/SetupChecks/PhpImagickModule.php +++ b/apps/theming/lib/SetupChecks/PhpImagickModule.php @@ -51,13 +51,15 @@ public function run(): SetupResult { $this->l10n->t('The PHP module "imagick" is not enabled although the theming app is. For favicon generation to work correctly, you need to install and enable this module.'), $this->urlGenerator->linkToDocs('admin-php-modules') ); - } elseif (count(\Imagick::queryFormats('SVG')) === 0) { + } + + if (count(\Imagick::queryFormats('SVG')) === 0) { return SetupResult::info( $this->l10n->t('The PHP module "imagick" in this instance has no SVG support. For better compatibility it is recommended to install it.'), $this->urlGenerator->linkToDocs('admin-php-modules') ); - } else { - return SetupResult::success(); } + + return SetupResult::success(); } }