refactor: improve ThemeHelper constructor by enforcing theme parameter and removing redundant initialization method

This commit is contained in:
Zack Spear
2025-04-07 14:05:09 -07:00
parent 274332456c
commit 7c408531bd

View File

@@ -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;
}