diff options
author | Andreas Gohr <andi@splitbrain.org> | 2023-09-02 14:42:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-02 14:42:51 +0200 |
commit | 5ff5424d8c81c7123d8656a787af2ff85b3dec21 (patch) | |
tree | 322929ee01d892bb3c927e7fe1238369c647f820 /inc/Extension/PluginController.php | |
parent | 0613df3287b82a98b1e97cf86ed9d4c8fbd16f1c (diff) | |
parent | 91560755291852b8302767d454183a7662666f7e (diff) | |
download | dokuwiki-5ff5424d8c81c7123d8656a787af2ff85b3dec21.tar.gz dokuwiki-5ff5424d8c81c7123d8656a787af2ff85b3dec21.zip |
Merge pull request #4045 from dokuwiki/autofix
Use Rector to autofix code smell
Diffstat (limited to 'inc/Extension/PluginController.php')
-rw-r--r-- | inc/Extension/PluginController.php | 54 |
1 files changed, 23 insertions, 31 deletions
diff --git a/inc/Extension/PluginController.php b/inc/Extension/PluginController.php index d53ea853e..dcdf29cd2 100644 --- a/inc/Extension/PluginController.php +++ b/inc/Extension/PluginController.php @@ -13,7 +13,7 @@ use dokuwiki\ErrorHandler; class PluginController { /** @var array the types of plugins DokuWiki supports */ - const PLUGIN_TYPES = ['auth', 'admin', 'syntax', 'action', 'renderer', 'helper', 'remote', 'cli']; + public const PLUGIN_TYPES = ['auth', 'admin', 'syntax', 'action', 'renderer', 'helper', 'remote', 'cli']; protected $listByType = []; /** @var array all installed plugins and their enabled state [plugin=>enabled] */ @@ -83,7 +83,7 @@ class PluginController //we keep all loaded plugins available in global scope for reuse global $DOKU_PLUGINS; - list($plugin, /* $component */) = $this->splitName($name); + [$plugin, /* component */ ] = $this->splitName($name); // check if disabled if (!$disabled && !$this->isEnabled($plugin)) { @@ -96,8 +96,7 @@ class PluginController //plugin already loaded? if (!empty($DOKU_PLUGINS[$type][$name])) { if ($new || !$DOKU_PLUGINS[$type][$name]->isSingleton()) { - - return class_exists($class, true) ? new $class : null; + return class_exists($class, true) ? new $class() : null; } return $DOKU_PLUGINS[$type][$name]; @@ -115,21 +114,19 @@ class PluginController hsc( $inf['base'] ) - ), -1 + ), + -1 ); } elseif (preg_match('/^' . DOKU_PLUGIN_NAME_REGEX . '$/', $plugin) !== 1) { - msg( - sprintf( - "Plugin name '%s' is not a valid plugin name, only the characters a-z ". - "and 0-9 are allowed. " . - 'Maybe the plugin has been installed in the wrong directory?', hsc($plugin) - ), -1 - ); + msg(sprintf( + 'Plugin name \'%s\' is not a valid plugin name, only the characters a-z and 0-9 are allowed. ' . + 'Maybe the plugin has been installed in the wrong directory?', + hsc($plugin) + ), -1); } return null; } - $DOKU_PLUGINS[$type][$name] = new $class; - + $DOKU_PLUGINS[$type][$name] = new $class(); } catch (\Throwable $e) { ErrorHandler::showExceptionMsg($e, sprintf('Failed to load plugin %s', $plugin)); return null; @@ -204,14 +201,13 @@ class PluginController protected function populateMasterList() { if ($dh = @opendir(DOKU_PLUGIN)) { - $all_plugins = array(); + $all_plugins = []; while (false !== ($plugin = readdir($dh))) { if ($plugin[0] === '.') continue; // skip hidden entries if (is_file(DOKU_PLUGIN . $plugin)) continue; // skip files, we're only interested in directories if (array_key_exists($plugin, $this->masterList) && $this->masterList[$plugin] == 0) { $all_plugins[$plugin] = 0; - } elseif (array_key_exists($plugin, $this->masterList) && $this->masterList[$plugin] == 1) { $all_plugins[$plugin] = 1; } else { @@ -234,7 +230,7 @@ class PluginController */ protected function checkRequire($files) { - $plugins = array(); + $plugins = []; foreach ($files as $file) { if (file_exists($file)) { include_once($file); @@ -297,7 +293,7 @@ class PluginController //gives us the ones we need to check and save $diffed_ones = array_diff_key($local_default, $this->pluginCascade['default']); //The ones which we are sure of (list of 0s not in default) - $sure_plugins = array_filter($diffed_ones, array($this, 'negate')); + $sure_plugins = array_filter($diffed_ones, [$this, 'negate']); //the ones in need of diff $conflicts = array_diff_key($local_default, $diffed_ones); //The final list @@ -311,20 +307,18 @@ class PluginController protected function loadConfig() { global $config_cascade; - foreach (array('default', 'protected') as $type) { + foreach (['default', 'protected'] as $type) { if (array_key_exists($type, $config_cascade['plugins'])) { $this->pluginCascade[$type] = $this->checkRequire($config_cascade['plugins'][$type]); } } $local = $config_cascade['plugins']['local']; $this->lastLocalConfigFile = array_pop($local); - $this->pluginCascade['local'] = $this->checkRequire(array($this->lastLocalConfigFile)); - if (is_array($local)) { - $this->pluginCascade['default'] = array_merge( - $this->pluginCascade['default'], - $this->checkRequire($local) - ); - } + $this->pluginCascade['local'] = $this->checkRequire([$this->lastLocalConfigFile]); + $this->pluginCascade['default'] = array_merge( + $this->pluginCascade['default'], + $this->checkRequire($local) + ); $this->masterList = array_merge( $this->pluginCascade['default'], $this->pluginCascade['local'], @@ -344,11 +338,10 @@ class PluginController { $master_list = $enabled ? array_keys(array_filter($this->masterList)) - : array_keys(array_filter($this->masterList, array($this, 'negate'))); - $plugins = array(); + : array_keys(array_filter($this->masterList, [$this, 'negate'])); + $plugins = []; foreach ($master_list as $plugin) { - if (file_exists(DOKU_PLUGIN . "$plugin/$type.php")) { $plugins[] = $plugin; continue; @@ -366,7 +359,6 @@ class PluginController closedir($dp); } } - }//foreach return $plugins; @@ -386,7 +378,7 @@ class PluginController return sexplode('_', $name, 2, ''); } - return array($name, ''); + return [$name, '']; } /** |