phpstan level 9: no more mixed declaration

master
Jean-Christian Paul Denis 2021-11-09 00:40:39 +01:00
parent 5e8d9dcc14
commit c3102b3636
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
13 changed files with 248 additions and 170 deletions

View File

@ -21,7 +21,7 @@ $improve = new Improve($core);
$combo_actions = []; $combo_actions = [];
foreach ($improve->modules() as $action) { foreach ($improve->modules() as $action) {
$combo_actions[$action->get('name')] = $action->get('id'); $combo_actions[$action->name()] = $action->id();
} }
$disabled = $improve->disabled(); $disabled = $improve->disabled();
if (!empty($disabled)) { if (!empty($disabled)) {

View File

@ -52,15 +52,26 @@ abstract class ImproveAction
/** @var array<string> Action module settings */ /** @var array<string> Action module settings */
private $settings = []; private $settings = [];
/** @var array<mixed> Action module properties */ /** @var array List of allowed properties */
private $properties = [ protected static $allowed_properties = ['id', 'name', 'description', 'priority', 'configurator', 'types'];
'id' => '',
'name' => '', /** @var string Module id */
'desc' => '', private $id = '';
'priority' => 500,
'config' => false, //mixed bool for internal, string for ext url /** @var string Module name */
'types' => ['plugin'] private $name = '';
];
/** @var string Module description */
private $description = '';
/** @var integer Module id */
private $priority = 500;
/** @var boolean Module has config page */
private $configurator = false;
/** @var array Module supported types */
private $types = ['plugin'];
/** /**
* ImproveAction constructor inits properpties and settings of a child class. * ImproveAction constructor inits properpties and settings of a child class.
@ -79,7 +90,7 @@ abstract class ImproveAction
// can overload priority by settings // can overload priority by settings
if (1 < ($p = (int) $core->blog->settings->improve->get('priority_' . $this->class_name))) { if (1 < ($p = (int) $core->blog->settings->improve->get('priority_' . $this->class_name))) {
$this->properties['priority'] = $p; $this->priority = $p;
} }
} }
@ -117,50 +128,61 @@ abstract class ImproveAction
*/ */
final public function get(string $key) final public function get(string $key)
{ {
if (isset($this->properties[$key])) { if (isset($this->settings[$key])) {
return $this->properties[$key];
} elseif (isset($this->settings[$key])) {
return $this->settings[$key]; return $this->settings[$key];
} }
return null; return null;
} }
/** /** Get action module id */
* Get a definition property of action class final public function id(): string
*
* @return mixed A property of action definition.
*/
final public function getProperty(string $property)
{ {
return $this->properties[$property] ?? null; return $this->id;
}
/** Get action module name */
final public function name(): string
{
return $this->name;
}
/** Get action module description */
final public function description(): string
{
return $this->description;
}
/** Get action module priority */
final public function priority(): int
{
return $this->priority;
}
/** Get action module configuration url if any */
final public function configurator(): bool
{
return $this->configurator;
}
/** Get action module supported types */
final public function types(): array
{
return $this->types;
} }
/** /**
* Set a definition property of action class * Set properties of action class
* *
* Property can be: * @param array $properties Properties
* - id : action id
* - name : action short name
* - desc : action short description,
* - priority : order of execution of this action
* - config : as configuration gui, false = none, true = internal, string = ext url
* - types : array of supported type of module, can : be plugins and/or themes
*
* @param mixed $property one or more definition
* @param mixed $value value for a single property
* *
* @return boolean Success * @return boolean Success
*/ */
final protected function setProperties($property, $value = null): bool final protected function setProperties(array $properties): bool
{ {
$properties = is_array($property) ? $property : [$property => $value]; foreach ($properties as $key => $value) {
foreach ($properties as $k => $v) { if (in_array($key, self::$allowed_properties)) {
if (isset($this->properties[$k])) { $this->{$key} = $value;
if ($k == 'types' && !is_array($v)) {
$v = [$v];
}
$this->properties[$k] = $v;
} }
} }
@ -385,7 +407,7 @@ abstract class ImproveAction
/** /**
* Get action logs. * Get action logs.
* *
* @param mixed $type type of message, can be error, warning, succes * @param string|null $type type of message, can be error, warning, succes
* *
* @return array Arry of given type of log or all if type is null * @return array Arry of given type of log or all if type is null
*/ */

View File

@ -51,11 +51,11 @@ class Improve
$this->core->callBehavior('improveAddAction', $list, $this->core); $this->core->callBehavior('improveAddAction', $list, $this->core);
foreach ($list as $action) { foreach ($list as $action) {
if (is_a($action, 'ImproveAction') && !isset($this->actions[$action->get('id')])) { if (is_a($action, 'ImproveAction') && !isset($this->actions[$action->id()])) {
if (in_array($action->get('id'), $disabled)) { if (in_array($action->id(), $disabled)) {
$this->disabled[$action->get('id')] = $action->get('name'); $this->disabled[$action->id()] = $action->name();
} else { } else {
$this->actions[$action->get('id')] = $action; $this->actions[$action->id()] = $action;
} }
} }
} }
@ -96,7 +96,9 @@ class Improve
} }
$this->core->log->delLogs($rs->log_id); $this->core->log->delLogs($rs->log_id);
return unserialize($rs->log_msg); $res = unserialize($rs->log_msg);
return is_array($res) ? $res : [];
} }
public function parselogs(int $id): array public function parselogs(int $id): array
@ -182,7 +184,7 @@ class Improve
} }
foreach ($workers as $action) { foreach ($workers as $action) {
// trace all path and action in logs // trace all path and action in logs
$this->logs['improve'][__('Begin')][] = $action->get('id'); $this->logs['improve'][__('Begin')][] = $action->id();
// info: set current module // info: set current module
$action->setModule($module); $action->setModule($module);
$action->setPath(__('Begin'), '', true); $action->setPath(__('Begin'), '', true);
@ -199,7 +201,7 @@ class Improve
} }
foreach ($workers as $action) { foreach ($workers as $action) {
// trace all path and action in logs // trace all path and action in logs
$this->logs['improve'][$file[0]][] = $action->get('id'); $this->logs['improve'][$file[0]][] = $action->id();
// info: set current path // info: set current path
$action->setPath($file[0], $file[1], $file[2]); $action->setPath($file[0], $file[1], $file[2]);
} }
@ -223,7 +225,7 @@ class Improve
throw new Exception(sprintf( throw new Exception(sprintf(
__('File content has been removed: %s by %s'), __('File content has been removed: %s by %s'),
$file[0], $file[0],
$action->get('name') $action->name()
)); ));
} }
} }
@ -238,7 +240,7 @@ class Improve
} }
foreach ($workers as $action) { foreach ($workers as $action) {
// trace all path and action in logs // trace all path and action in logs
$this->logs['improve'][__('End')][] = $action->get('id'); $this->logs['improve'][__('End')][] = $action->id();
// info: set current module // info: set current module
$action->setPath(__('End'), '', true); $action->setPath(__('End'), '', true);
// action: close module // action: close module
@ -246,7 +248,7 @@ class Improve
} }
// info: get acions reports // info: get acions reports
foreach ($workers as $action) { foreach ($workers as $action) {
$this->logs[$action->get('id')] = $action->getLogs(); $this->logs[$action->id()] = $action->getLogs();
foreach ($this->has_log as $type => $v) { foreach ($this->has_log as $type => $v) {
if ($action->hasLog($type)) { if ($action->hasLog($type)) {
$this->has_log[$type] = true; $this->has_log[$type] = true;
@ -329,11 +331,11 @@ class Improve
*/ */
private function sortModules(ImproveAction $a, ImproveAction $b): int private function sortModules(ImproveAction $a, ImproveAction $b): int
{ {
if ($a->get('priority') == $b->get('priority')) { if ($a->priority() == $b->priority()) {
return strcasecmp($a->get('name'), $b->get('name')); return strcasecmp($a->name(), $b->name());
} }
return $a->get('priority') < $b->get('priority') ? -1 : 1; return $a->priority() < $b->priority() ? -1 : 1;
} }
} }
@ -411,7 +413,7 @@ class ImproveDefinition
* *
* @return boolean Success * @return boolean Success
*/ */
private function registerModule(string $name, string $desc, string $author, string $version, $properties = []): bool // @phpstan-ignore-line private function registerModule(string $name, string $desc, string $author, string $version, $properties = []): bool
{ {
if (!is_array($properties)) { if (!is_array($properties)) {
$args = func_get_args(); $args = func_get_args();

View File

@ -62,11 +62,11 @@ class ImproveActionDcdeprecated extends ImproveAction
protected function init(): bool protected function init(): bool
{ {
$this->setProperties([ $this->setProperties([
'id' => 'dcdeprecated', 'id' => 'dcdeprecated',
'name' => __('Dotclear deprecated'), 'name' => __('Dotclear deprecated'),
'desc' => __('Search for use of deprecated Dotclear functions'), 'description' => __('Search for use of deprecated Dotclear functions'),
'priority' => 520, 'priority' => 520,
'types' => ['plugin', 'theme'] 'types' => ['plugin', 'theme']
]); ]);
return true; return true;

View File

@ -15,12 +15,12 @@ class ImproveActionDcstore extends ImproveAction
protected function init(): bool protected function init(): bool
{ {
$this->setProperties([ $this->setProperties([
'id' => 'dcstore', 'id' => 'dcstore',
'name' => __('Store file'), 'name' => __('Store file'),
'desc' => __('Re-create dcstore.xml file according to _define.php variables'), 'description' => __('Re-create dcstore.xml file according to _define.php variables'),
'priority' => 420, 'priority' => 420,
'config' => true, 'configurator' => true,
'types' => ['plugin', 'theme'] 'types' => ['plugin', 'theme']
]); ]);
return true; return true;
@ -187,6 +187,11 @@ class ImproveActionDcstore extends ImproveAction
private function parseFilePattern(): string private function parseFilePattern(): string
{ {
$str = $this->getSetting('pattern');
if (!is_string($str)) {
return '';
}
return text::tidyURL(str_replace( return text::tidyURL(str_replace(
[ [
'%type%', '%type%',
@ -200,7 +205,7 @@ class ImproveActionDcstore extends ImproveAction
$this->module['version'], $this->module['version'],
$this->module['author'] $this->module['author']
], ],
$this->getSetting('pattern') $str
)); ));
} }
} }

View File

@ -37,12 +37,12 @@ class ImproveActionGitshields extends ImproveAction
protected function init(): bool protected function init(): bool
{ {
$this->setProperties([ $this->setProperties([
'id' => 'gitshields', 'id' => 'gitshields',
'name' => __('Shields badges'), 'name' => __('Shields badges'),
'desc' => __('Add and maintain shields.io badges to the REDAME.md file'), 'description' => __('Add and maintain shields.io badges to the REDAME.md file'),
'priority' => 380, 'priority' => 380,
'config' => true, 'configurator' => true,
'types' => ['plugin', 'theme'] 'types' => ['plugin', 'theme']
]); ]);
return true; return true;

View File

@ -28,12 +28,12 @@ class ImproveActionLicensefile extends ImproveAction
protected function init(): bool protected function init(): bool
{ {
$this->setProperties([ $this->setProperties([
'id' => 'license', 'id' => 'license',
'name' => __('License file'), 'name' => __('License file'),
'desc' => __('Add or remove full license file to module root'), 'description' => __('Add or remove full license file to module root'),
'priority' => 330, 'priority' => 330,
'config' => true, 'configurator' => true,
'types' => ['plugin', 'theme'] 'types' => ['plugin', 'theme']
]); ]);
$this->action_version = [ $this->action_version = [
__('no version selected') => '', __('no version selected') => '',

View File

@ -15,11 +15,11 @@ class ImproveActionTab extends ImproveAction
protected function init(): bool protected function init(): bool
{ {
$this->setProperties([ $this->setProperties([
'id' => 'tab', 'id' => 'tab',
'name' => __('Tabulations'), 'name' => __('Tabulations'),
'desc' => __('Replace tabulation by four space in php files'), 'description' => __('Replace tabulation by four space in php files'),
'priority' => 820, 'priority' => 820,
'types' => ['plugin', 'theme'] 'types' => ['plugin', 'theme']
]); ]);
return true; return true;
@ -50,12 +50,12 @@ class ImproveActionNewline extends ImproveAction
protected function init(): bool protected function init(): bool
{ {
$this->setProperties([ $this->setProperties([
'id' => 'newline', 'id' => 'newline',
'name' => __('Newlines'), 'name' => __('Newlines'),
'desc' => __('Replace bad and repetitive and empty newline by single newline in files'), 'description' => __('Replace bad and repetitive and empty newline by single newline in files'),
'priority' => 840, 'priority' => 840,
'config' => true, 'configurator' => true,
'types' => ['plugin', 'theme'] 'types' => ['plugin', 'theme']
]); ]);
/* /*
$ext = @unserialize($this->core->blog->settings->improve->newline_extensions); $ext = @unserialize($this->core->blog->settings->improve->newline_extensions);
@ -129,12 +129,12 @@ class ImproveActionEndoffile extends ImproveAction
protected function init(): bool protected function init(): bool
{ {
$this->setProperties([ $this->setProperties([
'id' => 'endoffile', 'id' => 'endoffile',
'name' => __('End of files'), 'name' => __('End of files'),
'desc' => __('Remove php tag and empty lines from end of files'), 'description' => __('Remove php tag and empty lines from end of files'),
'priority' => 860, 'priority' => 860,
'config' => true, 'configurator' => true,
'types' => ['plugin', 'theme'] 'types' => ['plugin', 'theme']
]); ]);
return true; return true;

View File

@ -29,17 +29,22 @@ class ImproveActionPhpcsfixer extends ImproveAction
/** @var string User pref for colored synthax theme */ /** @var string User pref for colored synthax theme */
protected static $user_ui_colorsyntax_theme = 'default'; protected static $user_ui_colorsyntax_theme = 'default';
/** @var string Settings PHP executable path */
private $phpexe_path = '';
protected function init(): bool protected function init(): bool
{ {
$this->setProperties([ $this->setProperties([
'id' => 'phpcsfixer', 'id' => 'phpcsfixer',
'name' => __('PHP CS Fixer'), 'name' => __('PHP CS Fixer'),
'desc' => __('Fix PSR coding style using Php CS Fixer'), 'description' => __('Fix PSR coding style using Php CS Fixer'),
'priority' => 920, 'priority' => 920,
'config' => true, 'configurator' => true,
'types' => ['plugin', 'theme'] 'types' => ['plugin', 'theme']
]); ]);
$this->getPhpPath();
$this->core->auth->user_prefs->addWorkspace('interface'); $this->core->auth->user_prefs->addWorkspace('interface');
self::$user_ui_colorsyntax = $this->core->auth->user_prefs->interface->colorsyntax; self::$user_ui_colorsyntax = $this->core->auth->user_prefs->interface->colorsyntax;
self::$user_ui_colorsyntax_theme = $this->core->auth->user_prefs->interface->colorsyntax_theme; self::$user_ui_colorsyntax_theme = $this->core->auth->user_prefs->interface->colorsyntax_theme;
@ -74,7 +79,7 @@ class ImproveActionPhpcsfixer extends ImproveAction
return return
'<p><label class="classic" for="phpexe_path">' . '<p><label class="classic" for="phpexe_path">' .
__('Root directory of PHP executable:') . '<br />' . __('Root directory of PHP executable:') . '<br />' .
form::field('phpexe_path', 160, 255, $this->getSetting('phpexe_path')) . '</label>' . form::field('phpexe_path', 160, 255, $this->phpexe_path) . '</label>' .
'</p>' . '</p>' .
'<p class="form-note">' . '<p class="form-note">' .
__('If this module does not work you can try to put here directory to php executable (without executable file name).') . __('If this module does not work you can try to put here directory to php executable (without executable file name).') .
@ -95,14 +100,9 @@ class ImproveActionPhpcsfixer extends ImproveAction
public function closeModule(): ?bool public function closeModule(): ?bool
{ {
$phpexe_path = $this->getPhpPath();
if (!empty($phpexe_path)) {
$phpexe_path .= '/';
}
$command = sprintf( $command = sprintf(
'%sphp %s/libs/php-cs-fixer.phar fix %s --config=%s/libs/dc.phpcsfixer.rules.php --using-cache=no', '%sphp %s/libs/php-cs-fixer.phar fix %s --config=%s/libs/dc.phpcsfixer.rules.php --using-cache=no',
$phpexe_path, $this->phpexe_path,
dirname(__FILE__), dirname(__FILE__),
$this->module['sroot'], $this->module['sroot'],
dirname(__FILE__) dirname(__FILE__)
@ -131,16 +131,20 @@ class ImproveActionPhpcsfixer extends ImproveAction
/** /**
* Get php executable path * Get php executable path
*
* @return string The path
*/ */
private function getPhpPath(): string private function getPhpPath(): void
{ {
$phpexe_path = $this->getSetting('phpexe_path'); $phpexe_path = $this->getSetting('phpexe_path');
if (!is_string($phpexe_path)) {
$phpexe_path = '';
}
if (empty($phpexe_path) && !empty(PHP_BINDIR)) { if (empty($phpexe_path) && !empty(PHP_BINDIR)) {
$phpexe_path = PHP_BINDIR; $phpexe_path = PHP_BINDIR;
} }
$phpexe_path = (string) path::real($phpexe_path);
return (string) path::real($phpexe_path); if (!empty($phpexe_path)) {
$phpexe_path .= '/';
}
$this->phpexe_path = $phpexe_path;
} }
} }

View File

@ -47,15 +47,18 @@ EOF;
/** @var boolean Stop parsing files */ /** @var boolean Stop parsing files */
private $stop_scan = false; private $stop_scan = false;
/** @var string Settings bloc content */
private $bloc_content = '';
protected function init(): bool protected function init(): bool
{ {
$this->setProperties([ $this->setProperties([
'id' => 'phpheader', 'id' => 'phpheader',
'name' => __('PHP header'), 'name' => __('PHP header'),
'desc' => __('Add or remove phpdoc header bloc from php file'), 'description' => __('Add or remove phpdoc header bloc from php file'),
'priority' => 340, 'priority' => 340,
'config' => true, 'configurator' => true,
'types' => ['plugin', 'theme'] 'types' => ['plugin', 'theme']
]); ]);
$this->action_bloc = [ $this->action_bloc = [
@ -66,6 +69,9 @@ EOF;
__('Remove existing bloc header') => 'remove' __('Remove existing bloc header') => 'remove'
]; ];
$bloc_content = $this->getSetting('bloc_content');
$this->bloc_content = is_string($bloc_content) ? $bloc_content : '';
return true; return true;
} }
@ -103,7 +109,7 @@ EOF;
<p>' . __('Bloc content:') . '</p> <p>' . __('Bloc content:') . '</p>
<p class="area">' . <p class="area">' .
form::textarea('bloc_content', 50, 10, html::escapeHTML($this->getSetting('bloc_content'))) . ' form::textarea('bloc_content', 50, 10, html::escapeHTML($this->bloc_content)) . '
</p><p class="form-note">' . </p><p class="form-note">' .
sprintf( sprintf(
__('You can use wildcards %s'), __('You can use wildcards %s'),
@ -114,7 +120,7 @@ EOF;
public function openModule(): ?bool public function openModule(): ?bool
{ {
$bloc = trim($this->getSetting('bloc_content')); $bloc = trim($this->bloc_content);
if (empty($bloc)) { if (empty($bloc)) {
$this->setWarning(__('bloc is empty')); $this->setWarning(__('bloc is empty'));

View File

@ -18,17 +18,34 @@ class ImproveActionPhpstan extends ImproveAction
/** @var string User pref for colored synthax theme */ /** @var string User pref for colored synthax theme */
protected static $user_ui_colorsyntax_theme = 'default'; protected static $user_ui_colorsyntax_theme = 'default';
/** @var integer Settings phpstan run level */
private $run_level = 5;
/** @var string Settings phpstan ignored vars */
private $ignored_vars = '';
/** @var string Settings PHP executable path */
private $phpexe_path = '';
protected function init(): bool protected function init(): bool
{ {
$this->setProperties([ $this->setProperties([
'id' => 'phpstan', 'id' => 'phpstan',
'name' => __('PHPStan'), 'name' => __('PHPStan'),
'desc' => __('Analyse php code using PHPStan'), 'description' => __('Analyse php code using PHPStan'),
'priority' => 910, 'priority' => 910,
'config' => true, 'configurator' => true,
'types' => ['plugin'] 'types' => ['plugin']
]); ]);
$this->getPhpPath();
$run_level = $this->getSetting('run_level');
$this->run_level = is_int($run_level) ? $run_level : 5;
$ignored_vars = $this->getSetting('ignored_vars');
$this->ignored_vars = is_string($ignored_vars) ? $ignored_vars : '';
$this->core->auth->user_prefs->addWorkspace('interface'); $this->core->auth->user_prefs->addWorkspace('interface');
self::$user_ui_colorsyntax = $this->core->auth->user_prefs->interface->colorsyntax; self::$user_ui_colorsyntax = $this->core->auth->user_prefs->interface->colorsyntax;
self::$user_ui_colorsyntax_theme = $this->core->auth->user_prefs->interface->colorsyntax_theme; self::$user_ui_colorsyntax_theme = $this->core->auth->user_prefs->interface->colorsyntax_theme;
@ -67,16 +84,16 @@ class ImproveActionPhpstan extends ImproveAction
'<p class="info">' . __('You must enable improve details to view analyse results !') . '</p>' . '<p class="info">' . __('You must enable improve details to view analyse results !') . '</p>' .
'<p><label class="classic" for="phpexe_path">' . '<p><label class="classic" for="phpexe_path">' .
__('Root directory of PHP executable:') . '<br />' . __('Root directory of PHP executable:') . '<br />' .
form::field('phpexe_path', 160, 255, $this->getSetting('phpexe_path')) . '</label>' . form::field('phpexe_path', 160, 255, $this->phpexe_path) . '</label>' .
'</p>' . '</p>' .
'<p class="form-note">' . '<p class="form-note">' .
__('If this module does not work you can try to put here directory to php executable (without executable file name).') . __('If this module does not work you can try to put here directory to php executable (without executable file name).') .
' C:\path_to\php</p>' . ' C:\path_to\php</p>' .
'<p><label class="classic" for="run_level">' . __('Level:') . ' </label>' . '<p><label class="classic" for="run_level">' . __('Level:') . ' </label>' .
form::number('run_level', ['min' => 0, 'max' => 9, 'default' => (int) $this->getSetting('run_level')]) . '</p>' . form::number('run_level', ['min' => 0, 'max' => 9, 'default' => $this->run_level]) . '</p>' .
'<p><label class="classic" for="ignored_vars">' . '<p><label class="classic" for="ignored_vars">' .
__('List of ignored variables:') . '<br />' . __('List of ignored variables:') . '<br />' .
form::field('ignored_vars', 160, 255, $this->getSetting('ignored_vars')) . '</label>' . form::field('ignored_vars', 160, 255, $this->ignored_vars) . '</label>' .
'</p>' . '</p>' .
'<p class="form-note">' . sprintf( '<p class="form-note">' . sprintf(
__('If you have errors like "%s", you can add this var here. Use ; as separator and do not put $ ahead.'), __('If you have errors like "%s", you can add this var here. Use ; as separator and do not put $ ahead.'),
@ -136,17 +153,13 @@ class ImproveActionPhpstan extends ImproveAction
private function execFixer(string $path = null): bool private function execFixer(string $path = null): bool
{ {
$phpexe_path = $this->getPhpPath();
if (!empty($phpexe_path)) {
$phpexe_path .= '/';
}
if (!empty($path)) { if (!empty($path)) {
$path .= ' '; $path .= ' ';
} }
$command = sprintf( $command = sprintf(
'%sphp %s/libs/phpstan.phar analyse ' . $path . '--configuration=%s', '%sphp %s/libs/phpstan.phar analyse ' . $path . '--configuration=%s',
$phpexe_path, $this->phpexe_path,
dirname(__FILE__), dirname(__FILE__),
DC_VAR . '/phpstan.neon' DC_VAR . '/phpstan.neon'
); );
@ -171,14 +184,23 @@ class ImproveActionPhpstan extends ImproveAction
} }
} }
private function getPhpPath(): string /**
* Get php executable path
*/
private function getPhpPath(): void
{ {
$phpexe_path = $this->getSetting('phpexe_path'); $phpexe_path = $this->getSetting('phpexe_path');
if (!is_string($phpexe_path)) {
$phpexe_path = '';
}
if (empty($phpexe_path) && !empty(PHP_BINDIR)) { if (empty($phpexe_path) && !empty(PHP_BINDIR)) {
$phpexe_path = PHP_BINDIR; $phpexe_path = PHP_BINDIR;
} }
$phpexe_path = (string) path::real($phpexe_path);
return (string) path::real($phpexe_path); if (!empty($phpexe_path)) {
$phpexe_path .= '/';
}
$this->phpexe_path = $phpexe_path;
} }
private function writeConf(): bool private function writeConf(): bool
@ -191,7 +213,7 @@ class ImproveActionPhpstan extends ImproveAction
'%BOOTSTRAP_ROOT%' '%BOOTSTRAP_ROOT%'
], ],
[ [
(int) $this->getSetting('run_level'), $this->run_level,
$this->module['sroot'], $this->module['sroot'],
DC_ROOT, DC_ROOT,
dirname(__FILE__) . '/libs/' dirname(__FILE__) . '/libs/'
@ -199,7 +221,7 @@ class ImproveActionPhpstan extends ImproveAction
(string) file_get_contents(dirname(__FILE__) . '/libs/dc.phpstan.rules.conf') (string) file_get_contents(dirname(__FILE__) . '/libs/dc.phpstan.rules.conf')
); );
$ignored = explode(';', $this->getSetting('ignored_vars')); $ignored = explode(';', $this->ignored_vars);
foreach ($ignored as $var) { foreach ($ignored as $var) {
$var = trim($var); $var = trim($var);
if (empty($var)) { if (empty($var)) {

View File

@ -35,17 +35,35 @@ class ImproveActionZip extends ImproveAction
'%time%' '%time%'
]; ];
/** @var string Settings Excluded files */
private $pack_excludefiles = '';
/** @var string Settings Main packacge filename */
private $pack_filename = '';
/** @var string Settings Second package filename */
private $secondpack_filename = '';
protected function init(): bool protected function init(): bool
{ {
$this->setProperties([ $this->setProperties([
'id' => 'zip', 'id' => 'zip',
'name' => __('Zip module'), 'name' => __('Zip module'),
'desc' => __('Compress module into a ready to install package'), 'description' => __('Compress module into a ready to install package'),
'priority' => 980, 'priority' => 980,
'config' => true, 'configurator' => true,
'types' => ['plugin', 'theme'] 'types' => ['plugin', 'theme']
]); ]);
$pack_excludefiles = $this->getSetting('pack_excludefiles');
$this->pack_excludefiles = is_string($pack_excludefiles) ? $pack_excludefiles : '';
$pack_filename = $this->getSetting('pack_filename');
$this->pack_filename = is_string($pack_filename) ? $pack_filename : '';
$secondpack_filename = $this->getSetting('secondpack_filename');
$this->secondpack_filename = is_string($secondpack_filename) ? $secondpack_filename : '';
return true; return true;
} }
@ -86,7 +104,7 @@ class ImproveActionZip extends ImproveAction
<h4>' . __('Files') . '</h4> <h4>' . __('Files') . '</h4>
<p><label for="pack_filename">' . __('Name of exported package:') . ' ' . <p><label for="pack_filename">' . __('Name of exported package:') . ' ' .
form::field('pack_filename', 65, 255, $this->getSetting('pack_filename'), 'maximal') . form::field('pack_filename', 65, 255, $this->pack_filename, 'maximal') .
'</label></p> '</label></p>
<p class="form-note">' . sprintf(__('Preconization: %s'), '%type%-%id%') . '</p> <p class="form-note">' . sprintf(__('Preconization: %s'), '%type%-%id%') . '</p>
@ -105,7 +123,7 @@ class ImproveActionZip extends ImproveAction
<h4>' . __('Content') . '</h4> <h4>' . __('Content') . '</h4>
<p><label for="pack_excludefiles">' . __('Extra files to exclude from package:') . ' ' . <p><label for="pack_excludefiles">' . __('Extra files to exclude from package:') . ' ' .
form::field('pack_excludefiles', 65, 255, $this->getSetting('pack_excludefiles'), 'maximal') . form::field('pack_excludefiles', 65, 255, $this->pack_excludefiles, 'maximal') .
'</label></p> '</label></p>
<p class="form-note">' . sprintf(__('Preconization: %s'), '*.zip,*.tar,*.tar.gz') . '<br />' . <p class="form-note">' . sprintf(__('Preconization: %s'), '*.zip,*.tar,*.tar.gz') . '<br />' .
sprintf(__('By default all these files are always removed from packages : %s'), implode(', ', self::$exclude)) . '</p> sprintf(__('By default all these files are always removed from packages : %s'), implode(', ', self::$exclude)) . '</p>
@ -121,7 +139,7 @@ class ImproveActionZip extends ImproveAction
{ {
$exclude = array_merge( $exclude = array_merge(
self::$exclude, self::$exclude,
explode(',', $this->getSetting('pack_excludefiles')) explode(',', $this->pack_excludefiles)
); );
$this->setSuccess(sprintf(__('Prepare excluded files "%s"'), implode(', ', $exclude))); $this->setSuccess(sprintf(__('Prepare excluded files "%s"'), implode(', ', $exclude)));
if (!empty($this->getSetting('pack_nocomment'))) { if (!empty($this->getSetting('pack_nocomment'))) {
@ -129,10 +147,10 @@ class ImproveActionZip extends ImproveAction
$this->setSuccess(__('Prepare comment removal')); $this->setSuccess(__('Prepare comment removal'));
} }
if (!empty($this->getSetting('pack_filename'))) { if (!empty($this->getSetting('pack_filename'))) {
$this->zipModule($this->getSetting('pack_filename'), $exclude); $this->zipModule($this->pack_filename, $exclude);
} }
if (!empty($this->getSetting('secondpack_filename'))) { if (!empty($this->getSetting('secondpack_filename'))) {
$this->zipModule($this->getSetting('secondpack_filename'), $exclude); $this->zipModule($this->secondpack_filename, $exclude);
} }
return null; return null;

View File

@ -31,8 +31,8 @@ if (!empty($_POST['save_preferences'])) {
$preferences[$type] = []; $preferences[$type] = [];
if (!empty($_POST['actions'])) { if (!empty($_POST['actions'])) {
foreach ($improve->modules() as $action) { foreach ($improve->modules() as $action) {
if (in_array($type, $action->get('types')) && in_array($action->get('id'), $_POST['actions'])) { if (in_array($type, $action->types()) && in_array($action->id(), $_POST['actions'])) {
$preferences[$type][] = $action->get('id'); $preferences[$type][] = $action->id();
} }
} }
} }
@ -141,18 +141,18 @@ if (!empty($_REQUEST['config'])) {
$back_url = $_REQUEST['redir'] ?? $core->adminurl->get('admin.plugin.improve', ['type' => $type]); $back_url = $_REQUEST['redir'] ?? $core->adminurl->get('admin.plugin.improve', ['type' => $type]);
if (null !== $action) { if (null !== $action) {
$redir = $_REQUEST['redir'] ?? $core->adminurl->get('admin.plugin.improve', ['type' => $type, 'config' => $action->get('id')]); $redir = $_REQUEST['redir'] ?? $core->adminurl->get('admin.plugin.improve', ['type' => $type, 'config' => $action->id()]);
$res = $action->configure($redir); $res = $action->configure($redir);
echo ' echo '
<h3>' . sprintf(__('Configure module "%s"'), $action->get('name')) . '</h3> <h3>' . sprintf(__('Configure module "%s"'), $action->name()) . '</h3>
<p><a class="back" href="' . $back_url . '">' . __('Back') . '</a></p> <p><a class="back" href="' . $back_url . '">' . __('Back') . '</a></p>
<p class="info">' . html::escapeHTML($action->get('desc')) . '</p> <p class="info">' . html::escapeHTML($action->description()) . '</p>
<form action="' . $core->adminurl->get('admin.plugin.improve') . '" method="post" id="form-actions">' . <form action="' . $core->adminurl->get('admin.plugin.improve') . '" method="post" id="form-actions">' .
(empty($res) ? '<p class="message">' . __('Nothing to configure') . '</p>' : $res) . ' (empty($res) ? '<p class="message">' . __('Nothing to configure') . '</p>' : $res) . '
<p class="clear"><input type="submit" name="save" value="' . __('Save') . '" />' . <p class="clear"><input type="submit" name="save" value="' . __('Save') . '" />' .
form::hidden('type', $type) . form::hidden('type', $type) .
form::hidden('config', $action->get('id')) . form::hidden('config', $action->id()) .
form::hidden('redir', $redir) . form::hidden('redir', $redir) .
$core->formNonce() . '</p>' . $core->formNonce() . '</p>' .
'</form>'; '</form>';
@ -173,31 +173,30 @@ if (!empty($_REQUEST['config'])) {
(DC_DEBUG ? '<th scope="col">' . __('Priority') . '</td>' : '') . (DC_DEBUG ? '<th scope="col">' . __('Priority') . '</td>' : '') .
'</tr></thead><tbody>'; '</tr></thead><tbody>';
foreach ($improve->modules() as $action) { foreach ($improve->modules() as $action) {
if (!in_array($type, $action->get('types'))) { if (!in_array($type, $action->types())) {
continue; continue;
} }
echo echo
'<tr class="line' . ($action->isConfigured() ? '' : ' offline') . '">' . '<tr class="line' . ($action->isConfigured() ? '' : ' offline') . '">' .
'<td class="minimal">' . form::checkbox( '<td class="minimal">' . form::checkbox(
['actions[]', ['actions[]',
'action_' . $action->get('id')], 'action_' . $action->id()],
$action->get('id'), $action->id(),
in_array($action->get('id'), $preferences[$type]) && $action->isConfigured(), in_array($action->id(), $preferences[$type]) && $action->isConfigured(),
'', '',
'', '',
!$action->isConfigured() !$action->isConfigured()
) . '</td>' . ) . '</td>' .
'<td class="minimal nowrap">' . '<td class="minimal nowrap">' .
'<label for="action_' . $action->get('id') . '" class="classic">' . html::escapeHTML($action->get('name')) . '</label>' . '<label for="action_' . $action->id() . '" class="classic">' . html::escapeHTML($action->name()) . '</label>' .
'</td>' . '</td>' .
'<td class="maximal">' . $action->get('desc') . '</td>' . '<td class="maximal">' . $action->description() . '</td>' .
'<td class="minimal nowrap modules">' . ( '<td class="minimal nowrap modules">' . (
false === $action->get('config') ? '' : false === $action->configurator() ? '' :
'<a class="module-config" href="' . '<a class="module-config" href="' . $core->adminurl->get('admin.plugin.improve', ['type' => $type, 'config' => $action->id()]) .
(true === $action->get('config') ? $core->adminurl->get('admin.plugin.improve', ['type' => $type, 'config' => $action->get('id')]) : $action->get('config')) . '" title="' . sprintf(__("Configure action '%s'"), $action->name()) . '">' . __('Configure') . '</a>'
'" title="' . sprintf(__("Configure action '%s'"), $action->get('name')) . '">' . __('Configure') . '</a>'
) . '</td>' . ) . '</td>' .
(DC_DEBUG ? '<td class="minimal"><span class="debug">' . $action->get('priority') . '</span></td>' : '') . (DC_DEBUG ? '<td class="minimal"><span class="debug">' . $action->priority() . '</span></td>' : '') .
'</tr>'; '</tr>';
} }
@ -227,7 +226,7 @@ if (!empty($_REQUEST['config'])) {
echo '<div class="' . $type . '"><ul>'; echo '<div class="' . $type . '"><ul>';
foreach ($tools as $tool => $msgs) { foreach ($tools as $tool => $msgs) {
$a = $improve->module($tool); $a = $improve->module($tool);
echo '<li>' . ($a !== null ? $a->get('name') : 'unknow') . '<ul>'; echo '<li>' . ($a !== null ? $a->name() : 'unknow') . '<ul>';
foreach ($msgs as $msg) { foreach ($msgs as $msg) {
echo '<li>' . $msg . '</li>'; echo '<li>' . $msg . '</li>';
} }