diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..f4da20891502a3992abf2981d8f6c46e33868ab6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +tools/ +phpstan.neon +.phpunit.result.cache +phpunit.xml \ No newline at end of file diff --git a/.phive/phars.xml b/.phive/phars.xml new file mode 100644 index 0000000000000000000000000000000000000000..a1315a09b4adad780a9c5e52f74835c708c5c7d5 --- /dev/null +++ b/.phive/phars.xml @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8"?> +<phive xmlns="https://phar.io/phive"> + <phar name="phpstan" version="^1.10.67" installed="1.10.67" location="./tools/phpstan" copy="false"/> +</phive> diff --git a/ajax/backend/independent/create.php b/ajax/backend/independent/create.php index f27e53cc16e2e3bb2ba544c38434cbd02f20faaf..afac51909c29858adf9fc2258411698eb5e2f885 100644 --- a/ajax/backend/independent/create.php +++ b/ajax/backend/independent/create.php @@ -12,13 +12,16 @@ * * @return array */ + +use QUI\Menu\Independent\Factory; + QUI::$Ajax->registerFunction( 'package_quiqqer_menu_ajax_backend_independent_create', function ($title, $workingTitle) { $title = json_decode($title, true); $workingTitle = json_decode($workingTitle, true); - $Menu = \QUI\Menu\Independent\Factory::createMenu(); + $Menu = Factory::createMenu(); $Menu->setTitle($title); $Menu->setWorkingTitle($workingTitle); $Menu->save(); diff --git a/ajax/backend/independent/get.php b/ajax/backend/independent/get.php index a06cd8588a68c981cd9b1ac2ddff9056abcbad1d..cc4300de799306547a86e4d1bc6434b9057e303f 100644 --- a/ajax/backend/independent/get.php +++ b/ajax/backend/independent/get.php @@ -4,6 +4,8 @@ * This file contains package_quiqqer_menu_ajax_backend_independent_get */ +use QUI\Menu\Independent\Items\AbstractMenuItem; + QUI::$Ajax->registerFunction( 'package_quiqqer_menu_ajax_backend_independent_get', function ($id) { @@ -21,7 +23,7 @@ function parseChildren(&$data) continue; } - /* @var $Item \QUI\Menu\Independent\Items\AbstractMenuItem */ + /* @var $Item AbstractMenuItem */ $Item = new $entry['type']($entry); $icon = QUI\Menu\Independent\Items\Site::itemIcon(); // default diff --git a/ajax/backend/independent/getItemName.php b/ajax/backend/independent/getItemName.php index 7fe6a6e6a25f6906e7b429162458e75f5ec9894c..5d4ec02acce63eee00b1b3959c7953d76f48facd 100644 --- a/ajax/backend/independent/getItemName.php +++ b/ajax/backend/independent/getItemName.php @@ -7,6 +7,9 @@ /** * Return the item name */ + +use QUI\Menu\Independent\Items\AbstractMenuItem; + QUI::$Ajax->registerFunction( 'package_quiqqer_menu_ajax_backend_independent_getItemName', function ($item) { @@ -16,7 +19,7 @@ function ($item) { return ''; } - /* @var $Item \QUI\Menu\Independent\Items\AbstractMenuItem */ + /* @var $Item AbstractMenuItem */ $Item = new $item['type']($item); return $Item->getName(); }, diff --git a/ajax/backend/independent/getItemTitle.php b/ajax/backend/independent/getItemTitle.php index 97e6a5ce0d3ef1b7dd7942f84495e06c5f8bf110..ba0e957cdbd81fa5f5710c8519f438f201e5dc5f 100644 --- a/ajax/backend/independent/getItemTitle.php +++ b/ajax/backend/independent/getItemTitle.php @@ -7,6 +7,9 @@ /** * Return the item name */ + +use QUI\Menu\Independent\Items\AbstractMenuItem; + QUI::$Ajax->registerFunction( 'package_quiqqer_menu_ajax_backend_independent_getItemTitle', function ($item) { @@ -16,7 +19,7 @@ function ($item) { return ''; } - /* @var $Item \QUI\Menu\Independent\Items\AbstractMenuItem */ + /* @var $Item AbstractMenuItem */ $Item = new $item['type']($item); return $Item->getTitle(); }, diff --git a/composer.json b/composer.json index c344b8cf5705870428a316ad810c35955b983f99..bf6130980ce9750f00550504981b2c0d3189570a 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "quiqqer\/menu", + "name": "quiqqer/menu", "type": "quiqqer-module", "description": "The Plugin menu provides various menu controls.", "license": [ @@ -10,21 +10,21 @@ { "name": "Henning Leutz", "email": "leutz@pcsg.de", - "homepage": "http:\/\/www.pcsg.de", + "homepage": "https://www.pcsg.de", "role": "Developer" } ], "support": { "email": "support@pcsg.de", - "url": "http:\/\/www.pcsg.de" + "url": "https://www.pcsg.de" }, "require": { - "php": ">=5.3", - "quiqqer\/quiqqer": "*@dev" + "php": "^8.1", + "quiqqer/core": "^2" }, "autoload": { "psr-4": { - "QUI\\Menu\\": "src\/QUI\/Menu" + "QUI\\Menu\\": "src/QUI/Menu" } } } \ No newline at end of file diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/phpstan.dist.neon b/phpstan.dist.neon new file mode 100644 index 0000000000000000000000000000000000000000..a545a041a3c5b0c758d99bf8c1c49b2a83252eaa --- /dev/null +++ b/phpstan.dist.neon @@ -0,0 +1,10 @@ +includes: + - phpstan-baseline.neon + +parameters: + level: 1 + paths: + - src + - ajax + bootstrapFiles: + - tests/phpstan-bootstrap.php \ No newline at end of file diff --git a/src/QUI/Menu/AbstractMenu.php b/src/QUI/Menu/AbstractMenu.php index bd5d7946c37d4b255e968c70e85169a3cf27bc74..5962d088e2f8e57cacf10c3ce668ebd22cca49fb 100644 --- a/src/QUI/Menu/AbstractMenu.php +++ b/src/QUI/Menu/AbstractMenu.php @@ -15,12 +15,12 @@ abstract class AbstractMenu extends QUI\Control /** * @var string */ - protected $append = ''; + protected string $append = ''; /** * @var string */ - protected $prepend = ''; + protected string $prepend = ''; /** * append html to the menu @@ -28,7 +28,7 @@ abstract class AbstractMenu extends QUI\Control * * @param string $html */ - public function appendHTML($html) + public function appendHTML(string $html): void { $this->append = $html; } @@ -39,7 +39,7 @@ public function appendHTML($html) * * @param string $html */ - public function prependHTML($html) + public function prependHTML(string $html): void { $this->prepend = $html; } diff --git a/src/QUI/Menu/Controls/FloatedNav.php b/src/QUI/Menu/Controls/FloatedNav.php index 556c9cb87024a31e07996dbf6e5824ac773c5450..6944a3ead5171fd939730310cb37d3e56fd4537c 100644 --- a/src/QUI/Menu/Controls/FloatedNav.php +++ b/src/QUI/Menu/Controls/FloatedNav.php @@ -21,7 +21,7 @@ class FloatedNav extends QUI\Control * * @param array $attributes */ - public function __construct($attributes = []) + public function __construct(array $attributes = []) { // default options $this->setAttributes([ @@ -60,7 +60,7 @@ public function __construct($attributes = []) * * @see \QUI\Control::create() */ - public function getBody() + public function getBody(): string { $Engine = QUI::getTemplateManager()->getEngine(); $LangSwitch = null; @@ -73,11 +73,8 @@ public function getBody() return ''; } - if (!$IndependentMenu) { - return ''; - } - $showToggleButton = true; + switch ($this->getAttribute('showToggleButton')) { case 'always': $this->setJavaScriptControlOption('showtogglebutton', 'always'); @@ -94,26 +91,15 @@ public function getBody() break; } - switch ($this->getAttribute('size')) { - case 'small': - case 'medium': - case 'large': - $size = 'quiqqer-floatedNavControl__size-' . $this->getAttribute('size'); - break; - - default: - $size = 'quiqqer-floatedNavControl__size-medium'; - } - - switch ($this->getAttribute('design')) { - case 'flat': - $design = 'quiqqer-floatedNavControl__design-' . $this->getAttribute('design'); - break; + $size = match ($this->getAttribute('size')) { + 'small', 'medium', 'large' => 'quiqqer-floatedNavControl__size-' . $this->getAttribute('size'), + default => 'quiqqer-floatedNavControl__size-medium', + }; - case 'iconBar': - default: - $design = 'quiqqer-floatedNavControl__design-iconsBar'; - } + $design = match ($this->getAttribute('design')) { + 'flat' => 'quiqqer-floatedNavControl__design-' . $this->getAttribute('design'), + default => 'quiqqer-floatedNavControl__design-iconsBar', + }; switch ($this->getAttribute('posX')) { case 'left': @@ -130,14 +116,10 @@ public function getBody() } if ($this->getAttribute('showLangSwitch')) { - try { - $LangSwitch = new QUI\Bricks\Controls\LanguageSwitches\Flags([ - 'showFlags' => 0, - 'class' => 'quiqqer-floatedNav-entry' - ]); - } catch (QUI\Exception $Exception) { - QUI\System\Log::writeException($Exception); - } + $LangSwitch = new QUI\Bricks\Controls\LanguageSwitches\Flags([ + 'showFlags' => 0, + 'class' => 'quiqqer-floatedNav-entry' + ]); } $animation = ''; @@ -187,7 +169,7 @@ public function getBody() * * @return false|mixed|string */ - public function getAnimationEasingName() + public function getAnimationEasingName(): mixed { switch ($this->getAttribute('animationEasing')) { case 'easeInQuad': diff --git a/src/QUI/Menu/Controls/Tabs.php b/src/QUI/Menu/Controls/Tabs.php index bf151d991b4f0546877a213d49453f2552fe5bc8..83efc05bc1ec5b8f3c4c5d92616f79bf8f1e7f35 100644 --- a/src/QUI/Menu/Controls/Tabs.php +++ b/src/QUI/Menu/Controls/Tabs.php @@ -21,7 +21,7 @@ class Tabs extends QUI\Control * * @param array $attributes */ - public function __construct($attributes = []) + public function __construct(array $attributes = []) { // default options $this->setAttributes([ @@ -63,7 +63,7 @@ public function __construct($attributes = []) * * @see \QUI\Control::create() */ - public function getBody() + public function getBody(): string { $Engine = QUI::getTemplateManager()->getEngine(); $entries = $this->getAttribute('entries'); @@ -78,7 +78,7 @@ public function getBody() continue; } - array_push($enabledEntries, $entry); + $enabledEntries[] = $entry; } $active = 1; diff --git a/src/QUI/Menu/DropDownMenu.php b/src/QUI/Menu/DropDownMenu.php index 32290394a614a0db098677e4eb1d5e6831424240..9b65eecd33709ea721644a38fb8fe5fe5290f58c 100644 --- a/src/QUI/Menu/DropDownMenu.php +++ b/src/QUI/Menu/DropDownMenu.php @@ -7,10 +7,18 @@ namespace QUI\Menu; use QUI; +use QUI\Exception; +use QUI\Interfaces\Projects\Site; + +use function array_filter; +use function dirname; +use function is_object; +use function md5; +use function serialize; /** * Class DropDownMenu - * Creates an Drop Down Menu + * Creates a Drop-Down Menu * * @package QUI\Menu * @author www.pcsg.de (Henning Leutz) @@ -20,7 +28,7 @@ class DropDownMenu extends QUI\Control /** * @param array $attributes */ - public function __construct($attributes = []) + public function __construct(array $attributes = []) { $this->setAttribute('class', 'qui-menu-dropdown'); $this->setAttribute('qui-class', 'package/quiqqer/menu/bin/DropDownMenu'); @@ -28,7 +36,7 @@ public function __construct($attributes = []) parent::__construct($attributes); - $this->addCSSFile(\dirname(__FILE__) . '/DropDownMenu.css'); + $this->addCSSFile(dirname(__FILE__) . '/DropDownMenu.css'); } /** @@ -37,23 +45,23 @@ public function __construct($attributes = []) * @return string * @throws QUI\Exception */ - public function getBody() + public function getBody(): string { $cache = EventHandler::menuCacheName() . '/dropDownMenu/'; $attributes = $this->getAttributes(); - $attributes = \array_filter($attributes, function ($entry) { - return \is_object($entry) === false; + $attributes = array_filter($attributes, function ($entry) { + return is_object($entry) === false; }); - $cache .= \md5( + $cache .= md5( $this->getSite()->getCachePath() . - \serialize($attributes) + serialize($attributes) ); try { return QUI\Cache\Manager::get($cache); - } catch (QUI\Exception $Exception) { + } catch (QUI\Exception) { } $Engine = QUI::getTemplateManager()->getEngine(); @@ -62,10 +70,10 @@ public function getBody() 'this' => $this, 'Site' => $this->getSite(), 'Project' => $this->getProject(), - 'FileMenu' => \dirname(__FILE__) . '/DropDownMenu.Children.html' + 'FileMenu' => dirname(__FILE__) . '/DropDownMenu.Children.html' ]); - $result = $Engine->fetch(\dirname(__FILE__) . '/DropDownMenu.html'); + $result = $Engine->fetch(dirname(__FILE__) . '/DropDownMenu.html'); QUI\Cache\Manager::set($cache, $result); @@ -75,9 +83,10 @@ public function getBody() /** * Return the current site * - * @return mixed|QUI\Projects\Site + * @return Site + * @throws Exception */ - protected function getSite() + protected function getSite(): QUI\Interfaces\Projects\Site { if ($this->getAttribute('Site')) { return $this->getAttribute('Site'); diff --git a/src/QUI/Menu/Elastic.php b/src/QUI/Menu/Elastic.php index a601ae761d8e2675343522b53816f69cb7f5fa54..de25cdf35efb47168f0fc15a1606b28c16b6c0f8 100644 --- a/src/QUI/Menu/Elastic.php +++ b/src/QUI/Menu/Elastic.php @@ -6,6 +6,7 @@ namespace QUI\Menu; +use Exception; use QUI; /** @@ -20,7 +21,7 @@ class Elastic extends QUI\Control /** * @param array $attributes */ - public function __construct($attributes = []) + public function __construct(array $attributes = []) { parent::__construct($attributes); } @@ -28,8 +29,9 @@ public function __construct($attributes = []) /** * @return string * @throws QUI\Exception + * @throws Exception */ - public function getBody() + public function getBody(): string { $Engine = QUI::getTemplateManager()->getEngine(); @@ -48,8 +50,9 @@ public function getBody() * Return the current site * * @return mixed|QUI\Projects\Site + * @throws QUI\Exception */ - protected function getSite() + protected function getSite(): mixed { if ($this->getAttribute('Site')) { return $this->getAttribute('Site'); diff --git a/src/QUI/Menu/EventHandler.php b/src/QUI/Menu/EventHandler.php index 41ef14b0c30cb3a9218b33820ff2a65b88a6fe7d..cf6ae9c3c928901e6725eb86984185225e1d9d28 100644 --- a/src/QUI/Menu/EventHandler.php +++ b/src/QUI/Menu/EventHandler.php @@ -25,7 +25,7 @@ public static function menuCacheName(): string /** * @param Site $Site */ - public static function onSiteSave(Site $Site) + public static function onSiteSave(Site $Site): void { QUI\Cache\Manager::clear(self::menuCacheName()); } @@ -35,7 +35,7 @@ public static function onSiteSave(Site $Site) * * @return void */ - public static function onProjectConfigSave() + public static function onProjectConfigSave(): void { QUI\Cache\Manager::clear(self::menuCacheName()); } @@ -47,7 +47,7 @@ public static function onProjectConfigSave() * @param Smarty $Smarty * @throws SmartyException */ - public static function onSmartyInit(Smarty $Smarty) + public static function onSmartyInit(Smarty $Smarty): void { if ( !isset($Smarty->registered_plugins['function']) @@ -62,7 +62,7 @@ public static function onSmartyInit(Smarty $Smarty) * * @return void */ - public static function onAdminLoadFooter() + public static function onAdminLoadFooter(): void { $jsFile = URL_OPT_DIR . 'quiqqer/menu/bin/onAdminLoadFooter.js'; echo '<script src="' . $jsFile . '" async></script>'; @@ -72,7 +72,7 @@ public static function onAdminLoadFooter() * @param $menuId * @return void */ - public static function onQuiqqerMenuIndependentClear($menuId) + public static function onQuiqqerMenuIndependentClear($menuId): void { QUI\Cache\Manager::clear(self::menuCacheName()); } diff --git a/src/QUI/Menu/Independent/Factory.php b/src/QUI/Menu/Independent/Factory.php index 51f89e5aa13f103a3a749dda1ec13825be101513..884af3be92d3b77ae6ff4a0569615edfbd2c7ac5 100644 --- a/src/QUI/Menu/Independent/Factory.php +++ b/src/QUI/Menu/Independent/Factory.php @@ -2,6 +2,7 @@ namespace QUI\Menu\Independent; +use Exception; use QUI; /** @@ -29,7 +30,7 @@ public static function createMenu(): Menu try { QUI::getEvents()->fireEvent('quiqqerMenuIndependentCreate', [$Menu]); - } catch (\Exception $Exception) { + } catch (Exception $Exception) { QUI\System\Log::writeException($Exception); } @@ -42,7 +43,7 @@ public static function createMenu(): Menu * @throws QUI\Database\Exception * @throws QUI\Permissions\Exception */ - public static function deleteMenu(int $menuId) + public static function deleteMenu(int $menuId): void { QUI\Permissions\Permission::checkPermission('quiqqer.menu.delete'); @@ -52,7 +53,7 @@ public static function deleteMenu(int $menuId) try { QUI::getEvents()->fireEvent('quiqqerMenuIndependentDelete', [$menuId]); - } catch (\Exception $Exception) { + } catch (Exception $Exception) { QUI\System\Log::writeException($Exception); } } diff --git a/src/QUI/Menu/Independent/Handler.php b/src/QUI/Menu/Independent/Handler.php index e1b357bf2223af561e92f38a6b45300fa70c6dfa..8e7668785d4fe2c26fc39b535c0b034fba6c8a8e 100644 --- a/src/QUI/Menu/Independent/Handler.php +++ b/src/QUI/Menu/Independent/Handler.php @@ -36,7 +36,7 @@ public static function getMenu(int $menuId): Menu * @param QUI\Projects\Project|null $Project * @return string */ - public static function getMenuCacheName($menuId = false, QUI\Projects\Project $Project = null): string + public static function getMenuCacheName(bool|int $menuId = false, QUI\Projects\Project $Project = null): string { if ($Project) { $project = $Project->getName(); diff --git a/src/QUI/Menu/Independent/Items/AbstractMenuItem.php b/src/QUI/Menu/Independent/Items/AbstractMenuItem.php index 4cfe8b03a1f8763ed1e5bd562d76545c76e97940..c8317f63c1fb05cb9a3d50e21d4a231150077e46 100644 --- a/src/QUI/Menu/Independent/Items/AbstractMenuItem.php +++ b/src/QUI/Menu/Independent/Items/AbstractMenuItem.php @@ -112,7 +112,7 @@ public function getName(Locale $Locale = null): string /** * alias for name - * - can be use for the `a title=""` attribute + * - can be used for the `a title=""` attribute * * @param Locale|null $Locale * @return string @@ -209,7 +209,7 @@ public function getMenuType(): string /** * @return mixed */ - public function getCustomData() + public function getCustomData(): mixed { if (isset($this->attributes['data'])) { return $this->attributes['data']; @@ -352,7 +352,7 @@ public function getChildren(bool $onlyActive = true): array * * @param AbstractMenuItem $Item */ - public function appendChild(AbstractMenuItem $Item) + public function appendChild(AbstractMenuItem $Item): void { $this->children[] = $Item; } diff --git a/src/QUI/Menu/Independent/Items/Anchor.php b/src/QUI/Menu/Independent/Items/Anchor.php index 79dac31f3f4c2107ac303c09e82e6c10ad41d296..62c179556ac9e280e5cc6c047741e01b06d274ba 100644 --- a/src/QUI/Menu/Independent/Items/Anchor.php +++ b/src/QUI/Menu/Independent/Items/Anchor.php @@ -35,7 +35,7 @@ public function getUrl(): string if ($Site) { try { $url .= $Site->getUrlRewritten(); - } catch (QUI\Exception $Exception) { + } catch (QUI\Exception) { } } @@ -66,7 +66,7 @@ public function getSite(): ?QUI\Projects\Site try { $siteUrl = $data['site']; $Site = QUI\Projects\Site\Utils::getSiteByLink($siteUrl); - } catch (QUI\Exception $Exception) { + } catch (QUI\Exception) { return null; } @@ -79,7 +79,7 @@ public function getSite(): ?QUI\Projects\Site $langId = $Site->getId($current); $LangProject = QUI::getProject($Project->getName(), $current); return $LangProject->get($langId); - } catch (QUI\Exception $exception) { + } catch (QUI\Exception) { return null; } } diff --git a/src/QUI/Menu/Independent/Items/Site.php b/src/QUI/Menu/Independent/Items/Site.php index 884fa312460ae272d59dc6f2e58e2bbc545fa2a1..3d49d1243b7e1ce8d91ef04ae28575a5188cc399 100644 --- a/src/QUI/Menu/Independent/Items/Site.php +++ b/src/QUI/Menu/Independent/Items/Site.php @@ -58,7 +58,7 @@ public function getSite(): ?QUI\Projects\Site try { $siteUrl = $data['site']; $Site = QUI\Projects\Site\Utils::getSiteByLink($siteUrl); - } catch (QUI\Exception $Exception) { + } catch (QUI\Exception) { return null; } @@ -72,7 +72,7 @@ public function getSite(): ?QUI\Projects\Site $LangProject = QUI::getProject($Project->getName(), $current); return $LangProject->get($langId); - } catch (QUI\Exception $exception) { + } catch (QUI\Exception) { return null; } } @@ -136,7 +136,7 @@ public function getTitle(QUI\Locale $Locale = null): string $Site = QUI\Projects\Site\Utils::getSiteByLink($siteUrl); return $Site->getAttribute('title'); - } catch (QUI\Exception $Exception) { + } catch (QUI\Exception) { } return ''; @@ -152,7 +152,7 @@ public function getUrl(): string if ($Site) { try { return $Site->getUrlRewritten(); - } catch (QUI\Exception $Exception) { + } catch (QUI\Exception) { return ''; } } diff --git a/src/QUI/Menu/Independent/Menu.php b/src/QUI/Menu/Independent/Menu.php index efc156a3fbef91d97fdad11e34c182784e02024e..9f9d1dfc347defcb715128cd18afa4ba973e7cde 100644 --- a/src/QUI/Menu/Independent/Menu.php +++ b/src/QUI/Menu/Independent/Menu.php @@ -2,6 +2,7 @@ namespace QUI\Menu\Independent; +use Exception; use QUI; use QUI\Menu\Independent\Items\AbstractMenuItem; @@ -33,7 +34,7 @@ class Menu * @throws QUI\Exception * @throws QUI\Database\Exception */ - public function __construct($menuId) + public function __construct(int|array $menuId) { if (is_numeric($menuId)) { $data = Handler::getMenuData($menuId); @@ -92,7 +93,7 @@ public function __construct($menuId) * @param array $children * @return void */ - protected function buildChildren($Parent, array $children) + protected function buildChildren(AbstractMenuItem|Menu $Parent, array $children): void { foreach ($children as $item) { $type = $item['type']; @@ -124,7 +125,7 @@ protected function buildChildren($Parent, array $children) * * @param AbstractMenuItem $Item */ - public function appendChild(AbstractMenuItem $Item) + public function appendChild(AbstractMenuItem $Item): void { $this->children[] = $Item; } @@ -244,7 +245,7 @@ public function getData(): array * @throws QUI\Database\Exception * @throws QUI\Permissions\Exception */ - public function save(?QUI\Interfaces\Users\User $PermissionUser = null) + public function save(?QUI\Interfaces\Users\User $PermissionUser = null): void { QUI\Permissions\Permission::checkPermission('quiqqer.menu.edit', $PermissionUser); @@ -258,7 +259,7 @@ public function save(?QUI\Interfaces\Users\User $PermissionUser = null) try { QUI::getEvents()->fireEvent('quiqqerMenuIndependentSave', [$this]); - } catch (\Exception $Exception) { + } catch (Exception $Exception) { QUI\System\Log::writeException($Exception); } } @@ -269,7 +270,7 @@ public function save(?QUI\Interfaces\Users\User $PermissionUser = null) * @param array|null $title - ['de' => '', 'en' => ''] * @return void */ - public function setTitle(?array $title) + public function setTitle(?array $title): void { if ($title === null) { return; @@ -294,7 +295,7 @@ public function setTitle(?array $title) * @param array|null $title - ['de' => '', 'en' => ''] * @return void */ - public function setWorkingTitle(?array $title) + public function setWorkingTitle(?array $title): void { if ($title === null) { return; @@ -317,7 +318,7 @@ public function setWorkingTitle(?array $title) * @param array|null $data * @return void */ - public function setData(?array $data) + public function setData(?array $data): void { if ($data === null) { return; diff --git a/src/QUI/Menu/Independent/Smarty.php b/src/QUI/Menu/Independent/Smarty.php index b14ff5e9dddf0138441be49ac84e0f2735ba4a4e..7e218f6d1b1cb30e3f92550930a301fc3ad18080 100644 --- a/src/QUI/Menu/Independent/Smarty.php +++ b/src/QUI/Menu/Independent/Smarty.php @@ -14,7 +14,9 @@ class Smarty /** * Menu function for smarty * - * @return void + * @param $params + * @param $smarty + * @return string */ public static function menu($params, $smarty): string { @@ -25,7 +27,7 @@ public static function menu($params, $smarty): string try { $Project = QUI::getRewrite()->getProject(); - } catch (QUI\Exception $Exception) { + } catch (QUI\Exception) { return ''; } @@ -34,7 +36,7 @@ public static function menu($params, $smarty): string try { return QUI\Cache\Manager::get($cacheName); - } catch (QUI\Exception $Exception) { + } catch (QUI\Exception) { } try { diff --git a/src/QUI/Menu/Mega/AbstractChild.php b/src/QUI/Menu/Mega/AbstractChild.php index b0ee03b12c831457399ba66c4485ed089ab025f5..ad975486a7fe1944b4afc2e17bc06bd57567c9df 100644 --- a/src/QUI/Menu/Mega/AbstractChild.php +++ b/src/QUI/Menu/Mega/AbstractChild.php @@ -3,6 +3,8 @@ namespace QUI\Menu\Mega; use QUI; +use QUI\Exception; +use QUI\Interfaces\Projects\Site; /** * Class AbstractMenu @@ -15,14 +17,15 @@ abstract class AbstractChild extends QUI\Control /** * @var null|array */ - protected $children = null; + protected ?array $children = null; /** * Return the current site * - * @return mixed|QUI\Projects\Site + * @return Site + * @throws Exception */ - protected function getSite() + protected function getSite(): QUI\Interfaces\Projects\Site { if ($this->getAttribute('Site')) { return $this->getAttribute('Site'); @@ -32,9 +35,10 @@ protected function getSite() } /** - * @return array + * @return array|null + * @throws Exception */ - public function getChildren() + public function getChildren(): ?array { if (is_null($this->children)) { $this->children = $this->getSite()->getNavigation(); @@ -47,8 +51,9 @@ public function getChildren() * Returns the number of children * * @return int + * @throws Exception */ - public function count() + public function count(): int { return count($this->getChildren()); } diff --git a/src/QUI/Menu/Mega/Icons.php b/src/QUI/Menu/Mega/Icons.php index 627c29bba0d50038648513b09a973c04253fc3f8..a60677465c549bd181b142a25c7d58fe2e53916a 100644 --- a/src/QUI/Menu/Mega/Icons.php +++ b/src/QUI/Menu/Mega/Icons.php @@ -16,9 +16,9 @@ class Icons extends AbstractChild { /** - * @var null + * @var array|null */ - protected $children = null; + protected ?array $children = null; /** * Standard constructor. @@ -39,7 +39,7 @@ public function __construct(array $params = []) * @return string * @throws QUI\Exception */ - public function getBody() + public function getBody(): string { $Engine = QUI::getTemplateManager()->getEngine(); diff --git a/src/QUI/Menu/Mega/IconsDescription.php b/src/QUI/Menu/Mega/IconsDescription.php index 06bc80b6ee5f8dd1a2909d73ef14b78746ec6d7d..e3935fb9975c64e24e84ae8661aee51f3c96bcce 100644 --- a/src/QUI/Menu/Mega/IconsDescription.php +++ b/src/QUI/Menu/Mega/IconsDescription.php @@ -17,9 +17,9 @@ class IconsDescription extends AbstractChild { /** - * @var null + * @var array|null */ - protected $children = null; + protected ?array $children = null; /** * Standard constructor. @@ -40,7 +40,7 @@ public function __construct(array $params = []) * @return string * @throws QUI\Exception */ - public function getBody() + public function getBody(): string { $Engine = QUI::getTemplateManager()->getEngine(); diff --git a/src/QUI/Menu/Mega/Image.php b/src/QUI/Menu/Mega/Image.php index 7644293013623b816bf1a9c9060e6d5d41cb6822..a95bba30caac540e9a7bbfc28e69a5d45882c3f2 100644 --- a/src/QUI/Menu/Mega/Image.php +++ b/src/QUI/Menu/Mega/Image.php @@ -16,9 +16,9 @@ class Image extends AbstractChild { /** - * @var null + * @var array|null */ - protected $children = null; + protected ?array $children = null; /** * Standard constructor. @@ -39,7 +39,7 @@ public function __construct(array $params = []) * @return string * @throws QUI\Exception */ - public function getBody() + public function getBody(): string { $Engine = QUI::getTemplateManager()->getEngine(); diff --git a/src/QUI/Menu/Mega/Simple.php b/src/QUI/Menu/Mega/Simple.php index b3a19ae31dca52472dfcce1e46920552c47d8f56..8da7f3b131c92c8697a17f695e9f303fa79fdb36 100644 --- a/src/QUI/Menu/Mega/Simple.php +++ b/src/QUI/Menu/Mega/Simple.php @@ -16,9 +16,9 @@ class Simple extends AbstractChild { /** - * @var null + * @var array|null */ - protected $children = null; + protected ?array $children = null; /** * Standard constructor. @@ -44,7 +44,7 @@ public function __construct(array $params = []) * @return string * @throws QUI\Exception */ - public function getBody() + public function getBody(): string { $Engine = QUI::getTemplateManager()->getEngine(); diff --git a/src/QUI/Menu/Mega/Standard.php b/src/QUI/Menu/Mega/Standard.php index 9bddadfe991b00f66722bef11fe4d940583e6c55..7562701cf2386e5afbd44fb32ebddc2956f5a85d 100644 --- a/src/QUI/Menu/Mega/Standard.php +++ b/src/QUI/Menu/Mega/Standard.php @@ -16,9 +16,9 @@ class Standard extends AbstractChild { /** - * @var null + * @var array|null */ - protected $children = null; + protected ?array $children = null; /** * Standard constructor. @@ -39,7 +39,7 @@ public function __construct(array $params = []) * @return string * @throws QUI\Exception */ - public function getBody() + public function getBody(): string { $Engine = QUI::getTemplateManager()->getEngine(); diff --git a/src/QUI/Menu/MegaMenu.php b/src/QUI/Menu/MegaMenu.php index a84a64a3f1048d5a10d3a5b9cc4cd1755187deff..542a515918728ce5532589bf46742ac8879b7579 100644 --- a/src/QUI/Menu/MegaMenu.php +++ b/src/QUI/Menu/MegaMenu.php @@ -6,8 +6,16 @@ namespace QUI\Menu; +use Exception; use QUI; +use function array_filter; +use function array_merge; +use function array_unique; +use function is_object; +use function md5; +use function serialize; + /** * Class MegaMenu * @@ -16,19 +24,21 @@ class MegaMenu extends AbstractMenu { /** - * @var SlideOut + * @var SlideOut|SlideOutAdvanced|null */ - protected $Mobile = null; + protected SlideOutAdvanced|null|SlideOut $Mobile = null; /** * @var array */ - protected $subMenus = []; + protected array $subMenus = []; /** * @param array $attributes + * @throws QUI\Exception + * @throws Exception */ - public function __construct($attributes = []) + public function __construct(array $attributes = []) { $this->setAttributes([ 'showStart' => false, @@ -86,19 +96,20 @@ public function __construct($attributes = []) /** * @return string * @throws QUI\Exception + * @throws Exception */ - public function getBody() + public function getBody(): string { $cache = EventHandler::menuCacheName() . '/megaMenu/'; $attributes = $this->getAttributes(); - $attributes = \array_filter($attributes, function ($entry) { - return \is_object($entry) === false; + $attributes = array_filter($attributes, function ($entry) { + return is_object($entry) === false; }); - $cache .= \md5( + $cache .= md5( $this->getSite()->getCachePath() . - \serialize($attributes) + serialize($attributes) ); $childControl = $this->getMenuControl($this->getAttribute('display')); @@ -125,7 +136,7 @@ public function getBody() foreach ($cacheResult['subMenus'] as $childControl) { $Instance = new $childControl(); - $cssFiles = \array_merge($cssFiles, $Instance->getCSSFiles()); + $cssFiles = array_merge($cssFiles, $Instance->getCSSFiles()); } foreach ($cssFiles as $cssFile) { @@ -133,7 +144,7 @@ public function getBody() } return $cacheResult['html']; - } catch (QUI\Exception $Exception) { + } catch (QUI\Exception) { } $Engine = QUI::getTemplateManager()->getEngine(); @@ -207,7 +218,7 @@ public function getBody() $result['html'] = $Engine->fetch(dirname(__FILE__) . '/MegaMenu.html'); } - $result['subMenus'] = \array_unique($this->subMenus); + $result['subMenus'] = array_unique($this->subMenus); QUI\Cache\Manager::set($cache, $result); @@ -215,9 +226,11 @@ public function getBody() } /** - * @return QUI\Projects\Site + * @return QUI\Interfaces\Projects\Site + * @throws QUI\Exception + * @throws Exception */ - public function getStart() + public function getStart(): QUI\Interfaces\Projects\Site { if ($this->getAttribute('Start')) { return $this->getAttribute('Start'); @@ -230,9 +243,9 @@ public function getStart() * Return the menu control class name for a menu control shortcut * * @param $control - * @return mixed + * @return false|string */ - public function getMenuControl($control) + public function getMenuControl($control): bool|string { switch ($control) { case 'Image': @@ -292,7 +305,7 @@ public function getMenuControl($control) /** * @param $subMenu */ - public function addSubMenu($subMenu) + public function addSubMenu($subMenu): void { $this->subMenus[] = $subMenu; } @@ -300,9 +313,10 @@ public function addSubMenu($subMenu) /** * Return the current site * - * @return mixed|QUI\Projects\Site + * @return QUI\Interfaces\Projects\Site + * @throws QUI\Exception */ - protected function getSite() + protected function getSite(): QUI\Interfaces\Projects\Site { if ($this->getAttribute('Site')) { return $this->getAttribute('Site'); @@ -317,8 +331,9 @@ protected function getSite() * @param $slideOutParam * @return SlideOutAdvanced|SlideOut * @throws QUI\Exception + * @throws Exception */ - protected function getMobileMenu($slideOutParam) + protected function getMobileMenu($slideOutParam): SlideOut|SlideOutAdvanced { if ($this->getProject()->getConfig('mobileMenu.settings.type') == 'slideoutAdvanced') { $Menu = new QUI\Menu\SlideOutAdvanced($slideOutParam); diff --git a/src/QUI/Menu/NavTabs.php b/src/QUI/Menu/NavTabs.php index 969e091995e42e8284678dbc62469374e761ce73..3f65adab298094070a54610024edfdcbb8d1d602 100644 --- a/src/QUI/Menu/NavTabs.php +++ b/src/QUI/Menu/NavTabs.php @@ -7,6 +7,9 @@ namespace QUI\Menu; use QUI; +use QUI\Projects\Site\Utils; + +use function count; /** * Class NavTabs @@ -25,12 +28,12 @@ class NavTabs extends QUI\Control * * @var array */ - private $entries = []; + private array $entries = []; /** * @param array $attributes */ - public function __construct($attributes = []) + public function __construct(array $attributes = []) { $this->setAttributes([ 'nodeName' => 'div', @@ -53,7 +56,7 @@ public function __construct($attributes = []) * @return string * @throws QUI\Exception */ - public function getBody() + public function getBody(): string { $Engine = QUI::getTemplateManager()->getEngine(); $this->setJavaScriptControlOption('animation', 'slide'); @@ -83,13 +86,13 @@ public function getBody() * @return array|string * @throws QUI\Exception */ - private function getChildrenFromParent() + private function getChildrenFromParent(): array|string { $ParentSite = null; if ($this->getAttribute('parentSite')) { try { - $ParentSite = \QUI\Projects\Site\Utils::getSiteByLink($this->getAttribute('parentSite')); + $ParentSite = Utils::getSiteByLink($this->getAttribute('parentSite')); } catch (QUI\Exception $Exception) { QUI\System\Log::addDebug($Exception->getMessage()); @@ -143,7 +146,7 @@ private function getChildrenFromParent() */ public function setData(array $data) { - if (\count($data) < 1) { + if (count($data) < 1) { return false; } @@ -151,7 +154,7 @@ public function setData(array $data) /** @var QUI\Projects\Site $Site */ foreach ($data as $dataSet) { - if (\count($dataSet) < 2) { + if (count($dataSet) < 2) { continue; } diff --git a/src/QUI/Menu/NavTabsVertical.php b/src/QUI/Menu/NavTabsVertical.php index e986cdea1dc6aa297705f21fd40c42d32325eb34..7a23cbbbe869c708a14afbd1bcd0325e1592d033 100644 --- a/src/QUI/Menu/NavTabsVertical.php +++ b/src/QUI/Menu/NavTabsVertical.php @@ -21,7 +21,7 @@ class NavTabsVertical extends QUI\Control * * @param array $attributes */ - public function __construct($attributes = []) + public function __construct(array $attributes = []) { // default options $this->setAttributes([ @@ -46,7 +46,7 @@ public function __construct($attributes = []) * * @see \QUI\Control::create() */ - public function getBody() + public function getBody(): string { $Engine = QUI::getTemplateManager()->getEngine(); $entries = $this->getAttribute('entries'); @@ -61,7 +61,7 @@ public function getBody() continue; } - array_push($enabledEntries, $entry); + $enabledEntries[] = $entry; } $Engine->assign([ diff --git a/src/QUI/Menu/OnePageNav.php b/src/QUI/Menu/OnePageNav.php index f2959788109c229db1fedd331a75d0a90c56315f..5961adcaa9eec228a734c84154a3acc915ec98dd 100644 --- a/src/QUI/Menu/OnePageNav.php +++ b/src/QUI/Menu/OnePageNav.php @@ -20,7 +20,7 @@ class OnePageNav extends QUI\Control * * @param array $attributes */ - public function __construct($attributes = []) + public function __construct(array $attributes = []) { // default options $this->setAttributes([ @@ -42,7 +42,7 @@ public function __construct($attributes = []) * * @see \QUI\Control::create() */ - public function getBody() + public function getBody(): string { $Engine = QUI::getTemplateManager()->getEngine(); $entries = $this->getAttribute('entries'); diff --git a/src/QUI/Menu/Rest/Provider.php b/src/QUI/Menu/Rest/Provider.php index dd66fca32858ced2d1d5f29a921c5c04391b734b..242af21db8978957790dec7417fc096064ffb8e4 100644 --- a/src/QUI/Menu/Rest/Provider.php +++ b/src/QUI/Menu/Rest/Provider.php @@ -29,7 +29,7 @@ class Provider implements ProviderInterface * * @param Server $Server */ - public function register(Server $Server) + public function register(Server $Server): void { $Slim = $Server->getSlim(); @@ -158,12 +158,9 @@ public function create(RequestInterface $Request, ResponseInterface $Response): return Handler::getGenericExceptionResponse($Exception); } - return Handler::getGenericSuccessResponse( - 'Menu created.', - [ - 'id' => $newMenuId - ] - ); + return Handler::getGenericSuccessResponse('Menu created.', [ + 'id' => $newMenuId + ]); } /** @@ -318,11 +315,11 @@ public function delete(RequestInterface $Request, ResponseInterface $Response): } /** - * Get file containting OpenApi definition for this API. + * Get file containing OpenApi definition for this API. * * @return string|false - Absolute file path or false if no definition exists */ - public function getOpenApiDefinitionFile() + public function getOpenApiDefinitionFile(): bool|string { return false; } diff --git a/src/QUI/Menu/SidebarDropDownMenu.php b/src/QUI/Menu/SidebarDropDownMenu.php index 94ed4d3d1f4ec98510d4bbc8a5625d5ff31763d7..d9e600f75e427f42b882241e631c2edd25751cdf 100644 --- a/src/QUI/Menu/SidebarDropDownMenu.php +++ b/src/QUI/Menu/SidebarDropDownMenu.php @@ -6,6 +6,7 @@ namespace QUI\Menu; +use Exception; use QUI; use QUI\Projects\Site\Utils; @@ -21,7 +22,7 @@ class SidebarDropDownMenu extends QUI\Control /** * @param array $attributes */ - public function __construct($attributes = []) + public function __construct(array $attributes = []) { // defaults values $this->setAttributes([ @@ -48,9 +49,10 @@ public function __construct($attributes = []) /** * (non-PHPdoc) * + * @throws Exception * @see \QUI\Control::create() */ - public function getBody() + public function getBody(): string { $Engine = QUI::getTemplateManager()->getEngine(); $Project = $this->getProject(); @@ -164,12 +166,13 @@ public function getBody() $this->addCSSFile($css); $html = $Engine->fetch($template); - $html = '<nav>' . $html . '</nav>'; - - return $html; + return '<nav>' . $html . '</nav>'; } - public function getChildren(QUI\Projects\Site $Site) + /** + * @throws QUI\Exception + */ + public function getChildren(QUI\Projects\Site $Site): array|int { if (!$this->getAttribute('showAllChildren')) { return $Site->getNavigation(); diff --git a/src/QUI/Menu/SlideOut.php b/src/QUI/Menu/SlideOut.php index 6124feff6a20b5526b7c48c9a01ee898805aa13f..663bea4234c062343cedb2192e863bca023b95f3 100644 --- a/src/QUI/Menu/SlideOut.php +++ b/src/QUI/Menu/SlideOut.php @@ -20,7 +20,7 @@ class SlideOut extends QUI\Control /** * @param array $attributes */ - public function __construct($attributes = []) + public function __construct(array $attributes = []) { $this->setAttributes([ 'showHomeLink' => true, @@ -37,7 +37,7 @@ public function __construct($attributes = []) * @return string * @throws QUI\Exception */ - public function getBody() + public function getBody(): string { $Engine = QUI::getTemplateManager()->getEngine(); @@ -77,9 +77,9 @@ public function getBody() /** * Return the current site * - * @return mixed|QUI\Projects\Site + * @return QUI\Interfaces\Projects\Site */ - protected function getSite() + protected function getSite(): QUI\Interfaces\Projects\Site { if ($this->getAttribute('Site')) { return $this->getAttribute('Site'); diff --git a/src/QUI/Menu/SlideOutAdvanced.php b/src/QUI/Menu/SlideOutAdvanced.php index 96f6465924243bf92a916deb676c96ff19f55da9..d345844cc3719502762884ae6e969a1527bc5548 100644 --- a/src/QUI/Menu/SlideOutAdvanced.php +++ b/src/QUI/Menu/SlideOutAdvanced.php @@ -8,9 +8,11 @@ use QUI; +use function dirname; + /** * Class MenuAdvanced - * Creates an slideout menu + * Creates a slide-out menu * * @package QUI\Menu */ @@ -19,7 +21,7 @@ class SlideOutAdvanced extends QUI\Control /** * @param array $attributes */ - public function __construct($attributes = []) + public function __construct(array $attributes = []) { $this->setAttributes([ 'menuId' => false, // if set independent menu template will be used @@ -31,7 +33,7 @@ public function __construct($attributes = []) parent::__construct($attributes); $this->addCSSFile( - \dirname(__FILE__) . '/SlideOutAdvanced.css' + dirname(__FILE__) . '/SlideOutAdvanced.css' ); } @@ -39,7 +41,7 @@ public function __construct($attributes = []) * @return string * @throws QUI\Exception */ - public function getBody() + public function getBody(): string { $Engine = QUI::getTemplateManager()->getEngine(); @@ -73,9 +75,9 @@ public function getBody() /** * Return the current site * - * @return mixed|QUI\Projects\Site + * @return QUI\Interfaces\Projects\Site */ - protected function getSite() + protected function getSite(): QUI\Interfaces\Projects\Site { if ($this->getAttribute('Site')) { return $this->getAttribute('Site'); diff --git a/src/QUI/Menu/UrlList.php b/src/QUI/Menu/UrlList.php index f9007250927c879bf39ad7f6eae4163ac20f28d2..a3fa9d7507b593ae888eaf26063cc9698172403b 100644 --- a/src/QUI/Menu/UrlList.php +++ b/src/QUI/Menu/UrlList.php @@ -7,6 +7,7 @@ namespace QUI\Menu; use QUI; +use QUI\Exception; use QUI\Projects\Site\Utils; /** @@ -29,7 +30,7 @@ class UrlList extends QUI\Control /** * @param array $attributes */ - public function __construct($attributes = []) + public function __construct(array $attributes = []) { // defaults values $this->setAttributes([ @@ -50,9 +51,10 @@ public function __construct($attributes = []) /** * (non-PHPdoc) * + * @throws Exception * @see \QUI\Control::create() */ - public function getBody() + public function getBody(): string { if ($this->getAttribute('menuId')) { // independent menu @@ -70,7 +72,7 @@ public function getBody() $icon = ''; $restLinkColorCss = ''; - if ($this->getAttribute('icon') && strpos($this->getAttribute('icon'), 'fa ') === 0) { + if ($this->getAttribute('icon') && str_starts_with($this->getAttribute('icon'), 'fa ')) { $icon = $this->getAttribute('icon'); } @@ -104,7 +106,7 @@ public function getBody() * @return array * @throws QUI\Exception */ - public function getChildrenForIndependentMenu() + public function getChildrenForIndependentMenu(): array { $IndependentMenu = Independent\Handler::getMenu($this->getAttribute('menuId')); @@ -114,10 +116,10 @@ public function getChildrenForIndependentMenu() /** * Get sites for QUI site * - * @return array - * @throws QUI\Exception + * @return array|int + * @throws Exception */ - public function getChildrenForQUISite() + public function getChildrenForQUISite(): array|int { $Project = $this->getProject(); @@ -144,7 +146,7 @@ public function getChildrenForQUISite() * @return array|int * @throws QUI\Exception */ - public function getChildren(QUI\Projects\Site $Site) + public function getChildren(QUI\Projects\Site $Site): array|int { if (!$this->getAttribute('showAllChildren')) { return $Site->getNavigation(); diff --git a/tests/phpstan-bootstrap.php b/tests/phpstan-bootstrap.php new file mode 100644 index 0000000000000000000000000000000000000000..b61ff4b8300a965e0f46025ba64745a22b118e74 --- /dev/null +++ b/tests/phpstan-bootstrap.php @@ -0,0 +1,13 @@ +<?php + +if (!defined('QUIQQER_SYSTEM')) { + define('QUIQQER_SYSTEM', true); +} + +if (!defined('QUIQQER_AJAX')) { + define('QUIQQER_AJAX', true); +} + +putenv("QUIQQER_OTHER_AUTOLOADERS=KEEP"); + +require_once __DIR__ . '/../../../../bootstrap.php';