From 7a3117e1ac249f23bcf79b2682490db408c32bce Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sat, 13 May 2023 11:38:18 +0200 Subject: [PATCH] fix nullsafe warnings and type hint --- src/Backend.php | 21 ++++++++++++--------- src/Frontend.php | 2 +- src/Install.php | 6 ++++-- src/Manage.php | 14 ++++++++------ src/Utils.php | 4 ++-- 5 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/Backend.php b/src/Backend.php index 24bf31f..a4eb76f 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -17,6 +17,7 @@ namespace Dotclear\Plugin\httpPassword; use dcAdmin; use dcCore; use dcPage; +use dcMenu; use dcNsProcess; class Backend extends dcNsProcess @@ -35,15 +36,17 @@ class Backend extends dcNsProcess } // add backend sidebar menu icon - dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( - My::name(), - dcCore::app()->adminurl->get('admin.plugin.' . My::id()), - dcPage::getPF(My::id() . '/icon.png'), - preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . My::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']), - dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([ - My::PERMISSION, - ]), dcCore::app()->blog->id) - ); + if ((dcCore::app()->menu[dcAdmin::MENU_PLUGINS] instanceof dcMenu)) { + dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( + My::name(), + dcCore::app()->adminurl->get('admin.plugin.' . My::id()), + dcPage::getPF(My::id() . '/icon.png'), + preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . My::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']), + dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([ + My::PERMISSION, + ]), dcCore::app()->blog->id) + ); + } return true; } diff --git a/src/Frontend.php b/src/Frontend.php index 57d07ab..650496a 100644 --- a/src/Frontend.php +++ b/src/Frontend.php @@ -79,7 +79,7 @@ class Frontend extends dcNsProcess if (!$logs->isEmpty()) { $ids = []; while ($logs->fetch()) { - $ids[] = (int) $logs->f('log_id'); + $ids[] = is_numeric($logs->f('log_id')) ? (int) $logs->f('log_id') : 0; } $logs = dcCore::app()->log->delLogs($ids); } diff --git a/src/Install.php b/src/Install.php index cd47085..11f9c56 100644 --- a/src/Install.php +++ b/src/Install.php @@ -22,8 +22,10 @@ class Install extends dcNsProcess { public static function init(): bool { - static::$init = defined('DC_CONTEXT_ADMIN') - && dcCore::app()->newVersion(My::id(), dcCore::app()->plugins->moduleInfo(My::id(), 'version')); + if (defined('DC_CONTEXT_ADMIN')) { + $version = dcCore::app()->plugins->moduleInfo(My::id(), 'version'); + static::$init = is_string($version) ? dcCore::app()->newVersion(My::id(), $version) : true; + } return static::$init; } diff --git a/src/Manage.php b/src/Manage.php index 3186d54..97692a1 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -216,7 +216,7 @@ class Manage extends dcNsProcess (new Submit(['save']))->value(__('Save')), (new Hidden(['action'], 'savesettings')), (new Hidden(['part'], $part)), - (new Text('', dcCore::app()->formNonce())), + dcCore::app()->formNonce(false), ]), ])->render(); } @@ -234,7 +234,7 @@ class Manage extends dcNsProcess (new Submit(['save']))->value(__('Clear logs')), (new Hidden(['action'], 'savelogins')), (new Hidden(['part'], $part)), - (new Text('', dcCore::app()->formNonce())), + dcCore::app()->formNonce(false), ]), ])->render() . @@ -246,10 +246,12 @@ class Manage extends dcNsProcess ''; while ($logs->fetch()) { + $msg = is_string($logs->f('log_msg')) ? $logs->f('log_msg') : ''; + $dt = is_string($logs->f('log_dt')) ? $logs->f('log_dt') : ''; echo '' . - '' . Html::escapeHTML($logs->f('log_msg')) . '' . - '' . Html::escapeHTML(Date::dt2str(__('%Y-%m-%d %H:%M'), $logs->f('log_dt'))) . '' . + '' . Html::escapeHTML($msg) . '' . + '' . Html::escapeHTML(Date::dt2str(__('%Y-%m-%d %H:%M'), $dt)) . '' . ''; } @@ -299,7 +301,7 @@ class Manage extends dcNsProcess (new Para())->items([ (new Hidden(['action'], 'savepasswords')), (new Hidden(['part'], $part)), - (new Text('', dcCore::app()->formNonce())), + dcCore::app()->formNonce(false), ]), ])->render(); } @@ -322,7 +324,7 @@ class Manage extends dcNsProcess (new Submit(['add']))->value(__('Save')), (new Hidden(['action'], 'savepasswords')), (new Hidden(['part'], $part)), - (new Text('', dcCore::app()->formNonce())), + dcCore::app()->formNonce(false), ]), ])->render(); } diff --git a/src/Utils.php b/src/Utils.php index 9c7af5b..7f6f4fd 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -98,7 +98,7 @@ class Utils */ public static function cryptMethod(): string { - return is_null(dcCore::app()->blog) ? '' : (string) dcCore::app()->blog->settings->get(My::id())->get('crypt'); + return !is_null(dcCore::app()->blog) && is_string(dcCore::app()->blog->settings->get(My::id())->get('crypt')) ? dcCore::app()->blog->settings->get(My::id())->get('crypt') : ''; } /** @@ -108,7 +108,7 @@ class Utils */ public static function httpMessage(): string { - return is_null(dcCore::app()->blog) ? '' : (string) dcCore::app()->blog->settings->get(My::id())->get('message'); + return !is_null(dcCore::app()->blog) && is_string(dcCore::app()->blog->settings->get(My::id())->get('message')) ? dcCore::app()->blog->settings->get(My::id())->get('message') : ''; } /**