update to Dotclear 2.24, phpstan 1.9.2, php-cs-fixer 3.13.0

master
Jean-Christian Paul Denis 2022-11-12 22:58:44 +01:00
parent 6da2f9d3e6
commit 5d32b5c410
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
18 changed files with 144 additions and 152 deletions

View File

@ -5,6 +5,11 @@ dev
- [ ] add module to create full README file
- [ ] write documentation of php class
0.9 - 2022.11.12
- update to Dotclear 2.24
- update to php-cs-fixer.phar 3.13.0
- update to phpstan.phar 1.9.2
0.8.2 - 2021.11.18
- update php-cs-fixer.phar to 3.3.2
- update phpstan.phar to 1.2.0

View File

@ -3,7 +3,7 @@
[![Release](https://img.shields.io/github/v/release/JcDenis/improve)](https://github.com/JcDenis/improve/releases)
[![Date](https://img.shields.io/github/release-date/JcDenis/improve)](https://github.com/JcDenis/improve/releases)
[![Issues](https://img.shields.io/github/issues/JcDenis/improve)](https://github.com/JcDenis/improve/issues)
[![Dotclear](https://img.shields.io/badge/dotclear-v2.19-blue.svg)](https://fr.dotclear.org/download)
[![Dotclear](https://img.shields.io/badge/dotclear-v2.24-blue.svg)](https://fr.dotclear.org/download)
[![Dotaddict](https://img.shields.io/badge/dotaddict-official-green.svg)](https://plugins.dotaddict.org/dc2/details/improve)
[![License](https://img.shields.io/github/license/JcDenis/improve)](https://github.com/JcDenis/improve/blob/master/LICENSE)
@ -23,7 +23,7 @@ It helps dev to clean up plugin or theme before publishing code.
**improve** requires:
* admin permission
* Dotclear 2.19
* Dotclear 2.24
## USAGE

View File

@ -19,16 +19,15 @@ if (!defined('DC_CONTEXT_ADMIN')) {
}
/* dotclear */
use dcAdmin;
use dcCore;
use dcPage;
use dcFavorites;
/* clearbricks */
use Clearbricks;
use files;
/* php */
use ArrayObject;
/**
* Improve admin class
*
@ -36,54 +35,52 @@ use ArrayObject;
*/
class admin
{
public static function process(dcCore $core, ArrayObject $_menu): void
public static function process(): void
{
self::addSettingsNamespace($core);
self::addAdminBehaviors($core);
self::addAdminMenu($core, $_menu);
self::addImproveActions($core);
self::addSettingsNamespace();
self::addAdminBehaviors();
self::addAdminMenu();
self::addImproveActions();
}
private static function addSettingsNamespace(dcCore $core): void
private static function addSettingsNamespace(): void
{
$core->blog->settings->addNamespace('improve');
dcCore::app()->blog->settings->addNamespace('improve');
}
private static function addAdminBehaviors(dcCore $core): void
private static function addAdminBehaviors(): void
{
$core->addBehavior('adminDashboardFavorites', __NAMESPACE__ . '\admin::adminDashboardFavorites');
dcCore::app()->addBehavior('adminDashboardFavoritesV2', __NAMESPACE__ . '\admin::adminDashboardFavorites');
}
private static function addAdminMenu(dcCore $core, ArrayObject $_menu): void
private static function addAdminMenu(): void
{
$_menu['Plugins']->addItem(
dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
__('improve'),
$core->adminurl->get('admin.plugin.improve'),
dcCore::app()->adminurl->get('admin.plugin.improve'),
dcPage::getPF('improve/icon.png'),
preg_match('/' . preg_quote($core->adminurl->get('admin.plugin.improve')) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
$core->auth->isSuperAdmin()
preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.improve')) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
dcCore::app()->auth->isSuperAdmin()
);
}
private static function addImproveActions(dcCore $core): void
private static function addImproveActions(): void
{
global $__autoload;
foreach (files::scandir(prepend::getActionsDir()) as $file) {
if (is_file(prepend::getActionsDir() . $file) && '.php' == substr($file, -4)) {
$__autoload[prepend::getActionsNS() . substr($file, 0, -4)] = prepend::getActionsDir() . $file;
$core->addBehavior('improveAddAction', [prepend::getActionsNS() . substr($file, 0, -4), 'create']); /* @phpstan-ignore-line */
Clearbricks::lib()->autoload([prepend::getActionsNS() . substr($file, 0, -4) => prepend::getActionsDir() . $file]);
dcCore::app()->addBehavior('improveAddAction', [prepend::getActionsNS() . substr($file, 0, -4), 'create']); /* @phpstan-ignore-line */
}
}
}
public static function adminDashboardFavorites(dcCore $core, dcFavorites $favs): void
public static function adminDashboardFavorites(dcFavorites $favs): void
{
$favs->register(
'improve',
[
'title' => __('improve'),
'url' => $core->adminurl->get('admin.plugin.improve'),
'url' => dcCore::app()->adminurl->get('admin.plugin.improve'),
'small-icon' => dcPage::getPF('improve/icon.png'),
'large-icon' => dcPage::getPF('improve/icon-b.png'),
'permissions' => null,
@ -93,4 +90,4 @@ class admin
}
/* process */
admin::process($core, $_menu);
admin::process();

View File

@ -20,7 +20,6 @@ if (!defined('DC_CONTEXT_ADMIN')) {
/* dotclear */
use dcCore;
use adminModulesList;
use dcPage;
/* clearbricks */
@ -36,20 +35,14 @@ use Exception;
*/
class config
{
/** @var dcCore $core dcCore instance */
private $core = null;
/** @var adminModulesList $list adminModulesList instance */
private $list = null;
/** @var improve $improve improve core instance */
private $improve = null;
public function __construct(dcCore $core, adminModulesList $list)
public function __construct()
{
dcPage::checkSuper();
$this->core = $core;
$this->list = $list;
$this->improve = new improve($core);
$this->improve = new improve();
$this->saveConfig();
$this->displayConfig();
@ -77,17 +70,17 @@ class config
if (!empty($_POST['disabled']) && is_array($_POST['disabled'])) {
$pdisabled = implode(';', $_POST['disabled']);
}
$this->core->blog->settings->improve->put('disabled', $pdisabled);
$this->core->blog->settings->improve->put('nodetails', !empty($_POST['nodetails']));
dcCore::app()->blog->settings->improve->put('disabled', $pdisabled);
dcCore::app()->blog->settings->improve->put('nodetails', !empty($_POST['nodetails']));
dcPage::addSuccessNotice(__('Configuration successfully updated'));
$this->core->adminurl->redirect(
dcCore::app()->adminurl->redirect(
'admin.plugins',
['module' => 'improve', 'conf' => 1, 'chk' => 1, 'redir' => $this->list->getRedir()]
['module' => 'improve', 'conf' => 1, 'chk' => 1, 'redir' => dcCore::app()->admin->list->getRedir()]
);
} catch (Exception $e) {
$this->core->error->add($e->getMessage());
dcCore::app()->error->add($e->getMessage());
}
}
@ -104,11 +97,11 @@ class config
echo
'</div><div class="fieldset"><h4>' . __('Options') . '</h4>' .
'<p><label class="classic">' .
form::checkbox('nodetails', '1', ['checked' => $this->core->blog->settings->improve->nodetails]) .
form::checkbox('nodetails', '1', ['checked' => dcCore::app()->blog->settings->improve->nodetails]) .
__('Hide details of rendered actions') . '</label></p>' .
'</div>';
}
}
/* process */
new config($core, $list);
new config();

View File

@ -18,9 +18,9 @@ $this->registerModule(
'improve',
'Tiny tools to fix things for module devs',
'Jean-Christian Denis and contributors',
'0.8.2',
'0.9',
[
'requires' => [['core', '2.19']],
'requires' => [['core', '2.24']],
'permissions' => null,
'type' => 'plugin',
'support' => 'https://github.com/JcDenis/improve',

View File

@ -34,7 +34,7 @@ use Exception;
class install
{
/** @var string Dotclear minimal version */
private static $dotclear_version = '2.19';
private static $dotclear_version = '2.24';
/** @var array Improve default settings */
private static $default_settings = [[
'disabled',
@ -43,12 +43,12 @@ class install
'string',
]];
public static function process(dcCore $core): ?bool
public static function process(): ?bool
{
if (!self::checkModuleVersion($core)) {
if (!self::checkModuleVersion()) {
return null;
}
if (!self::checkDotclearVersion($core)) {
if (!self::checkDotclearVersion()) {
throw new Exception(sprintf(
'%s requires Dotclear %s',
'improve',
@ -56,40 +56,40 @@ class install
));
}
$core->blog->settings->addNamespace('improve');
self::update_0_8_0($core);
self::putSettings($core);
self::setVersion($core);
dcCore::app()->blog->settings->addNamespace('improve');
self::update_0_8_0();
self::putSettings();
self::setVersion();
return true;
}
private static function getInstalledVersion(dcCore $core): string
private static function getInstalledVersion(): string
{
$version = $core->getVersion('improve');
$version = dcCore::app()->getVersion('improve');
return is_string($version) ? $version : '0';
}
private static function checkModuleVersion(dcCore $core): bool
private static function checkModuleVersion(): bool
{
return version_compare(
self::getInstalledVersion($core),
$core->plugins->moduleInfo('improve', 'version'),
self::getInstalledVersion(),
dcCore::app()->plugins->moduleInfo('improve', 'version'),
'<'
);
}
private static function checkDotclearVersion(dcCore $core): bool
private static function checkDotclearVersion(): bool
{
return method_exists('dcUtils', 'versionsCompare')
&& dcUtils::versionsCompare(DC_VERSION, self::$dotclear_version, '>=', false);
}
private static function putSettings(dcCore $core): void
private static function putSettings(): void
{
foreach (self::$default_settings as $v) {
$core->blog->settings->improve->put(
dcCore::app()->blog->settings->improve->put(
$v[0],
$v[2],
$v[3],
@ -100,19 +100,19 @@ class install
}
}
private static function setVersion(dcCore $core): void
private static function setVersion(): void
{
$core->setVersion('improve', $core->plugins->moduleInfo('improve', 'version'));
dcCore::app()->setVersion('improve', dcCore::app()->plugins->moduleInfo('improve', 'version'));
}
/** Update improve < 0.8 : action modules settings name */
private static function update_0_8_0(dcCore $core): void
private static function update_0_8_0(): void
{
if (version_compare(self::getInstalledVersion($core), '0.8', '<')) {
foreach ($core->blog->settings->improve->dumpGlobalSettings() as $id => $values) {
if (version_compare(self::getInstalledVersion(), '0.8', '<')) {
foreach (dcCore::app()->blog->settings->improve->dumpGlobalSettings() as $id => $values) {
$newId = str_replace('ImproveAction', '', $id);
if ($id != $newId) {
$core->blog->settings->improve->rename($id, strtolower($newId));
dcCore::app()->blog->settings->improve->rename($id, strtolower($newId));
}
}
}
@ -121,7 +121,7 @@ class install
/* process */
try {
return install::process($core);
return install::process();
} catch (Exception $e) {
$core->error->add($e->getMessage());

View File

@ -14,6 +14,8 @@ declare(strict_types=1);
namespace plugins\improve;
use Clearbricks;
if (!defined('DC_RC_PATH') || !defined('DC_CONTEXT_ADMIN')) {
return;
}
@ -25,16 +27,16 @@ if (!defined('DC_RC_PATH') || !defined('DC_CONTEXT_ADMIN')) {
*/
class prepend
{
public static function process(array &$__autoload): void
public static function process(): void
{
foreach (['improve', 'action', 'module'] as $class) {
$__autoload['plugins\\improve\\' . $class] = dirname(__FILE__) . '/inc/core/' . $class . '.php';
Clearbricks::lib()->autoload(['plugins\\improve\\' . $class => __DIR__ . '/inc/core/' . $class . '.php']);
}
}
public static function getActionsDir(): string
{
return dirname(__FILE__) . '/inc/module/';
return __DIR__ . '/inc/module/';
}
public static function getActionsNS(): string
@ -44,4 +46,4 @@ class prepend
}
/* process */
prepend::process($__autoload);
prepend::process();

View File

@ -29,16 +29,13 @@ use arrayObject;
*
* Action class must extends class action.
* If your class signature is myActionClass extends plugins\improve\class\action,
* do $core->addBehavior('ImproveAddAction'), ['myClass', 'create']);
* do dcCore::app()->addBehavior('ImproveAddAction'), ['myClass', 'create']);
* your action class is automatically created,
* then function init() of your class wil be called.
* One class must manage only one action.
*/
abstract class action
{
/** @var dcCore dcCore instance */
protected $core;
/** @var array<string> Current module */
protected $module = [];
@ -83,15 +80,12 @@ abstract class action
/**
* Action constructor inits properties and settings of a child class.
*
* @param dcCore $core dcCore instance
*/
final public function __construct(dcCore $core)
final public function __construct()
{
$this->core = $core;
$this->class_name = str_replace(prepend::getActionsNS(), '', get_called_class());
$settings = $core->blog->settings->improve->get('settings_' . $this->class_name);
$settings = dcCore::app()->blog->settings->improve->get('settings_' . $this->class_name);
if (null != $settings) {
$settings = unserialize($settings);
}
@ -100,7 +94,7 @@ abstract class action
$this->init();
// can overload priority by settings
if (1 < ($p = (int) $core->blog->settings->improve->get('priority_' . $this->class_name))) {
if (1 < ($p = (int) dcCore::app()->blog->settings->improve->get('priority_' . $this->class_name))) {
$this->priority = $p;
}
}
@ -109,12 +103,11 @@ abstract class action
* Helper to create an instance of a ImproveAction child class.
*
* @param ArrayObject $list ArrayObject of actions list
* @param dcCore $core dcCore instance
*/
final public static function create(arrayObject $list, dcCore $core): void
final public static function create(arrayObject $list): void
{
$child = static::class;
$class = new $child($core);
$class = new $child();
$list->append($class);
}
@ -242,7 +235,7 @@ abstract class action
*/
final protected function redirect(string $url): bool
{
$this->core->blog->settings->improve->put(
dcCore::app()->blog->settings->improve->put(
'settings_' . $this->class_name,
serialize($this->settings),
'string',
@ -250,7 +243,7 @@ abstract class action
true,
true
);
$this->core->blog->triggerBlog();
dcCore::app()->blog->triggerBlog();
dcPage::addSuccessNotice(__('Configuration successfully updated'));
http::redirect($url);

View File

@ -35,9 +35,6 @@ class improve
'php', 'xml', 'js', 'css', 'csv', 'html', 'htm', 'txt', 'md',
];
/** @var dcCore $core dcCore instance */
private $core;
/** @var array<action> $actions Loaded actions modules */
private $actions = [];
@ -52,17 +49,14 @@ class improve
/**
* Constructor
*
* @param dcCore $core dcCore instance
*/
public function __construct(dcCore $core)
public function __construct()
{
$this->core = &$core;
$disabled = explode(';', (string) $core->blog->settings->improve->disabled);
$list = new arrayObject();
$disabled = explode(';', (string) dcCore::app()->blog->settings->improve->disabled);
$list = new arrayObject();
try {
$this->core->callBehavior('improveAddAction', $list, $this->core);
dcCore::app()->callBehavior('improveAddAction', $list);
foreach ($list as $action) {
if ($action instanceof action && !isset($this->actions[$action->id()])) {
@ -74,7 +68,7 @@ class improve
}
}
} catch (Exception $e) {
$core->error->add($e->getMessage());
dcCore::app()->error->add($e->getMessage());
}
uasort($this->actions, [$this, 'sortModules']);
}
@ -94,21 +88,21 @@ class improve
if (empty($this->logs)) {
return 0;
}
$cur = $this->core->con->openCursor($this->core->prefix . 'log');
$cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . 'log');
$cur->log_msg = serialize($this->logs);
$cur->log_table = 'improve';
$id = $this->core->log->addLog($cur);
$id = dcCore::app()->log->addLog($cur);
return $id;
}
public function readLogs(int $id): array
{
$rs = $this->core->log->getLogs(['log_table' => 'improve', 'log_id' => $id, 'limit' => 1]);
$rs = dcCore::app()->log->getLogs(['log_table' => 'improve', 'log_id' => $id, 'limit' => 1]);
if ($rs->isEmpty()) {
return [];
}
$this->core->log->delLogs($rs->log_id);
dcCore::app()->log->delLogs($rs->log_id);
$res = unserialize($rs->log_msg);
@ -308,7 +302,7 @@ class improve
public function getURL(array $params = []): string
{
return $this->core->adminurl->get('admin.plugin.improve', $params, '&');
return dcCore::app()->adminurl->get('admin.plugin.improve', $params, '&');
}
/**

View File

@ -14,6 +14,9 @@ declare(strict_types=1);
namespace plugins\improve\module;
/* dotclear */
use dcCore;
/* improve */
use plugins\improve\action;
@ -165,7 +168,7 @@ class gitshields extends action
$version = $this->module['dc_min'];
}
return $version ?: $this->core->getVersion('core');
return $version ?: dcCore::app()->getVersion('core');
}
private function writeShieldsBloc(string $content): string

View File

@ -37,7 +37,7 @@ class newline extends action
'types' => ['plugin', 'theme'],
]);
/*
$ext = @unserialize($this->core->blog->settings->improve->newline_extensions);
$ext = @unserialize(dcCore::app()->blog->settings->improve->newline_extensions);
$ext = Improve::cleanExtensions($ext);
if (!empty($ext)) {
$this->extensions = $ext;

View File

@ -18,6 +18,7 @@ namespace plugins\improve\module;
use plugins\improve\action;
/* dotclear */
use dcCore;
use dcPage;
/* clearbricks */
@ -66,9 +67,9 @@ class phpcsfixer extends action
$this->getPhpPath();
$this->core->auth->user_prefs->addWorkspace('interface');
self::$user_ui_colorsyntax = $this->core->auth->user_prefs->interface->colorsyntax;
self::$user_ui_colorsyntax_theme = $this->core->auth->user_prefs->interface->colorsyntax_theme;
dcCore::app()->auth->user_prefs->addWorkspace('interface');
self::$user_ui_colorsyntax = dcCore::app()->auth->user_prefs->interface->colorsyntax;
self::$user_ui_colorsyntax_theme = dcCore::app()->auth->user_prefs->interface->colorsyntax_theme;
return true;
}

View File

@ -14,6 +14,9 @@ declare(strict_types=1);
namespace plugins\improve\module;
/* dotclear */
use dcCore;
/* improve */
use plugins\improve\action;
@ -162,10 +165,10 @@ class phpheader extends action
$this->module['name'],
$this->module['author'],
$this->module['type'],
$this->core->auth->getInfo('user_cn'),
$this->core->auth->getinfo('user_name'),
$this->core->auth->getInfo('user_email'),
$this->core->auth->getInfo('user_url'),
dcCore::app()->auth->getInfo('user_cn'),
dcCore::app()->auth->getinfo('user_name'),
dcCore::app()->auth->getInfo('user_email'),
dcCore::app()->auth->getInfo('user_url'),
],
(string) $bloc
)

View File

@ -18,6 +18,7 @@ namespace plugins\improve\module;
use plugins\improve\action;
/* dotclear */
use dcCore;
use dcPage;
/* clearbricks */
@ -67,9 +68,9 @@ class phpstan extends action
$ignored_vars = $this->getSetting('ignored_vars');
$this->ignored_vars = is_string($ignored_vars) ? $ignored_vars : '';
$this->core->auth->user_prefs->addWorkspace('interface');
self::$user_ui_colorsyntax = $this->core->auth->user_prefs->interface->colorsyntax;
self::$user_ui_colorsyntax_theme = $this->core->auth->user_prefs->interface->colorsyntax_theme;
dcCore::app()->auth->user_prefs->addWorkspace('interface');
self::$user_ui_colorsyntax = dcCore::app()->auth->user_prefs->interface->colorsyntax;
self::$user_ui_colorsyntax_theme = dcCore::app()->auth->user_prefs->interface->colorsyntax_theme;
return true;
}
@ -200,7 +201,6 @@ class phpstan extends action
return true;
} catch (Exception $e) {
$this->setError(__('Failed to run phpstan'));
pdump($e);
return false;
}