diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index fec73d7a93..e824d34d1c 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -7149,7 +7149,7 @@ parameters: Use dependency injection instead\.$# ''' identifier: staticMethod.deprecated - count: 3 + count: 4 path: src/Header.php - diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 0ed509b4bf..3c4069806f 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -4767,6 +4767,7 @@ + diff --git a/src/Header.php b/src/Header.php index 4ff4cf9da7..b1200d76c8 100644 --- a/src/Header.php +++ b/src/Header.php @@ -46,10 +46,10 @@ class Header * The value for the id attribute for the body tag */ private string $bodyId = ''; - /** - * Whether to show the top menu - */ - private bool $menuEnabled; + + /** Whether to show the top menu */ + private bool|null $isMenuEnabled = null; + /** * Whether to show the warnings */ @@ -65,7 +65,6 @@ class Header private readonly Config $config, ) { $dbi = DatabaseInterface::getInstance(); - $this->menuEnabled = $dbi->isConnected(); $relation = new Relation($dbi); $this->menu = new Menu($dbi, $this->template, $this->config, $relation, Current::$database, Current::$table); $this->scripts = new Scripts($this->template); @@ -74,6 +73,18 @@ class Header $this->userPreferences = new UserPreferences($dbi, $relation, $this->template); } + private function isMenuEnabled(): bool + { + if ($this->isMenuEnabled !== null) { + return $this->isMenuEnabled; + } + + $dbi = DatabaseInterface::getInstance(); + $this->isMenuEnabled = $dbi->isConnected(); + + return $this->isMenuEnabled; + } + /** * Loads common scripts */ @@ -193,7 +204,7 @@ class Header */ public function disableMenuAndConsole(): void { - $this->menuEnabled = false; + $this->isMenuEnabled = false; $this->console->disable(); } @@ -246,7 +257,7 @@ class Header $this->scripts->addFiles($this->console->getScripts()); $dbi = DatabaseInterface::getInstance(); - if ($this->menuEnabled && Current::$server > 0) { + if ($this->isMenuEnabled() && Current::$server > 0) { $navigation = (new Navigation($this->template, new Relation($dbi), $dbi, $this->config))->getDisplay(); } @@ -260,7 +271,7 @@ class Header $loadUserPreferences = $this->userPreferences->autoloadGetHeader(); } - if ($this->menuEnabled && Current::$server > 0) { + if ($this->isMenuEnabled() && Current::$server > 0) { $menu = $this->menu->getDisplay(); } @@ -284,7 +295,7 @@ class Header 'load_user_preferences' => $loadUserPreferences ?? '', 'show_hint' => $this->config->settings['ShowHint'], 'is_warnings_enabled' => $this->warningsEnabled, - 'is_menu_enabled' => $this->menuEnabled, + 'is_menu_enabled' => $this->isMenuEnabled(), 'is_logged_in' => $isLoggedIn, 'menu' => $menu ?? '', 'console' => $console,