From e147da2fdd82ce6515e9f95633f0813c7d43ebf8 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Mon, 8 Nov 2021 22:36:38 +0100 Subject: [PATCH] Fix some errors from PhpStan analyse --- _admin.php | 12 ++++++------ inc/class.tweakstores.php | 21 ++++++++++++--------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/_admin.php b/_admin.php index bd6a0bc..540064d 100644 --- a/_admin.php +++ b/_admin.php @@ -37,13 +37,13 @@ $core->addBehavior('themesToolsTabs', ['tweakStoresBehaviors', 'themesToolsTabs' class tweakStoresBehaviors { # create dcstore.xml file on the fly when pack a module - public static function packmanBeforeCreatePackage(dcCore $core, $module) + public static function packmanBeforeCreatePackage(dcCore $core, array $module): void { tweakStores::writeXML($module['id'], $module, $core->blog->settings->tweakStores->file_pattern); } # addd some js - public static function modulesToolsHeaders(dcCore $core, $plugin) + public static function modulesToolsHeaders(dcCore $core, bool $is_plugin): string { $core->auth->user_prefs->addWorkspace('interface'); @@ -58,19 +58,19 @@ class tweakStoresBehaviors } # admin plugins page tab - public static function pluginsToolsTabs(dcCore $core) + public static function pluginsToolsTabs(dcCore $core): void { self::modulesToolsTabs($core, $core->plugins->getModules(), explode(',', DC_DISTRIB_PLUGINS), $core->adminurl->get('admin.plugins') . '#tweakStores'); } # admin themes page tab - public static function themesToolsTabs(dcCore $core) + public static function themesToolsTabs(dcCore $core): void { self::modulesToolsTabs($core, $core->themes->getModules(), explode(',', DC_DISTRIB_THEMES), $core->adminurl->get('admin.blog.theme') . '#tweakStores'); } # generic page tab - protected static function modulesToolsTabs(dcCore $core, $modules, $excludes, $page_url) + protected static function modulesToolsTabs(dcCore $core, array $modules, array $excludes, string $page_url): void { $core->auth->user_prefs->addWorkspace('interface'); $user_ui_colorsyntax = $core->auth->user_prefs->interface->colorsyntax; @@ -252,7 +252,7 @@ class tweakStoresBehaviors } # create list of module for combo and remove official modules - protected static function comboModules($modules, array $excludes) + protected static function comboModules(array $modules, array $excludes): array { $combo = [__('Select a module') => '0']; foreach ($modules as $id => $module) { diff --git a/inc/class.tweakstores.php b/inc/class.tweakstores.php index f5e3ff4..47d0dae 100644 --- a/inc/class.tweakstores.php +++ b/inc/class.tweakstores.php @@ -12,11 +12,14 @@ */ class tweakStores { + /** @var array List of notice messages */ public static $notice = []; + + /** @var array List of failed messages */ public static $failed = []; # taken from lib.moduleslist.php - public static function sanitizeModule($id, $module) + public static function sanitizeModule(string $id, array $module): array { $label = empty($module['label']) ? $id : $module['label']; $name = __(empty($module['name']) ? $label : $module['name']); @@ -62,12 +65,12 @@ class tweakStores } # taken from lib.moduleslist.php - public static function sanitizeString($str) + public static function sanitizeString(string $str): string { - return preg_replace('/[^A-Za-z0-9\@\#+_-]/', '', strtolower($str)); + return (string) preg_replace('/[^A-Za-z0-9\@\#+_-]/', '', strtolower($str)); } - public static function parseFilePattern($id, $module, $file_pattern) + public static function parseFilePattern(string $id, array $module, string $file_pattern): string { $module = self::sanitizeModule($id, $module); @@ -88,10 +91,10 @@ class tweakStores )); } - public static function generateXML($id, $module, $file_pattern) + public static function generateXML(string $id, array $module, string $file_pattern): string { if (!is_array($module) || empty($module)) { - return false; + return ''; } $module = self::sanitizeModule($id, $module); $rsp = new xmlTag('module'); @@ -185,7 +188,7 @@ class tweakStores return self::prettyXML($res->toXML()); } - public static function writeXML($id, $module, $file_pattern) + public static function writeXML(string $id, array $module, string $file_pattern): bool { self::$failed = []; if (!$module['root_writable']) { @@ -215,9 +218,9 @@ class tweakStores $dom->formatOutput = true; $dom->loadXML($str); - return $dom->saveXML(); + return (string) $dom->saveXML(); } - return str_replace('><', ">\n<", $str); + return (string) str_replace('><', ">\n<", $str); } }