Skip to content

Commit

Permalink
refactor: Improves readability mainly by utilizing PHP8's constructor…
Browse files Browse the repository at this point in the history
… property promotion feature.

Signed-off-by: Faraz Samapoor <f.samapoor@gmail.com>
  • Loading branch information
fsamapoor committed May 2, 2024
1 parent cf319df commit a9ab6f8
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 48 deletions.
1 change: 0 additions & 1 deletion apps/theming/lib/Settings/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
use OCP\Util;

class Admin implements IDelegatedSettings {

public function __construct(
private string $appName,
private IConfig $config,
Expand Down
25 changes: 9 additions & 16 deletions apps/theming/lib/Settings/AdminSection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand All @@ -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');
}
}
1 change: 0 additions & 1 deletion apps/theming/lib/Settings/Personal.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
use OCP\Util;

class Personal implements ISettings {

public function __construct(
protected string $appName,
private string $userId,
Expand Down
36 changes: 9 additions & 27 deletions apps/theming/lib/Settings/PersonalSection.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,61 +28,43 @@
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');
}

/**
* 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;
}

/**
* 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');
}

Expand All @@ -94,7 +76,7 @@ public function getName() {
* E.g.: 70
* @since 9.1
*/
public function getPriority() {
public function getPriority(): int {
return 15;
}
}
8 changes: 5 additions & 3 deletions apps/theming/lib/SetupChecks/PhpImagickModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit a9ab6f8

Please sign in to comment.