From ddb7f1c9fce1194021ce870277ab18d2c242195b Mon Sep 17 00:00:00 2001 From: David Siegfried <david.siegfried@uni-vechta.de> Date: Thu, 17 Feb 2022 14:12:04 +0000 Subject: [PATCH] fix php-doc and prevent php-warning, refs #687 --- lib/classes/URLHelper.php | 2 +- lib/plugins/engine/PluginEngine.class.php | 50 ++++---- lib/plugins/engine/PluginManager.class.php | 108 ++++++++++-------- lib/plugins/engine/PluginRepository.class.php | 26 ++--- 4 files changed, 97 insertions(+), 89 deletions(-) diff --git a/lib/classes/URLHelper.php b/lib/classes/URLHelper.php index a36cc10377f..a0c27b979bf 100644 --- a/lib/classes/URLHelper.php +++ b/lib/classes/URLHelper.php @@ -2,7 +2,7 @@ # Lifter007: TODO # Lifter003: TODO # Lifter010: TODO -/* +/** * URLHelper.php - utility functions for URL parameter handling * * Copyright (c) 2008 Elmar Ludwig diff --git a/lib/plugins/engine/PluginEngine.class.php b/lib/plugins/engine/PluginEngine.class.php index 9018cd8087e..a0db8b86a7d 100644 --- a/lib/plugins/engine/PluginEngine.class.php +++ b/lib/plugins/engine/PluginEngine.class.php @@ -1,6 +1,5 @@ <?php -# Lifter007: TODO -# Lifter010: TODO + /** * Factory Class for the plugin engine * @author Dennis Reil, <dennis.reil@offis.de> @@ -13,7 +12,7 @@ class PluginEngine /** * This function maps an incoming request to a tuple * (pluginclassname, unconsumed rest). - * + * @param string $dispatch_to * @return array the above mentioned tuple */ public static function routeRequest($dispatch_to) @@ -23,7 +22,7 @@ class PluginEngine throw new PluginNotFoundException(_('Es wurde kein Plugin gewählt.')); } $pos = mb_strpos($dispatch_to, '/'); - return $pos === FALSE + return $pos === false ? [$dispatch_to, ''] : [mb_substr($dispatch_to, 0, $pos), mb_substr($dispatch_to, $pos + 1)]; } @@ -59,7 +58,7 @@ class PluginEngine /** * Get instance of the plugin specified by plugin class name. * - * @param $class class name of plugin + * @param class-string $class class name of plugin */ public static function getPlugin ($class) { @@ -71,10 +70,11 @@ class PluginEngine * returns all enabled plugins. The optional context parameter can be * used to get only plugins that are activated in the given context. * - * @param $type plugin type or NULL (all types) - * @param $context context range id (optional) + * @param string $type plugin type or null (all types) + * @param string $context context range id (optional) + * @return array all plugins of the specified type */ - public static function getPlugins ($type, $context = NULL) + public static function getPlugins ($type, $context = null) { return PluginManager::getInstance()->getPlugins($type, $context); } @@ -83,16 +83,16 @@ class PluginEngine * Sends a message to all activated plugins of a type and returns an array of * the return values. * - * @param type plugin type or NULL (all types) - * @param string the method name that should be send to all plugins - * @param mixed a variable number of arguments + * @param string $type plugin type or null (all types) + * @param mixed $method the method name that should be send to all plugins + * @param mixed a variable number of arguments * - * @return array an array containing the return values + * @return array an array containing the return values */ public static function sendMessage($type, $method /* ... */) { $args = func_get_args(); - array_splice($args, 1, 0, [NULL]); + array_splice($args, 1, 0, [null]); return call_user_func_array([__CLASS__, 'sendMessageWithContext'], $args); } @@ -100,10 +100,10 @@ class PluginEngine * Sends a message to all activated plugins of a type enabled in a context and * returns an array of the return values. * - * @param type plugin type or NULL (all types) - * @param context context range id (may be NULL) - * @param string the method name that should be send to all plugins - * @param mixed a variable number of arguments + * @param string $type plugin type or null (all types) + * @param string $context context range id (may be null) + * @param string $method the method name that should be send to all plugins + * @param mixed a variable number of arguments * * @return array an array containing the return values */ @@ -120,11 +120,11 @@ class PluginEngine /** * Generates a URL which can be shown in user interfaces - * @param $plugin - the plugin to which should be linked - * @param $params - an array with name value pairs - * @param $cmd - command to execute by clicking the link + * @param StudIPPlugin|string $plugin - the plugin to which should be linked + * @param array $params - an array with name value pairs + * @param string $cmd - command to execute by clicking the link * @param bool $ignore_registered_params do not add registered params - * @return a link to the current plugin with the additional $params + * @return string a link to the current plugin with the additional $params */ public static function getURL($plugin, $params = [], $cmd = 'show', $ignore_registered_params = false) { @@ -141,11 +141,11 @@ class PluginEngine /** * Generates a link (entity encoded URL) which can be shown in user interfaces - * @param $plugin - the plugin to which should be linked - * @param $params - an array with name value pairs - * @param $cmd - command to execute by clicking the link + * @param StudIPPlugin|string $plugin - the plugin to which should be linked + * @param array $params - an array with name value pairs + * @param string $cmd - command to execute by clicking the link * @param bool $ignore_registered_params do not add registeredparams - * @return a link to the current plugin with the additional $params + * @return string a link to the current plugin with the additional $params */ public static function getLink($plugin, $params = [], $cmd = 'show', $ignore_registered_params = false) { diff --git a/lib/plugins/engine/PluginManager.class.php b/lib/plugins/engine/PluginManager.class.php index b7ecb0dfff8..f5c53de45da 100644 --- a/lib/plugins/engine/PluginManager.class.php +++ b/lib/plugins/engine/PluginManager.class.php @@ -104,7 +104,7 @@ class PluginManager * method will be called accordingly. If the method returns false or * throws and exception, the plugin's activation state is not updated. * - * @param string $id id of the plugin + * @param int $id id of the plugin * @param bool $enabled plugin status (true or false) * @param bool $force force (de)activation regardless of the result * of on(en|dis)able @@ -115,10 +115,11 @@ class PluginManager public function setPluginEnabled ($id, $enabled, $force = false) { $info = $this->getPluginInfoById($id); + $plugin_class = ''; // Plugin is not present or no changes if (!$info || $info['enabled'] == $enabled) { - return; + return null; } if ($info['core'] || !$this->isPluginsDisabled()) { @@ -154,8 +155,8 @@ class PluginManager /** * Set the navigation position of the given plugin. * - * @param $id id of the plugin - * @param $position plugin navigation position + * @param int $id id of the plugin + * @param string $position plugin navigation position * @return bool indicating whether any change occured */ public function setPluginPosition ($id, $position) @@ -180,8 +181,8 @@ class PluginManager * Get the activation status of a plugin in the given context. * This also checks the plugin default activations and sem_class-settings. * - * @param $id int of the plugin - * @param $context string range id + * @param int $id id of the plugin + * @param string $context range id * @returns bool */ public function isPluginActivated ($id, $context) @@ -204,8 +205,8 @@ class PluginManager * Get the activation status of a plugin for the given user. * This also checks the plugin default activations and sem_class-settings. * - * @param $pluginId id of the plugin - * @param $userId id of the user + * @param int $pluginId id of the plugin + * @param string $userId id of the user */ public function isPluginActivatedForUser($pluginId, $userId) { @@ -234,9 +235,9 @@ class PluginManager /** * Sets the activation status of a plugin in the given context. * - * @param $id string id of the plugin - * @param $rangeId string context range id - * @param $active bool plugin status (true or false) + * @param int $id id of the plugin + * @param string $rangeId context range id + * @param bool $active plugin status (true or false) */ public function setPluginActivated ($id, $rangeId, $active) { @@ -262,9 +263,9 @@ class PluginManager /** * Sets the activation status of a plugin in the given context. * - * @param $pluginid string of the plugin - * @param $user_id string user id - * @param $active bool plugin status (true or false) + * @param int $pluginid id of the plugin + * @param string $user_id user id + * @param bool $active plugin status (true or false) */ public function setPluginActivatedForUser($pluginid, $user_id, $active) { @@ -302,7 +303,7 @@ class PluginManager * Returns the list of institutes for which a specific plugin is * enabled by default. * - * @param $id id of the plugin + * @param int $id id of the plugin */ public function getDefaultActivations ($id) { @@ -338,7 +339,7 @@ class PluginManager /** * Disable loading of all non-core plugins for the current session. * - * @param $status true: disable non-core plugins + * @param bool $status true: disable non-core plugins */ public function setPluginsDisabled($status) { @@ -357,8 +358,8 @@ class PluginManager * Load a plugin class from the given file system path and * return the ReflectionClass instance for the plugin. * - * @param $class plugin class name - * @param $path plugin relative path + * @param string $class plugin class name + * @param string $path plugin relative path */ private function loadPlugin ($class, $path) { @@ -375,7 +376,7 @@ class PluginManager $pluginfile = $basepath.'/'.$path.'/'.$class.'.php'; if (!file_exists($pluginfile)) { - return NULL; + return null; } } @@ -387,8 +388,8 @@ class PluginManager /** * Determine the type of a plugin to be installed. * - * @param $class plugin class name - * @param $path plugin relative path + * @param string $class plugin class name + * @param string $path plugin relative path */ private function getPluginType ($class, $path) { @@ -415,14 +416,13 @@ class PluginManager * Register a new plugin or update an existing plugin entry in the * data base. Returns the id of the new or updated plugin. * - * @param $name plugin name - * @param $class plugin class name - * @param $path plugin relative path - * @param $depends id of plugin this plugin depends on + * @param string $name plugin name + * @param string $class plugin class name + * @param string $path plugin relative path + * @param string $depends id of plugin this plugin depends on */ - public function registerPlugin ($name, $class, $path, $depends = NULL) + public function registerPlugin ($name, $class, $path, $depends = null) { - $db = DBManager::get(); $info = $this->getPluginInfo($class); $type = $this->getPluginType($class, $path); @@ -508,7 +508,7 @@ class PluginManager /** * Get meta data for the plugin specified by plugin class name. * - * @param $class class name of plugin + * @param class-string $class class name of plugin */ public function getPluginInfo ($class) { @@ -518,13 +518,13 @@ class PluginManager } } - return NULL; + return null; } /** * Get meta data for the plugin specified by plugin id. * - * @param $id id of the plugin + * @param int $id id of the plugin */ public function getPluginInfoById ($id) { @@ -532,21 +532,21 @@ class PluginManager return $this->plugins[$id]; } - return NULL; + return null; } /** - * Get meta data for all plugins of the specified type. A type of NULL + * Get meta data for all plugins of the specified type. A type of null * returns meta data for all installed plugins. * - * @param $type plugin type or NULL (all types) + * @param string $type plugin type or null (all types) */ - public function getPluginInfos ($type = NULL) + public function getPluginInfos ($type = null) { $result = []; foreach ($this->plugins as $id => $plugin) { - if ($type === NULL || in_array($type, $plugin['type'])) { + if ($type === null || in_array($type, $plugin['type'])) { $result[$id] = $plugin; } } @@ -557,17 +557,18 @@ class PluginManager /** * Check user access permission for the given plugin. * - * @param $plugin plugin meta data - * @param $user user id of user + * @param array $plugin plugin meta data + * @param string $user_id id of user + * @return bool */ - protected function checkUserAccess ($plugin, $user) + protected function checkUserAccess ($plugin, $user_id) { if (!$plugin['enabled']) { return false; } $plugin_roles = RolePersistence::getAssignedPluginRoles($plugin['id']); - $user_roles = RolePersistence::getAssignedRoles($user, true); + $user_roles = RolePersistence::getAssignedRoles($user_id, true); foreach ($plugin_roles as $plugin_role) { foreach ($user_roles as $user_role) { @@ -583,12 +584,15 @@ class PluginManager /** * Get instance of the plugin specified by plugin meta data. * - * @param $plugin_info plugin meta data + * @param array $plugin_info plugin meta data + * @return object */ protected function getCachedPlugin ($plugin_info) { $class = $plugin_info['class']; $path = $plugin_info['path']; + $plugin_class = ''; + $plugin = null; if (isset($this->plugin_cache[$class])) { return $this->plugin_cache[$class]; @@ -608,12 +612,14 @@ class PluginManager /** * Get instance of the plugin specified by plugin class name. * - * @param $class class name of plugin + * @param class-string $class class name of plugin + * @return object */ public function getPlugin ($class) { $user = $GLOBALS['user']->id; $plugin_info = $this->getPluginInfo($class); + $plugin = null; if (isset($plugin_info) && $this->checkUserAccess($plugin_info, $user)) { $plugin = $this->getCachedPlugin($plugin_info); @@ -625,12 +631,14 @@ class PluginManager /** * Get instance of the plugin specified by plugin id. * - * @param $id id of the plugin + * @param int $id id of the plugin + * @return object $plugin */ public function getPluginById ($id) { $user = $GLOBALS['user']->id; $plugin_info = $this->getPluginInfoById($id); + $plugin = null; if (isset($plugin_info) && $this->checkUserAccess($plugin_info, $user)) { $plugin = $this->getCachedPlugin($plugin_info); @@ -640,14 +648,14 @@ class PluginManager } /** - * Get instances of all plugins of the specified type. A type of NULL + * Get instances of all plugins of the specified type. A type of null * returns all enabled plugins. The optional context parameter can be * used to get only plugins that are activated in the given context. * - * @param $type plugin type or NULL (all types) - * @param $context context range id (optional) + * @param string $type plugin type or null (all types) + * @param string $context context range id (optional) */ - public function getPlugins ($type, $context = NULL) + public function getPlugins ($type, $context = null) { $user = $GLOBALS['user']->id ?: 'nobody'; $plugin_info = $this->getPluginInfos($type); @@ -656,13 +664,13 @@ class PluginManager usort($plugin_info, ['self', 'positionCompare']); foreach ($plugin_info as $info) { - $activated = $context == NULL + $activated = $context == null || $this->isPluginActivated($info['id'], $context); if ($this->checkUserAccess($info, $user) && $activated) { $plugin = $this->getCachedPlugin($info); - if ($plugin !== NULL) { + if ($plugin !== null) { $plugins[] = $plugin; } } @@ -673,7 +681,7 @@ class PluginManager /** * Read the manifest of the plugin in the given directory. - * Returns NULL if the manifest cannot be found. + * Returns null if the manifest cannot be found. * * @return array containing the manifest information */ @@ -683,7 +691,7 @@ class PluginManager $result = []; if ($manifest === false) { - return NULL; + return null; } foreach ($manifest as $line) { diff --git a/lib/plugins/engine/PluginRepository.class.php b/lib/plugins/engine/PluginRepository.class.php index cca8aad0447..78b5d02edf5 100644 --- a/lib/plugins/engine/PluginRepository.class.php +++ b/lib/plugins/engine/PluginRepository.class.php @@ -1,6 +1,6 @@ <?php -# Lifter010: TODO -/* + +/** * PluginRepository.class.php - query plugin meta data * * Copyright (c) 2008 Elmar Ludwig @@ -23,9 +23,9 @@ class PluginRepository /** * Initialize a new PluginRepository and read meta data from - * the given URL or the default list of URLs (if $url is NULL). + * the given URL or the default list of URLs (if $url is null). */ - public function __construct($url = NULL) + public function __construct($url = null) { if (isset($url)) { $this->readMetadata($url); @@ -40,6 +40,8 @@ class PluginRepository * Read plugin meta data from the given URL (using XML format). * The structure of the XML is: * + * @param string $url given url for plugin + * * <plugins> * <plugin name="DummyPlugin" * <release @@ -53,8 +55,6 @@ class PluginRepository */ public function readMetadata($url) { - global $SOFTWARE_VERSION; - $cache = StudipCacheFactory::getCache(); $cache_key = 'plugin_metadata/'.$url; $metadata = $cache->read($cache_key); @@ -111,8 +111,8 @@ class PluginRepository /** * Register a new plugin in this repository. * - * @param $name string plugin name - * @param $meta_data array of plugin meta data + * @param string $name plugin name + * @param array $meta_data plugin meta data */ protected function registerPlugin($name, $meta_data) { @@ -127,8 +127,8 @@ class PluginRepository /** * Get meta data for the plugin with the given name (if available). * Always chooses the newest compatible version of the plugin. - * - * @return array meta data for plugin (or NULL) + * @param string $name name of the plgin + * @return array meta data for plugin (or null) */ public function getPlugin($name) { @@ -140,15 +140,15 @@ class PluginRepository * string. You may omit the search string to get a list of all * available plugins. Returns the newest compatible version of * each plugin. - * + * @param string $search search string * @return array array of meta data for matching plugins */ - public function getPlugins($search = NULL) + public function getPlugins($search = null) { $result = []; foreach ($this->plugins as $name => $data) { - if ($search === NULL || $search === '' || + if ($search === null || $search === '' || is_int(mb_stripos($name, $search)) || is_int(mb_stripos($data['description'], $search))) { $result[$name] = $data; -- GitLab