From ba13d88082951d04b369648873f6637e51f02ea7 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sat, 22 Apr 2023 14:32:04 +0200 Subject: [PATCH] fix nullsafe warnings --- src/Backend.php | 6 +++--- src/Manage.php | 6 +++--- src/Utils.php | 8 ++++++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Backend.php b/src/Backend.php index 3a2e295..7f6ea81 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -41,7 +41,7 @@ class Backend extends dcNsProcess 'adminDashboardFavoritesV2' => function (dcFavorites $favs): void { $favs->register(My::id(), [ 'title' => My::name(), - 'url' => dcCore::app()->adminurl->get('admin.plugin.' . My::id()), + 'url' => dcCore::app()->adminurl?->get('admin.plugin.' . My::id()), 'small-icon' => dcPage::getPF(My::id() . '/icon.svg'), 'large-icon' => dcPage::getPF(My::id() . '/icon.svg'), //'permissions' => dcCore::app()->auth->isSuperAdmin(), @@ -56,9 +56,9 @@ class Backend extends dcNsProcess dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( My::name(), - dcCore::app()->adminurl->get('admin.plugin.' . My::id()), + dcCore::app()->adminurl?->get('admin.plugin.' . My::id()), dcPage::getPF(My::id() . '/icon.svg'), - preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . My::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']), + preg_match('/' . preg_quote((string) dcCore::app()->adminurl?->get('admin.plugin.' . My::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']), dcCore::app()->auth?->isSuperAdmin() ); diff --git a/src/Manage.php b/src/Manage.php index e7a29b4..be5f220 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -28,8 +28,8 @@ use Dotclear\Helper\Html\Form\{ Text }; use Dotclear\Helper\File\Path; +use Dotclear\Helper\Network\Http; use Exception; -use http; class Manage extends dcNsProcess { @@ -79,7 +79,7 @@ class Manage extends dcNsProcess dcPage::addSuccessNotice( __('License successfully added.') ); - http::redirect( + Http::redirect( empty($_POST['redir']) ? dcCore::app()->admin->getPageURL() : $_POST['redir'] ); @@ -212,7 +212,7 @@ class Manage extends dcNsProcess { if (!(dcCore::app()->themes instanceof dcThemes)) { dcCore::app()->themes = new dcThemes(); - dcCore::app()->themes->loadModules(dcCore::app()->blog->themes_path, null); + dcCore::app()->themes->loadModules((string) dcCore::app()->blog?->themes_path, null); } return [ diff --git a/src/Utils.php b/src/Utils.php index 5500a8c..0cfcf93 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -34,6 +34,10 @@ class Utils */ public static function addLicense(array $module): void { + if (is_null(dcCore::app()->auth)) { + return; + } + $s = Settings::init(); # --BEHAVIOR-- licenseBootstrapBeforeAddLicense @@ -237,7 +241,7 @@ class Utils */ protected static function replacePhpContent(string $content, string $license, bool $overwrite): string { - $clean = preg_replace( + $clean = (string) preg_replace( '/((# -- BEGIN LICENSE BLOCK ([-]+))(.*?)' . '(# -- END LICENSE BLOCK ([-]+))([\n|\r\n]+))/msi', '', @@ -248,7 +252,7 @@ class Utils return $content; } - return preg_replace( + return (string) preg_replace( '/(\<\?php)/', '