fix some phpstan warnings

This commit is contained in:
Jean-Christian Paul Denis 2023-03-19 23:40:42 +01:00
parent 86da84f2ad
commit 2f21d2105c
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
6 changed files with 38 additions and 37 deletions

View File

@ -40,7 +40,7 @@ class Backend extends dcNsProcess
dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs): void { dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs): void {
$favs->register(My::id(), [ $favs->register(My::id(), [
'title' => My::name(), 'title' => My::name(),
'url' => dcCore::app()->adminurl->get('admin.plugin.' . My::id(), [], '#packman-repository-repository'), 'url' => dcCore::app()->adminurl?->get('admin.plugin.' . My::id(), [], '#packman-repository-repository'),
'small-icon' => [dcPage::getPF(My::id() . '/icon.svg'), dcPage::getPF(My::id() . '/icon-dark.svg')], 'small-icon' => [dcPage::getPF(My::id() . '/icon.svg'), dcPage::getPF(My::id() . '/icon-dark.svg')],
'large-icon' => [dcPage::getPF(My::id() . '/icon.svg'), dcPage::getPF(My::id() . '/icon-dark.svg')], 'large-icon' => [dcPage::getPF(My::id() . '/icon.svg'), dcPage::getPF(My::id() . '/icon-dark.svg')],
//'permissions' => dcCore::app()->auth->isSuperAdmin(), //'permissions' => dcCore::app()->auth->isSuperAdmin(),
@ -49,10 +49,10 @@ class Backend extends dcNsProcess
dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
My::name(), My::name(),
dcCore::app()->adminurl->get('admin.plugin.' . My::id()) . '#packman-repository-repository', dcCore::app()->adminurl?->get('admin.plugin.' . My::id()) . '#packman-repository-repository',
[dcPage::getPF(My::id() . '/icon.svg'), dcPage::getPF(My::id() . '/icon-dark.svg')], [dcPage::getPF(My::id() . '/icon.svg'), dcPage::getPF(My::id() . '/icon-dark.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() dcCore::app()->auth?->isSuperAdmin()
); );
return true; return true;

View File

@ -61,7 +61,7 @@ class Config extends dcNsProcess
dcPage::addSuccessNotice( dcPage::addSuccessNotice(
__('Configuration has been successfully updated.') __('Configuration has been successfully updated.')
); );
dcCore::app()->adminurl->redirect('admin.plugins', [ dcCore::app()->adminurl?->redirect('admin.plugins', [
'module' => My::id(), 'module' => My::id(),
'conf' => '1', 'conf' => '1',
'redir' => dcCore::app()->admin->__get('list')->getRedir(), 'redir' => dcCore::app()->admin->__get('list')->getRedir(),
@ -87,12 +87,13 @@ class Config extends dcNsProcess
$img_on = sprintf($img, __('writable'), 'check-on.png'); $img_on = sprintf($img, __('writable'), 'check-on.png');
$img_off = sprintf($img, __('not writable'), 'check-off.png'); $img_off = sprintf($img, __('not writable'), 'check-off.png');
$check_repo = Utils::is_writable(Utils::getRepositoryDir($s->pack_repository), '_.zip') ? $img_on : $img_off; $repo = Utils::getRepositoryDir($s->pack_repository);
$check_first = !empty($s->pack_filename) && Utils::is_writable(Utils::getRepositoryDir($repo), $s->pack_filename) ? $img_on : $img_off; $check_repo = Utils::is_writable($repo, '_.zip') ? $img_on : $img_off;
$check_second = !empty($s->secondpack_filename) && Utils::is_writable(Utils::getRepositoryDir($repo), $s->secondpack_filename) ? $img_on : $img_off; $check_first = !empty($s->pack_filename) && Utils::is_writable($repo, $s->pack_filename) ? $img_on : $img_off;
$check_second = !empty($s->secondpack_filename) && Utils::is_writable($repo, $s->secondpack_filename) ? $img_on : $img_off;
$is_configured = Utils::is_configured( $is_configured = Utils::is_configured(
Utils::getRepositoryDir($s->pack_repository), $repo,
$s->pack_filename, $s->pack_filename,
$s->secondpack_filename $s->secondpack_filename
); );
@ -117,7 +118,7 @@ class Config extends dcNsProcess
(new Note())->class('form-note')->text( (new Note())->class('form-note')->text(
sprintf( sprintf(
__('Preconization: %s'), __('Preconization: %s'),
dcCore::app()->blog->public_path ? dcCore::app()->blog?->public_path ?
dcCore::app()->blog->public_path : __("Blog's public directory") dcCore::app()->blog->public_path : __("Blog's public directory")
) . ' ' . __('Leave it empty to use Dotclear VAR directory') ) . ' ' . __('Leave it empty to use Dotclear VAR directory')
), ),

View File

@ -164,7 +164,7 @@ class Core
$zip->addExclusion($e); $zip->addExclusion($e);
} }
$zip->addDirectory( $zip->addDirectory(
path::real($info['root']), (string) path::real($info['root'], false),
$info['id'], $info['id'],
true true
); );

View File

@ -52,7 +52,7 @@ class Manage extends dcNsProcess
# Modules # Modules
if (!(dcCore::app()->themes instanceof dcThemes)) { if (!(dcCore::app()->themes instanceof dcThemes)) {
dcCore::app()->themes = new 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);
} }
$themes = dcCore::app()->themes; $themes = dcCore::app()->themes;
$plugins = dcCore::app()->plugins; $plugins = dcCore::app()->plugins;
@ -113,7 +113,7 @@ class Manage extends dcNsProcess
if (!empty($_POST['redir'])) { if (!empty($_POST['redir'])) {
http::redirect($_POST['redir']); http::redirect($_POST['redir']);
} else { } else {
dcCore::app()->adminurl->redirect('admin.plugin.' . My::id(), [], '#packman-' . $type); dcCore::app()->adminurl?->redirect('admin.plugin.' . My::id(), [], '#packman-' . $type);
} }
# Pack # Pack
@ -151,7 +151,7 @@ class Manage extends dcNsProcess
if (!empty($_POST['redir'])) { if (!empty($_POST['redir'])) {
http::redirect($_POST['redir']); http::redirect($_POST['redir']);
} else { } else {
dcCore::app()->adminurl->redirect('admin.plugin.' . My::id(), [], '#packman-' . $type); dcCore::app()->adminurl?->redirect('admin.plugin.' . My::id(), [], '#packman-' . $type);
} }
# Delete # Delete
@ -176,7 +176,7 @@ class Manage extends dcNsProcess
if (!empty($_POST['redir'])) { if (!empty($_POST['redir'])) {
http::redirect($_POST['redir']); http::redirect($_POST['redir']);
} else { } else {
dcCore::app()->adminurl->redirect('admin.plugin.' . My::id(), [], '#packman-repository-' . $type); dcCore::app()->adminurl?->redirect('admin.plugin.' . My::id(), [], '#packman-repository-' . $type);
} }
# Install # Install
@ -203,7 +203,7 @@ class Manage extends dcNsProcess
if (!empty($_POST['redir'])) { if (!empty($_POST['redir'])) {
http::redirect($_POST['redir']); http::redirect($_POST['redir']);
} else { } else {
dcCore::app()->adminurl->redirect('admin.plugin.' . My::id(), [], '#packman-repository-' . $type); dcCore::app()->adminurl?->redirect('admin.plugin.' . My::id(), [], '#packman-repository-' . $type);
} }
# Copy # Copy
@ -229,7 +229,7 @@ class Manage extends dcNsProcess
if (!empty($_POST['redir'])) { if (!empty($_POST['redir'])) {
http::redirect($_POST['redir']); http::redirect($_POST['redir']);
} else { } else {
dcCore::app()->adminurl->redirect('admin.plugin.' . My::id(), [], '#packman-repository-' . $type); dcCore::app()->adminurl?->redirect('admin.plugin.' . My::id(), [], '#packman-repository-' . $type);
} }
# Move # Move
@ -256,7 +256,7 @@ class Manage extends dcNsProcess
if (!empty($_POST['redir'])) { if (!empty($_POST['redir'])) {
http::redirect($_POST['redir']); http::redirect($_POST['redir']);
} else { } else {
dcCore::app()->adminurl->redirect('admin.plugin.' . My::id(), [], '#packman-repository-' . $type); dcCore::app()->adminurl?->redirect('admin.plugin.' . My::id(), [], '#packman-repository-' . $type);
} }
} }
} catch (Exception $e) { } catch (Exception $e) {
@ -302,7 +302,7 @@ class Manage extends dcNsProcess
if (dcCore::app()->error->flag() || !$is_configured) { if (dcCore::app()->error->flag() || !$is_configured) {
echo echo
'<div class="warning">' . __('pacKman is not well configured.') . ' ' . '<div class="warning">' . __('pacKman is not well configured.') . ' ' .
'<a href="' . dcCore::app()->adminurl->get('admin.plugins', ['module' => My::id(), 'conf' => '1', 'redir' => dcCore::app()->adminurl->get('admin.plugin.' . My::id())]) . '">' . __('Configuration') . '</a>' . '<a href="' . dcCore::app()->adminurl?->get('admin.plugins', ['module' => My::id(), 'conf' => '1', 'redir' => dcCore::app()->adminurl->get('admin.plugin.' . My::id())]) . '">' . __('Configuration') . '</a>' .
'</div>'; '</div>';
} else { } else {
Utils::modules( Utils::modules(

View File

@ -47,16 +47,16 @@ class Settings
*/ */
public function __construct() public function __construct()
{ {
$s = dcCore::app()->blog->settings->get(My::id()); $s = dcCore::app()->blog?->settings->get(My::id());
$this->pack_nocomment = (bool) ($s->get('pack_nocomment') ?? false); $this->pack_nocomment = (bool) ($s?->get('pack_nocomment') ?? false);
$this->pack_fixnewline = (bool) ($s->get('pack_fixnewline') ?? false); $this->pack_fixnewline = (bool) ($s?->get('pack_fixnewline') ?? false);
$this->pack_overwrite = (bool) ($s->get('pack_overwrite') ?? false); $this->pack_overwrite = (bool) ($s?->get('pack_overwrite') ?? false);
$this->pack_filename = (string) ($s->get('pack_filename') ?? '%type%-%id%'); $this->pack_filename = (string) ($s?->get('pack_filename') ?? '%type%-%id%');
$this->secondpack_filename = (string) ($s->get('secondpack_filename') ?? '%type%-%id%-%version%'); $this->secondpack_filename = (string) ($s?->get('secondpack_filename') ?? '%type%-%id%-%version%');
$this->pack_repository = (string) ($s->get('pack_repository') ?? ''); $this->pack_repository = (string) ($s?->get('pack_repository') ?? '');
$this->pack_excludefiles = (string) ($s->get('pack_excludefiles') ?? '*.zip,*.tar,*.tar.gz,.directory,.hg'); $this->pack_excludefiles = (string) ($s?->get('pack_excludefiles') ?? '*.zip,*.tar,*.tar.gz,.directory,.hg');
$this->hide_distrib = (bool) ($s->get('hide_distrib') ?? false); $this->hide_distrib = (bool) ($s?->get('hide_distrib') ?? false);
} }
public function getSetting(string $key): mixed public function getSetting(string $key): mixed
@ -75,8 +75,8 @@ class Settings
public function writeSetting(string $key, mixed $value): bool public function writeSetting(string $key, mixed $value): bool
{ {
if (property_exists($this, $key) && settype($value, gettype($this->{$key})) === true) { if (property_exists($this, $key) && settype($value, gettype($this->{$key})) === true) {
dcCore::app()->blog->settings->get(My::id())->drop($key); dcCore::app()->blog?->settings->get(My::id())->drop($key);
dcCore::app()->blog->settings->get(My::id())->put($key, $value, gettype($this->{$key}), '', true, true); dcCore::app()->blog?->settings->get(My::id())->put($key, $value, gettype($this->{$key}), '', true, true);
return true; return true;
} }

View File

@ -38,7 +38,7 @@ class Utils
public static function getThemesPath(): string public static function getThemesPath(): string
{ {
return dcCore::app()->blog->themes_path; return (string) dcCore::app()->blog?->themes_path;
} }
public static function is_configured(string $repo, string $file_a, string $file_b): bool public static function is_configured(string $repo, string $file_a, string $file_b): bool
@ -101,7 +101,7 @@ class Utils
} }
break; break;
case self::USE_LEGACY: case Unzip::USE_LEGACY:
break; break;
} }
@ -130,7 +130,7 @@ class Utils
} }
break; break;
case self::USE_LEGACY: case Unzip::USE_LEGACY:
break; break;
} }
@ -152,7 +152,7 @@ class Utils
return $dir; return $dir;
} }
public static function getModules(string $type, ?string $id = null): ?array public static function getModules(string $type, ?string $id = null): array
{ {
$type = $type == 'themes' ? 'themes' : 'plugins'; $type = $type == 'themes' ? 'themes' : 'plugins';
@ -168,14 +168,14 @@ class Utils
return $modules[$id]; return $modules[$id];
} }
return null; return [];
} }
public static function moduleExists(string $type, ?string $id): bool public static function moduleExists(string $type, ?string $id): bool
{ {
$type = $type == 'themes' ? 'themes' : 'plugins'; $type = $type == 'themes' ? 'themes' : 'plugins';
return array_key_exists($id, array_merge(dcCore::app()->{$type}->getDisabledModules(), dcCore::app()->{$type}->getModules())); return array_key_exists((string) $id, array_merge(dcCore::app()->{$type}->getDisabledModules(), dcCore::app()->{$type}->getModules()));
} }
public static function modules(array $modules, string $type, string $title): ?bool public static function modules(array $modules, string $type, string $title): ?bool
@ -306,7 +306,7 @@ class Utils
'</td>' . '</td>' .
'<td class="nowrap">' . '<td class="nowrap">' .
'<a class="packman-download" href="' . '<a class="packman-download" href="' .
dcCore::app()->adminurl->get('admin.plugin.' . My::id(), [ dcCore::app()->adminurl?->get('admin.plugin.' . My::id(), [
'package' => basename($module['root']), 'package' => basename($module['root']),
'repo' => $type, 'repo' => $type,
]) . '" title="' . __('Download') . '">' . ]) . '" title="' . __('Download') . '">' .