mirror of
https://github.com/unraid/webgui.git
synced 2026-01-06 01:29:54 -06:00
refactor: improve ThemeHelper constructor by enforcing theme parameter and removing redundant initialization method
This commit is contained in:
@@ -41,15 +41,21 @@ class ThemeHelper {
|
||||
* @param '1'|null $width The width of the theme (optional)
|
||||
*/
|
||||
public function __construct(?string $theme = null, ?string $width = null) {
|
||||
if ($theme !== null) {
|
||||
$this->initWithCurrentThemeSetting($theme);
|
||||
if ($theme === null) {
|
||||
throw new \RuntimeException(self::INIT_ERROR);
|
||||
}
|
||||
|
||||
|
||||
$this->themeName = strtok($theme, '-');
|
||||
|
||||
$this->topNavTheme = in_array($this->themeName, self::TOP_NAV_THEMES);
|
||||
$this->sidebarTheme = in_array($this->themeName, self::SIDEBAR_THEMES);
|
||||
$this->darkTheme = in_array($this->themeName, self::DARK_THEMES);
|
||||
$this->lightTheme = in_array($this->themeName, self::LIGHT_THEMES);
|
||||
$this->fgcolor = self::FGCOLORS[$this->themeName] ?? self::COLOR_BLACK;
|
||||
|
||||
if ($width !== null) {
|
||||
$this->setWidth($width);
|
||||
}
|
||||
|
||||
throw new \RuntimeException(self::INIT_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,23 +77,6 @@ class ThemeHelper {
|
||||
return $this->unlimitedWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize theme properties
|
||||
*
|
||||
* @param string $theme The theme name
|
||||
* @return void
|
||||
*/
|
||||
public function initWithCurrentThemeSetting(string $theme): void {
|
||||
$this->themeName = strtok($theme, '-');
|
||||
|
||||
$this->topNavTheme = in_array($this->themeName, self::TOP_NAV_THEMES);
|
||||
$this->sidebarTheme = in_array($this->themeName, self::SIDEBAR_THEMES);
|
||||
$this->darkTheme = in_array($this->themeName, self::DARK_THEMES);
|
||||
$this->lightTheme = in_array($this->themeName, self::LIGHT_THEMES);
|
||||
|
||||
$this->fgcolor = self::FGCOLORS[$this->themeName] ?? self::COLOR_BLACK;
|
||||
}
|
||||
|
||||
public function getThemeName(): string {
|
||||
return $this->themeName;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user