From dbc8541d59d44266369f2164c08d009a40d3feaf Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sat, 29 Apr 2023 21:51:41 +0200 Subject: [PATCH] fix phpstan level 9 warnings --- src/Backend.php | 20 +++++++++++++------- src/Manage.php | 4 ++-- src/ManageVars.php | 5 +++-- src/My.php | 4 +++- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/Backend.php b/src/Backend.php index ecfc6d5..151b7db 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -18,6 +18,7 @@ use ArrayObject; use dcAdmin; use dcCore; use dcFavorites; +use dcMenu; use dcNsProcess; use dcPage; @@ -40,13 +41,18 @@ class Backend extends dcNsProcess } // backend sidebar menu icon - dcCore::app()->menu[dcAdmin::MENU_SYSTEM]->addItem( - My::name(), - dcCore::app()->adminurl?->get('admin.plugin.' . My::id()), - dcPage::getPF(My::id() . '/icon.svg'), - preg_match('/' . preg_quote((string) dcCore::app()->adminurl?->get('admin.plugin.' . My::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']), - dcCore::app()->auth?->isSuperAdmin() - ); + if (!is_null(dcCore::app()->auth) + && !is_null(dcCore::app()->adminurl) + && (dcCore::app()->menu[dcAdmin::MENU_SYSTEM] instanceof dcMenu) + ) { + dcCore::app()->menu[dcAdmin::MENU_SYSTEM]->addItem( + My::name(), + dcCore::app()->adminurl->get('admin.plugin.' . My::id()), + dcPage::getPF(My::id() . '/icon.svg'), + preg_match('/' . preg_quote((string) dcCore::app()->adminurl->get('admin.plugin.' . My::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']), + dcCore::app()->auth->isSuperAdmin() + ); + } dcCore::app()->addBehaviors([ // backend user preference for logs list columns diff --git a/src/Manage.php b/src/Manage.php index 634fcf5..ef7e864 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -104,8 +104,8 @@ class Manage extends dcNsProcess (new Hidden(['p'], My::id()))->render() ); $current->list->display( - (int) $current->filter->__get('page'), - (int) $current->filter->__get('nb'), + is_numeric($current->filter->__get('page')) ? (int) $current->filter->__get('page') : 1, + is_numeric($current->filter->__get('nb')) ? (int) $current->filter->__get('nb') : 10, (new Form('form-entries'))->action(dcCore::app()->adminurl?->get('admin.plugin.' . My::id()))->method('post')->fields([ (new Text('', '%s')), (new Div())->class('two-cols')->items([ diff --git a/src/ManageVars.php b/src/ManageVars.php index d545386..329702e 100644 --- a/src/ManageVars.php +++ b/src/ManageVars.php @@ -37,7 +37,7 @@ class ManageVars /** @var null|BackendList $list The records list form instance */ public readonly ?BackendList $list; - /** @var array $entries The post form selected entries */ + /** @var array $entries The post form selected entries */ public readonly array $entries; /** @var bool $selected_logs The post form action */ @@ -65,7 +65,8 @@ class ManageVars try { $this->logs = dcCore::app()->log->getLogs($params); - $count = (int) dcCore::app()->log->getLogs($params, true)->f(0); + $count = dcCore::app()->log->getLogs($params, true)->f(0); + $count = is_numeric($count) ? (int) $count : 0; $this->list = new BackendList($this->logs, $count); } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); diff --git a/src/My.php b/src/My.php index 9b85e1b..551984b 100644 --- a/src/My.php +++ b/src/My.php @@ -48,7 +48,9 @@ class My */ public static function name(): string { - return __((string) dcCore::app()->plugins->moduleInfo(self::id(), 'name')); + $name = dcCore::app()->plugins->moduleInfo(self::id(), 'name'); + + return __(is_string($name) ? $name : 'Undefined'); } /**